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
« 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."""
3from __future__ import annotations
5import click
6from assertpy import assert_that
8from lintro.cli_utils.command_chainer import CommandChainer
11def test_init_with_default_separator(mock_group: click.Group) -> None:
12 """Test initialization with default comma separator.
14 Args:
15 mock_group: Mocked Click group fixture.
16 """
17 chainer = CommandChainer(mock_group)
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()
24def test_init_with_custom_separator(mock_group: click.Group) -> None:
25 """Test initialization with custom separator.
27 Args:
28 mock_group: Mocked Click group fixture.
29 """
30 chainer = CommandChainer(mock_group, separator=";")
32 assert_that(chainer.separator).is_equal_to(";")
35def test_command_names_lazy_loading(mock_group: click.Group) -> None:
36 """Test that command names are loaded lazily.
38 Args:
39 mock_group: Mocked Click group fixture.
40 """
41 chainer = CommandChainer(mock_group)
43 assert_that(chainer._command_names).is_none()
45 names = chainer.command_names
47 assert_that(names).contains("fmt", "chk", "tst")
48 assert_that(chainer._command_names).is_not_none()
51def test_command_names_cached(mock_group: click.Group) -> None:
52 """Test that command names are cached after first access.
54 Args:
55 mock_group: Mocked Click group fixture.
56 """
57 chainer = CommandChainer(mock_group)
59 names1 = chainer.command_names
60 names2 = chainer.command_names
62 assert_that(names1).is_same_as(names2)