Carry the root across a reload; the tests tell it from the cwd
This commit is contained in:
+11
-11
@@ -331,38 +331,38 @@ class RunCycle(unittest.TestCase):
|
||||
|
||||
|
||||
class Reload(unittest.TestCase):
|
||||
def test_runs_the_edited_file_before_trusting_it_and_hands_it_the_counters_on_argv(self):
|
||||
def test_runs_the_edited_file_before_trusting_it_and_hands_it_the_root_and_counters_on_argv(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
script = os.path.join(root, "loop-claude")
|
||||
open(script, "w").write(loop.RELOAD_BASELINE.replace("import glob\n", "import glob\nimport no_such_module\n"))
|
||||
with unittest.mock.patch.object(loop, "__file__", script), unittest.mock.patch("os.execv") as execv:
|
||||
loop.reload_if_edited("do it", cycle_number=1, failures=0)
|
||||
loop.reload_if_edited("/r", "do it", cycle_number=1, failures=0)
|
||||
execv.assert_not_called()
|
||||
open(script, "w").write(loop.RELOAD_BASELINE.replace("RELOAD_FLAG = ", "RELOAD_FLAG = \"x\" or "))
|
||||
environment = dict(os.environ)
|
||||
with unittest.mock.patch.object(loop, "__file__", script), unittest.mock.patch("os.execv") as execv:
|
||||
loop.reload_if_edited("do it", cycle_number=1, failures=2)
|
||||
execv.assert_called_once_with(sys.executable, [sys.executable, script, loop.RELOAD_FLAG, "1", "2", "do it"])
|
||||
loop.reload_if_edited("/r", "do it", cycle_number=1, failures=2)
|
||||
execv.assert_called_once_with(sys.executable, [sys.executable, script, loop.RELOAD_FLAG, "1", "2", "/r", "do it"])
|
||||
self.assertEqual(dict(os.environ), environment)
|
||||
|
||||
|
||||
class Main(unittest.TestCase):
|
||||
def test_resumes_the_counters_a_reload_handed_over(self):
|
||||
def test_resumes_the_root_and_counters_a_reload_handed_over(self):
|
||||
patches = [unittest.mock.patch.object(loop, name) for name in ("checkout_root", "read_premises", "reload_if_edited", "run_cycle")]
|
||||
with contextlib.ExitStack() as stack:
|
||||
mocks = [stack.enter_context(patch) for patch in patches]
|
||||
stack.enter_context(unittest.mock.patch.object(sys, "argv", ["loop-claude", loop.RELOAD_FLAG, "3", "2", "do it"]))
|
||||
stack.enter_context(unittest.mock.patch.object(sys, "argv", ["loop-claude", loop.RELOAD_FLAG, "3", "2", "/r", "do it"]))
|
||||
stack.enter_context(unittest.mock.patch.object(sys, "stdout", io.StringIO()))
|
||||
mocks[0].return_value = os.getcwd()
|
||||
mocks[3].side_effect = SystemExit(0)
|
||||
with self.assertRaises(SystemExit):
|
||||
loop.main()
|
||||
mocks[1].assert_called_once_with(os.getcwd())
|
||||
mocks[2].assert_called_once_with("do it", 3, 2)
|
||||
self.assertEqual(mocks[3].call_args.args[0], os.getcwd())
|
||||
mocks[0].assert_not_called()
|
||||
mocks[1].assert_called_once_with("/r")
|
||||
mocks[2].assert_called_once_with("/r", "do it", 3, 2)
|
||||
self.assertEqual(mocks[3].call_args.args[0], "/r")
|
||||
self.assertIn("=== cycle 4 ===", sys.stdout.getvalue())
|
||||
mocks[3].side_effect = ["claude exited 3"] * 3
|
||||
stack.enter_context(unittest.mock.patch.object(sys, "argv", ["loop-claude", loop.RELOAD_FLAG, "3", "0", "do it"]))
|
||||
stack.enter_context(unittest.mock.patch.object(sys, "argv", ["loop-claude", loop.RELOAD_FLAG, "3", "0", "/r", "do it"]))
|
||||
stack.enter_context(unittest.mock.patch.object(sys, "stderr", io.StringIO()))
|
||||
sleep = stack.enter_context(unittest.mock.patch("time.sleep"))
|
||||
with self.assertRaises(SystemExit) as stopped:
|
||||
|
||||
Reference in New Issue
Block a user