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

23 statements  

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

1"""Tests for CommandChainer initialization and command_names property.""" 

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_init_with_default_separator(mock_group: click.Group) -> None: 

12 """Test initialization with default comma separator. 

13 

14 Args: 

15 mock_group: Mocked Click group fixture. 

16 """ 

17 chainer = CommandChainer(mock_group) 

18 

19 assert_that(chainer.group).is_equal_to(mock_group) 

20 assert_that(chainer.separator).is_equal_to(",") 

21 assert_that(chainer._command_names).is_none() 

22 

23 

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

25 """Test initialization with custom separator. 

26 

27 Args: 

28 mock_group: Mocked Click group fixture. 

29 """ 

30 chainer = CommandChainer(mock_group, separator=";") 

31 

32 assert_that(chainer.separator).is_equal_to(";") 

33 

34 

35def test_command_names_lazy_loading(mock_group: click.Group) -> None: 

36 """Test that command names are loaded lazily. 

37 

38 Args: 

39 mock_group: Mocked Click group fixture. 

40 """ 

41 chainer = CommandChainer(mock_group) 

42 

43 assert_that(chainer._command_names).is_none() 

44 

45 names = chainer.command_names 

46 

47 assert_that(names).contains("fmt", "chk", "tst") 

48 assert_that(chainer._command_names).is_not_none() 

49 

50 

51def test_command_names_cached(mock_group: click.Group) -> None: 

52 """Test that command names are cached after first access. 

53 

54 Args: 

55 mock_group: Mocked Click group fixture. 

56 """ 

57 chainer = CommandChainer(mock_group) 

58 

59 names1 = chainer.command_names 

60 names2 = chainer.command_names 

61 

62 assert_that(names1).is_same_as(names2)