Skip to content

[Code scan] Make CLI tests invoke the checkout under test instead of PATH dargs #123

Description

@njzjz

This issue was found by a Codex global code scan of the repository.

Affected code:

dargs/tests/test_cli.py

Lines 13 to 23 in b4db564

subprocess.check_call(
[
"dargs",
"check",
"-f",
"dargs._test.test_arguments",
str(this_directory / "test_arguments.json"),
str(this_directory / "test_arguments.json"),
]
)
subprocess.check_call(

dargs/tests/test_cli.py

Lines 46 to 202 in b4db564

def test_doc_all_arguments(self) -> None:
"""Test printing documentation for all arguments."""
result = subprocess.run(
[
"dargs",
"doc",
"dargs._test.test_arguments",
],
capture_output=True,
text=True,
check=True,
)
# Check that all arguments are in the output (including nested base)
self.assertIn("test1:", result.stdout)
self.assertIn("test2:", result.stdout)
self.assertIn("test3:", result.stdout)
self.assertIn("base:", result.stdout)
self.assertIn("Argument 1", result.stdout)
self.assertIn("Argument 2", result.stdout)
self.assertIn("Argument 3", result.stdout)
def test_doc_specific_argument(self) -> None:
"""Test printing documentation for a specific argument."""
result = subprocess.run(
[
"dargs",
"doc",
"dargs._test.test_arguments",
"test1",
],
capture_output=True,
text=True,
check=True,
)
# Check that only test1 is in the output
self.assertIn("test1:", result.stdout)
self.assertIn("Argument 1", result.stdout)
# test2 and test3 should not be in the output
self.assertNotIn("Argument 2", result.stdout)
self.assertNotIn("Argument 3", result.stdout)
def test_doc_nested_arguments(self) -> None:
"""Test printing documentation for nested arguments."""
# Test top-level base argument
result = subprocess.run(
[
"dargs",
"doc",
"dargs._test.test_arguments",
"base",
],
capture_output=True,
text=True,
check=True,
)
self.assertIn("base:", result.stdout)
self.assertIn("sub1:", result.stdout)
self.assertIn("sub2:", result.stdout)
self.assertIn("subsub1:", result.stdout)
# Test specific nested path
result = subprocess.run(
[
"dargs",
"doc",
"dargs._test.test_arguments",
"base/sub1",
],
capture_output=True,
text=True,
check=True,
)
self.assertIn("sub1:", result.stdout)
self.assertIn("Sub argument 1", result.stdout)
# Check that the full path is in the output
self.assertIn("base/sub1", result.stdout)
# subsub1 should not be in the output
self.assertNotIn("subsub1:", result.stdout)
# Test deeply nested path
result = subprocess.run(
[
"dargs",
"doc",
"dargs._test.test_arguments",
"base/sub2/subsub1",
],
capture_output=True,
text=True,
check=True,
)
self.assertIn("subsub1:", result.stdout)
self.assertIn("Sub-sub argument 1", result.stdout)
# Check that the full path is in the output
self.assertIn("base/sub2/subsub1", result.stdout)
def test_doc_invalid_path(self) -> None:
"""Test error handling for invalid argument path."""
result = subprocess.run(
[
"dargs",
"doc",
"dargs._test.test_arguments",
"invalid",
],
capture_output=True,
text=True,
)
self.assertNotEqual(result.returncode, 0)
self.assertIn("not found", result.stderr)
def test_doc_invalid_nested_path(self) -> None:
"""Test error handling for invalid nested argument path."""
result = subprocess.run(
[
"dargs",
"doc",
"dargs._test.test_arguments",
"base/invalid",
],
capture_output=True,
text=True,
)
self.assertNotEqual(result.returncode, 0)
self.assertIn("not found", result.stderr)
def test_doc_with_python_module(self) -> None:
"""Test doc command using python -m."""
result = subprocess.run(
[
sys.executable,
"-m",
"dargs",
"doc",
"dargs._test.test_arguments",
"test1",
],
capture_output=True,
text=True,
check=True,
)
self.assertIn("test1:", result.stdout)
self.assertIn("Argument 1", result.stdout)
def test_doc_invalid_function_format(self) -> None:
"""Test error handling for invalid function format."""
result = subprocess.run(
[
"dargs",
"doc",
"invalid_func",
],
capture_output=True,
text=True,
)
self.assertNotEqual(result.returncode, 0)
self.assertIn("module.function", result.stderr)

Problem:
The CLI tests invoke bare dargs repeatedly. That executes whichever console script appears first on PATH, which may be an older installed package rather than this checkout.

Observed behavior in this workspace:
python -m pytest -q ran the checkout for imports, but the bare dargs doc ... subprocess hit an installed script whose argparse choices only included check, causing the doc-command tests to fail with:

dargs: error: argument {check}: invalid choice: 'doc' (choose from check)

Expected behavior:
CLI tests should execute the checkout under test, for example via sys.executable -m dargs after making source-tree version handling robust, or by invoking a console script from an isolated editable install created for the test environment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions