Answer principles round 1: 1 🔴, 7 🟡 (0 misread); every effect is handed in as an argument, no test patches a global, and the traces principle scopes tools that run on their user's machine
CI / tests (pull_request) Successful in 3m43s
CI / tests (pull_request) Successful in 3m43s
This commit is contained in:
@@ -8,8 +8,8 @@ import tempfile
|
||||
import textwrap
|
||||
import threading
|
||||
import time
|
||||
import typing
|
||||
import unittest
|
||||
import unittest.mock
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
@@ -226,8 +226,8 @@ class ToolProcess(unittest.TestCase):
|
||||
self.assertTrue(pathlib.Path(folder, "stopped").is_file())
|
||||
|
||||
def test_an_interrupted_tool_that_ignores_sigint_is_killed_after_the_grace_period(self):
|
||||
with tempfile.TemporaryDirectory() as folder, unittest.mock.patch("mutate_changes.tool_process.GRACE_SECONDS", 0.5):
|
||||
self.assertLess(self.interrupted(folder, "trap '' INT; echo $$ > started; sleep 60;"), 30)
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
self.assertLess(self.interrupted(folder, "trap '' INT; echo $$ > started; sleep 60;", grace=0.5), 30)
|
||||
self.assert_ends(int(pathlib.Path(folder, "started").read_text()))
|
||||
|
||||
def test_an_interrupt_ends_the_run_where_the_tool_s_processes_end_first(self):
|
||||
@@ -237,10 +237,10 @@ class ToolProcess(unittest.TestCase):
|
||||
killpg(group, number)
|
||||
raise ProcessLookupError
|
||||
|
||||
with unittest.mock.patch("os.killpg", then_gone), tempfile.TemporaryDirectory() as folder:
|
||||
self.interrupted(folder, "sleep 60 & echo $! > started; wait;")
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
self.interrupted(folder, "sleep 60 & echo $! > started; wait;", killpg=then_gone)
|
||||
|
||||
def interrupted(self, folder: str, script: str) -> float:
|
||||
def interrupted(self, folder: str, script: str, **seams: typing.Any) -> float:
|
||||
"""Run script as the prefix of a tool in folder, interrupt run_tool once script writes folder/started, and return how long run_tool took."""
|
||||
started = pathlib.Path(folder, "started")
|
||||
|
||||
@@ -252,7 +252,7 @@ class ToolProcess(unittest.TestCase):
|
||||
threading.Thread(target=interrupt, daemon=True).start()
|
||||
began = time.monotonic()
|
||||
with self.assertRaises(KeyboardInterrupt):
|
||||
run_tool(["true"], folder, script)
|
||||
run_tool(["true"], folder, **{"prefix": script, "env": os.environ, "killpg": os.killpg, **seams})
|
||||
return time.monotonic() - began
|
||||
|
||||
def assert_ends(self, pid: int) -> None:
|
||||
|
||||
Reference in New Issue
Block a user