Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
from pathlib import Path

this_directory = Path(__file__).parent
DARGS_COMMAND = [sys.executable, "-m", "dargs"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Pin subprocess module resolution to the checkout

python -m dargs resolves from the child process's working directory, not from the parent test runner's in-memory sys.path, so this constant does not reliably select the checkout. Running unittest discovery from /tmp imported these tests from the PR checkout in the parent, but the subprocesses selected an older installed dargs; I reproduced four errors and three failures with the old CLI that only exposed check. Please run the CLI subprocesses with cwd=this_directory.parent (preferably through a helper), or explicitly prepend the repository root to each child's PYTHONPATH.



class TestCli(unittest.TestCase):
def test_check(self) -> None:
subprocess.check_call(
[
"dargs",
*DARGS_COMMAND,
"check",
"-f",
"dargs._test.test_arguments",
Expand All @@ -22,9 +23,7 @@ def test_check(self) -> None:
)
subprocess.check_call(
[
sys.executable,
"-m",
"dargs",
*DARGS_COMMAND,
"check",
"-f",
"dargs._test.test_arguments",
Expand All @@ -35,7 +34,7 @@ def test_check(self) -> None:
with (this_directory / "test_arguments.json").open() as f:
subprocess.check_call(
[
"dargs",
*DARGS_COMMAND,
"check",
"-f",
"dargs._test.test_arguments",
Expand All @@ -47,7 +46,7 @@ def test_doc_all_arguments(self) -> None:
"""Test printing documentation for all arguments."""
result = subprocess.run(
[
"dargs",
*DARGS_COMMAND,
"doc",
"dargs._test.test_arguments",
],
Expand All @@ -68,7 +67,7 @@ def test_doc_specific_argument(self) -> None:
"""Test printing documentation for a specific argument."""
result = subprocess.run(
[
"dargs",
*DARGS_COMMAND,
"doc",
"dargs._test.test_arguments",
"test1",
Expand All @@ -89,7 +88,7 @@ def test_doc_nested_arguments(self) -> None:
# Test top-level base argument
result = subprocess.run(
[
"dargs",
*DARGS_COMMAND,
"doc",
"dargs._test.test_arguments",
"base",
Expand All @@ -106,7 +105,7 @@ def test_doc_nested_arguments(self) -> None:
# Test specific nested path
result = subprocess.run(
[
"dargs",
*DARGS_COMMAND,
"doc",
"dargs._test.test_arguments",
"base/sub1",
Expand All @@ -125,7 +124,7 @@ def test_doc_nested_arguments(self) -> None:
# Test deeply nested path
result = subprocess.run(
[
"dargs",
*DARGS_COMMAND,
"doc",
"dargs._test.test_arguments",
"base/sub2/subsub1",
Expand All @@ -143,7 +142,7 @@ def test_doc_invalid_path(self) -> None:
"""Test error handling for invalid argument path."""
result = subprocess.run(
[
"dargs",
*DARGS_COMMAND,
"doc",
"dargs._test.test_arguments",
"invalid",
Expand All @@ -158,7 +157,7 @@ def test_doc_invalid_nested_path(self) -> None:
"""Test error handling for invalid nested argument path."""
result = subprocess.run(
[
"dargs",
*DARGS_COMMAND,
"doc",
"dargs._test.test_arguments",
"base/invalid",
Expand All @@ -173,9 +172,7 @@ def test_doc_with_python_module(self) -> None:
"""Test doc command using python -m."""
result = subprocess.run(
[
sys.executable,
"-m",
"dargs",
*DARGS_COMMAND,
"doc",
"dargs._test.test_arguments",
"test1",
Expand All @@ -191,7 +188,7 @@ def test_doc_invalid_function_format(self) -> None:
"""Test error handling for invalid function format."""
result = subprocess.run(
[
"dargs",
*DARGS_COMMAND,
"doc",
"invalid_func",
],
Expand Down
Loading