Skip to content

Commit 0ab50a9

Browse files
test: fix the four failures in the unit suite
Both pairs were test bugs, not defects in the code under test. tests/test_opencode_binary.py -- resolve_opencode_argv() returns str(Path), so the expected value has to be spelled the same way: str(Path("/mgd/opencode")) is "/mgd/opencode" on POSIX and "\mgd\opencode" on Windows. The POSIX form was hard-coded, so `test_managed_present_wins` and `test_download_when_no_path` failed on Windows only. Compare against str(Path(...)). tests/general/test_four_way_standalone.py -- `set_hp` refuses to guess when the process holds more than one hyperparam set ("Multiple hyperparam sets present; provide hp_name explicitly"), and the ledger is global: the sets registered by the other levels in this file, and by any module that ran earlier in the same process, are still there. So the two set_hp tests passed or failed depending on what had run before them. They now name their set via resolve_hp_name(), exactly as test_hp_lists_and_shows in the same file already does for `hp` -- and which its own comment explains was added for this reason. Full suite as CI runs it (pytest ./tests -m "not scale"): 1901 passed, 145 skipped, 17 deselected. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent b0347d3 commit 0ab50a9

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

tests/general/test_four_way_standalone.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,22 @@ def test_hp_lists_and_shows(self):
504504
self.assertEqual(shown["name"], name)
505505
self.assertEqual(shown["hyperparams"]["experiment_name"], "standalone_config")
506506

507+
# `set_hp` refuses to guess when the process holds more than one
508+
# hyperparam set ("Multiple hyperparam sets present; provide hp_name
509+
# explicitly"), and the ledger is global: the sets registered by the other
510+
# levels in this file (and by any test module that ran earlier in the same
511+
# process) are still there. Name the set, exactly as test_hp_lists_and_shows
512+
# already does for `hp` -- the alternative, asserting on whichever set the
513+
# CLI happens to pick, is what made these two order-dependent.
507514
def test_set_hp_updates_the_live_config(self):
508-
answer = self.cli("set_hp optimizer.lr 0.0005")
515+
answer = self.cli(f"set_hp {resolve_hp_name()} optimizer.lr 0.0005")
509516
self.assertTrue(answer["ok"], answer)
510517
self.assertEqual(answer["key"], "optimizer.lr")
511518
self.assertEqual(answer["value"], 0.0005)
512519
self.assertEqual(self.hp["optimizer"]["lr"], 0.0005)
513520

514521
def test_set_hp_updates_a_nested_data_key(self):
515-
answer = self.cli("set_hp data.train_loader.batch_size 32")
522+
answer = self.cli(f"set_hp {resolve_hp_name()} data.train_loader.batch_size 32")
516523
self.assertTrue(answer["ok"], answer)
517524
self.assertEqual(self.hp["data"]["train_loader"]["batch_size"], 32)
518525

tests/test_opencode_binary.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,17 @@ class ResolverPrecedenceTests(unittest.TestCase):
218218
"""opencode_process.resolve_opencode_argv order:
219219
managed-present -> PATH -> managed-download -> npx -> None."""
220220

221+
# resolve_opencode_argv returns str(Path), so the expected value has to be
222+
# spelled the same way: str(Path("/mgd/opencode")) is "/mgd/opencode" on
223+
# POSIX and "\\mgd\\opencode" on Windows. Hard-coding the POSIX form made
224+
# these two fail on Windows only, for no reason in the code under test.
225+
MANAGED = str(Path("/mgd/opencode"))
226+
221227
def test_managed_present_wins(self):
222228
with patch.object(opencode_process.opencode_binary, "find_managed_binary",
223229
return_value=Path("/mgd/opencode")), \
224230
patch.object(opencode_process.shutil, "which", return_value="/usr/bin/opencode"):
225-
self.assertEqual(opencode_process.resolve_opencode_argv(), ["/mgd/opencode"])
231+
self.assertEqual(opencode_process.resolve_opencode_argv(), [self.MANAGED])
226232

227233
def test_path_used_before_download(self):
228234
with patch.object(opencode_process.opencode_binary, "find_managed_binary", return_value=None), \
@@ -237,7 +243,7 @@ def test_download_when_no_path(self):
237243
patch.object(opencode_process.opencode_binary, "ensure_managed_binary",
238244
return_value=Path("/mgd/opencode")), \
239245
patch.object(opencode_process.shutil, "which", return_value=None):
240-
self.assertEqual(opencode_process.resolve_opencode_argv(), ["/mgd/opencode"])
246+
self.assertEqual(opencode_process.resolve_opencode_argv(), [self.MANAGED])
241247

242248
def test_npx_last_resort(self):
243249
def which(name):

0 commit comments

Comments
 (0)