Skip to content

Prevent //torchx/cli/test:cmd_run_test from picking up user's /home/kiuk/.torchxconfig when running test cases #1046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2025
Merged
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
33 changes: 19 additions & 14 deletions torchx/cli/test/cmd_run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from unittest.mock import MagicMock, patch

from torchx.cli.argparse_util import ArgOnceAction, torchxconfig

from torchx.cli.cmd_run import _parse_component_name_and_args, CmdBuiltins, CmdRun
from torchx.schedulers.local_scheduler import SignalException

Expand Down Expand Up @@ -216,38 +215,41 @@ def test_store_experiment_id(self, mock_runner_run: MagicMock) -> None:
self.assertEqual(call_kwargs["parent_run_id"], "experiment_1")

def test_parse_component_name_and_args_no_default(self) -> None:
# set dirs to test tmpdir so tests don't accidentally pick up user's $HOME/.torchxconfig
dirs = [str(self.tmpdir)]

sp = argparse.ArgumentParser(prog="test")
self.assertEqual(
("utils.echo", []),
_parse_component_name_and_args(["utils.echo"], sp),
_parse_component_name_and_args(["utils.echo"], sp, dirs),
)
self.assertEqual(
("utils.echo", []),
_parse_component_name_and_args(["--", "utils.echo"], sp),
_parse_component_name_and_args(["--", "utils.echo"], sp, dirs),
)
self.assertEqual(
("utils.echo", ["--msg", "hello"]),
_parse_component_name_and_args(["utils.echo", "--msg", "hello"], sp),
_parse_component_name_and_args(["utils.echo", "--msg", "hello"], sp, dirs),
)

self.assertEqual(
("utils.echo", ["--msg", "hello", "--", "--"]),
_parse_component_name_and_args(
["utils.echo", "--msg", "hello", "--", "--"], sp
["utils.echo", "--msg", "hello", "--", "--"], sp, dirs
),
)

self.assertEqual(
("utils.echo", ["--msg", "hello", "-", "-"]),
_parse_component_name_and_args(
["utils.echo", "--msg", "hello", "-", "-"], sp
["utils.echo", "--msg", "hello", "-", "-"], sp, dirs
),
)

self.assertEqual(
("utils.echo", ["--msg", "hello", "- ", "- "]),
_parse_component_name_and_args(
["utils.echo", "--msg", "hello", "- ", "- "], sp
["utils.echo", "--msg", "hello", "- ", "- "], sp, dirs
),
)

Expand All @@ -274,32 +276,35 @@ def test_parse_component_name_and_args_no_default(self) -> None:
"-m",
],
sp,
dirs,
),
)

with self.assertRaises(SystemExit):
_parse_component_name_and_args(["--"], sp)
_parse_component_name_and_args(["--"], sp, dirs)

with self.assertRaises(SystemExit):
_parse_component_name_and_args(["--msg", "hello"], sp)
_parse_component_name_and_args(["--msg", "hello"], sp, dirs)

with self.assertRaises(SystemExit):
_parse_component_name_and_args(["-m", "hello"], sp)
_parse_component_name_and_args(["-m", "hello"], sp, dirs)

with self.assertRaises(SystemExit):
_parse_component_name_and_args(["-m", "hello", "-m", "repeate"], sp)
_parse_component_name_and_args(["-m", "hello", "-m", "repeate"], sp, dirs)

with self.assertRaises(SystemExit):
_parse_component_name_and_args(["--msg", "hello", "--msg", "repeate"], sp)
_parse_component_name_and_args(
["--msg", "hello", "--msg", "repeate"], sp, dirs
)

with self.assertRaises(SystemExit):
_parse_component_name_and_args(
["--msg ", "hello", "--msg ", "repeate"], sp
["--msg ", "hello", "--msg ", "repeate"], sp, dirs
)

with self.assertRaises(SystemExit):
_parse_component_name_and_args(
["--m", "hello", "--", "--msg", "msg", "--msg", "repeate"], sp
["--m", "hello", "--", "--msg", "msg", "--msg", "repeate"], sp, dirs
)

def test_parse_component_name_and_args_with_default(self) -> None:
Expand Down
Loading