Skip to content

Commit cb10a4c

Browse files
committed
fix: improve robustness of CLI help text assertions in tests - Replace brittle exact string matching with content-based assertions - Use case-insensitive matching to handle Rich formatting variations - Ensure tests work consistently across different terminal environments - Maintain test coverage while improving CI/CD reliability
1 parent 0ddd876 commit cb10a4c

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

tests/test_main.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ def test_hello_command_help():
3939
"""Test the --help option for the hello command."""
4040
result = runner.invoke(app, ["hello", "--help"])
4141
assert result.exit_code == 0
42-
assert "Usage: contextcraft hello [OPTIONS]" in result.stdout
43-
assert "Greets a person." in result.stdout # Check for part of the docstring
42+
# Check for key content without depending on exact formatting
43+
assert "hello" in result.stdout.lower()
44+
assert "options" in result.stdout.lower()
45+
assert "greets a person" in result.stdout.lower() # Check for part of the docstring
4446

4547

4648
# --- Tests for the 'tree' command ---
@@ -50,8 +52,11 @@ def test_tree_command_help():
5052
"""Test the --help option for the tree command."""
5153
result = runner.invoke(app, ["tree", "--help"])
5254
assert result.exit_code == 0
53-
assert "Usage: contextcraft tree [OPTIONS] [ROOT_DIR]" in result.stdout
54-
assert "Generate and display or save a directory tree structure." in result.stdout
55+
# Check for key content without depending on exact formatting
56+
assert "tree" in result.stdout.lower()
57+
assert "options" in result.stdout.lower()
58+
assert "root_dir" in result.stdout.lower()
59+
assert "generate and display or save a directory tree" in result.stdout.lower()
5560

5661

5762
@mock.patch("src.contextcraft.tools.tree_generator.generate_and_output_tree")
@@ -147,8 +152,11 @@ def test_flatten_command_help():
147152
"""Test the --help option for the flatten command."""
148153
result = runner.invoke(app, ["flatten", "--help"])
149154
assert result.exit_code == 0
150-
assert "Usage: contextcraft flatten [OPTIONS] [ROOT_DIR]" in result.stdout
151-
assert "Flatten specified files from a directory" in result.stdout
155+
# Check for key content without depending on exact formatting
156+
assert "flatten" in result.stdout.lower()
157+
assert "options" in result.stdout.lower()
158+
assert "root_dir" in result.stdout.lower()
159+
assert "flatten specified files from a directory" in result.stdout.lower()
152160

153161

154162
@mock.patch("src.contextcraft.tools.flattener.flatten_code_logic")
@@ -214,10 +222,13 @@ def test_app_help():
214222
"""Test the main application's --help output."""
215223
result = runner.invoke(app, ["--help"])
216224
assert result.exit_code == 0
217-
assert "Usage: contextcraft [OPTIONS] COMMAND [ARGS]..." in result.stdout
218-
assert "hello" in result.stdout
219-
assert "tree" in result.stdout
220-
assert "flatten" in result.stdout
225+
# Check for key content without depending on exact formatting
226+
assert "contextcraft" in result.stdout.lower()
227+
assert "options" in result.stdout.lower()
228+
assert "command" in result.stdout.lower()
229+
assert "hello" in result.stdout.lower()
230+
assert "tree" in result.stdout.lower()
231+
assert "flatten" in result.stdout.lower()
221232

222233

223234
@mock.patch(

0 commit comments

Comments
 (0)