Kill the surviving mutants of run-tests and wait-for, and name a file wait-for cannot read
CI / tests (pull_request) Successful in 2m38s
CI / tests (pull_request) Successful in 2m38s
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import contextlib
|
||||
import io
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -57,6 +59,51 @@ class WaitFor(unittest.TestCase):
|
||||
def test_gives_up_on_a_file_that_never_appears(self):
|
||||
self.assertEqual(main.waited(str(self.file), None, 5, Clock()), Failure(f"{self.file} did not appear in 5 s"))
|
||||
|
||||
def test_reads_a_line_that_is_not_utf_8(self):
|
||||
self.file.write_bytes(b"caf\xe9 passed\n")
|
||||
self.assertEqual(main.waited(str(self.file), "passed", 60, Clock()), "caf\ufffd passed")
|
||||
|
||||
def test_an_empty_file_gives_up_saying_it_held_nothing_and_no_last_line(self):
|
||||
self.file.write_text("")
|
||||
clock = Clock()
|
||||
self.assertEqual(main.waited(str(self.file), None, 3, clock), Failure(f"{self.file} held nothing after 3 s"))
|
||||
self.assertEqual(clock.now, 3)
|
||||
|
||||
def test_sleeps_only_the_time_left_before_the_timeout(self):
|
||||
clock = Clock()
|
||||
main.waited(str(self.file), None, 3, clock)
|
||||
self.assertEqual(clock.now, 3)
|
||||
clock = Clock()
|
||||
main.waited(str(self.file), None, 2.5, clock)
|
||||
self.assertEqual(clock.now, 2.5)
|
||||
|
||||
def test_a_folder_fails_at_once_naming_it(self):
|
||||
self.assertEqual(main.waited(str(self.file.parent), None, 60, Clock()), Failure(f"cannot read {self.file.parent}: Is a directory"))
|
||||
|
||||
def test_main_prints_the_line_or_the_reason_and_gives_the_exit_code(self):
|
||||
self.file.write_text("== 1 passed ==\n")
|
||||
for argv, expected in (
|
||||
([str(self.file), "passed", "--timeout", "5"], (0, "== 1 passed ==\n", "")),
|
||||
(["--help"], (0, main.__doc__.strip() + "\n", "")),
|
||||
([str(self.file), "("], (1, "", "wait-for: cannot read the pattern `(`: missing ), unterminated subpattern at position 0\n")),
|
||||
):
|
||||
with self.subTest(argv=argv):
|
||||
out, err = io.StringIO(), io.StringIO()
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
|
||||
code = main.main(argv)
|
||||
self.assertEqual((code, out.getvalue(), err.getvalue()), expected)
|
||||
|
||||
def test_arguments_take_the_timeout_anywhere_and_refuse_a_bad_one(self):
|
||||
self.assertEqual(main.arguments(["--timeout", "1.5", "f", "p"]), ("f", "p", 1.5))
|
||||
self.assertEqual(main.arguments(["f"]), ("f", None, 540.0))
|
||||
for timeout in ("0", "-1", "x", "1.", None):
|
||||
with self.subTest(timeout=timeout):
|
||||
argv = ["f", "--timeout"] + ([timeout] if timeout else [])
|
||||
self.assertEqual(main.arguments(argv), Failure(f"give --timeout a number of seconds above 0; {main.USAGE}"))
|
||||
for argv in ([], ["f", "a", "b"]):
|
||||
with self.subTest(argv=argv):
|
||||
self.assertEqual(main.arguments(argv), Failure(main.USAGE))
|
||||
|
||||
def test_the_command_waits_for_a_file_another_process_writes(self):
|
||||
writer = threading.Timer(0.5, lambda: self.file.write_text("== 1 passed in 0.1s ==\n"))
|
||||
writer.start()
|
||||
|
||||
Reference in New Issue
Block a user