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

24 statements  

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

1"""Tests for CommandChainer.normalize_args 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_normalize_already_separated(mock_group: click.Group) -> None: 

12 """Test normalization of already separated args. 

13 

14 Args: 

15 mock_group: Mocked Click group fixture. 

16 """ 

17 chainer = CommandChainer(mock_group) 

18 

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

20 

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

22 

23 

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

25 """Test normalization of joined command names. 

26 

27 Args: 

28 mock_group: Mocked Click group fixture. 

29 """ 

30 chainer = CommandChainer(mock_group) 

31 

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

33 

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

35 

36 

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

38 """Test that command arguments are preserved. 

39 

40 Args: 

41 mock_group: Mocked Click group fixture. 

42 """ 

43 chainer = CommandChainer(mock_group) 

44 

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

46 

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

48 

49 

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

51 """Test that comma in option values is preserved. 

52 

53 Args: 

54 mock_group: Mocked Click group fixture. 

55 """ 

56 chainer = CommandChainer(mock_group) 

57 

58 result = chainer.normalize_args(["fmt", "--tools", "ruff,bandit"]) 

59 

60 assert_that(result).is_equal_to(["fmt", "--tools", "ruff,bandit"]) 

61 

62 

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

64 """Test normalization of multiple chained commands. 

65 

66 Args: 

67 mock_group: Mocked Click group fixture. 

68 """ 

69 chainer = CommandChainer(mock_group) 

70 

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

72 

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