Coverage for tests / unit / cli_utils / command_chainer / test_group_commands.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-04-03 18:53 +0000

1"""Tests for CommandChainer.group_commands method.""" 

2 

3from __future__ import annotations 

4 

5import click 

6from assertpy import assert_that 

7 

8from lintro.cli_utils.command_chainer import CommandChainer 

9 

10 

11def test_group_single_command(mock_group: click.Group) -> None: 

12 """Test grouping of a single command. 

13 

14 Args: 

15 mock_group: Mocked Click group fixture. 

16 """ 

17 chainer = CommandChainer(mock_group) 

18 

19 result = chainer.group_commands(["fmt", "."]) 

20 

21 assert_that(result).is_equal_to([["fmt", "."]]) 

22 

23 

24def test_group_two_commands(mock_group: click.Group) -> None: 

25 """Test grouping of two commands. 

26 

27 Args: 

28 mock_group: Mocked Click group fixture. 

29 """ 

30 chainer = CommandChainer(mock_group) 

31 

32 result = chainer.group_commands(["fmt", ".", ",", "chk", "."]) 

33 

34 assert_that(result).is_equal_to([["fmt", "."], ["chk", "."]]) 

35 

36 

37def test_group_three_commands(mock_group: click.Group) -> None: 

38 """Test grouping of three commands. 

39 

40 Args: 

41 mock_group: Mocked Click group fixture. 

42 """ 

43 chainer = CommandChainer(mock_group) 

44 

45 result = chainer.group_commands(["fmt", ",", "chk", ",", "tst"]) 

46 

47 assert_that(result).is_equal_to([["fmt"], ["chk"], ["tst"]]) 

48 

49 

50def test_group_empty_args(mock_group: click.Group) -> None: 

51 """Test grouping of empty args. 

52 

53 Args: 

54 mock_group: Mocked Click group fixture. 

55 """ 

56 chainer = CommandChainer(mock_group) 

57 

58 result = chainer.group_commands([]) 

59 

60 assert_that(result).is_equal_to([]) 

61 

62 

63def test_group_ignores_empty_groups(mock_group: click.Group) -> None: 

64 """Test that empty groups from consecutive separators are ignored. 

65 

66 Args: 

67 mock_group: Mocked Click group fixture. 

68 """ 

69 chainer = CommandChainer(mock_group) 

70 

71 result = chainer.group_commands(["fmt", ",", ",", "chk"]) 

72 

73 assert_that(result).is_equal_to([["fmt"], ["chk"]])