Add unit tests for utility functions#229
Conversation
Signed-off-by: Sahithi Chigurupati <schigurupati@nvidia.com>
📝 WalkthroughWalkthroughA new test module is added containing unit tests for core utility functions spanning submission configuration, SLURM environment handling, container mount formatting, and CLI argument construction. Tests validate environment variable precedence, YAML file discovery, node expansion, and argument transformation logic. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/test_utils.py (1)
294-319: Consider patching at the import site for more targeted mocking.The current approach patches
subprocess.runglobally. While this works correctly, patching at the import site (srtctl.core.slurm.subprocess.run) is a best practice that ensures the mock only affects the module under test and doesn't inadvertently impact other code that might run during the test.♻️ Suggested improvement
def test_expands_nodelist_via_scontrol(self, monkeypatch): monkeypatch.setenv("SLURM_NODELIST", "h100-[01-03]") mock_result = MagicMock() mock_result.stdout = "h100-01\nh100-02\nh100-03" mock_result.returncode = 0 - with patch("subprocess.run", return_value=mock_result) as mock_run: + with patch("srtctl.core.slurm.subprocess.run", return_value=mock_result) as mock_run: nodes = get_slurm_nodelist() assert nodes == ["h100-01", "h100-02", "h100-03"] mock_run.assert_called_once_with( ["scontrol", "show", "hostnames", "h100-[01-03]"], capture_output=True, text=True, check=True, ) def test_falls_back_to_raw_nodelist_on_scontrol_failure(self, monkeypatch): monkeypatch.setenv("SLURM_NODELIST", "single-node") - with patch("subprocess.run", side_effect=FileNotFoundError): + with patch("srtctl.core.slurm.subprocess.run", side_effect=FileNotFoundError): nodes = get_slurm_nodelist() assert nodes == ["single-node"] def test_falls_back_on_subprocess_error(self, monkeypatch): monkeypatch.setenv("SLURM_NODELIST", "node01") - with patch("subprocess.run", side_effect=subprocess.CalledProcessError(1, "scontrol")): + with patch("srtctl.core.slurm.subprocess.run", side_effect=subprocess.CalledProcessError(1, "scontrol")): nodes = get_slurm_nodelist() assert nodes == ["node01"]🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/test_utils.py` around lines 294 - 319, Tests patch subprocess.run globally which can affect other modules; change the patch target to the import site used by the code under test. Update the three tests (those calling get_slurm_nodelist) to patch "srtctl.core.slurm.subprocess.run" instead of "subprocess.run" so the mock only replaces the subprocess.run used inside get_slurm_nodelist; keep the same return_value/side_effect behavior and assertions (including mock_run.assert_called_once_with and the expected node lists).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/test_utils.py`:
- Around line 294-319: Tests patch subprocess.run globally which can affect
other modules; change the patch target to the import site used by the code under
test. Update the three tests (those calling get_slurm_nodelist) to patch
"srtctl.core.slurm.subprocess.run" instead of "subprocess.run" so the mock only
replaces the subprocess.run used inside get_slurm_nodelist; keep the same
return_value/side_effect behavior and assertions (including
mock_run.assert_called_once_with and the expected node lists).
Summary
tests/test_utils.pycovering 10 previously untested functions across four modules:submit.py,config.py,slurm.py,and
sglang.pyCoverage added
cli/submit.pyget_job_name,is_sweep_config,find_yaml_filescore/config.pyload_cluster_config,resolve_config_with_defaults,validate_config_filecore/slurm.pyget_slurm_job_id,get_slurm_nodelist,get_container_mounts_strbackends/sglang.py_config_to_cli_argsTest plan
make checkpasses (lint + all tests)🤖 Generated with Claude Code
Summary by CodeRabbit
Note: This release contains no user-visible changes—all updates are internal test enhancements.