Answer stability round 1: 0 🔴, 5 🟡 (0 misread); run both tools in a scratch copy, read Infection's two sources, end PHPUnit's list, spell glob characters
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""The copy of a tree that a mutation tool runs in."""
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import unittest.mock
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from failure import Failure
|
||||
from task_bench.scratch_copy import scratch_copy
|
||||
|
||||
|
||||
class ScratchCopyTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
folder = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(folder.cleanup)
|
||||
self.top = pathlib.Path(folder.name)
|
||||
(self.top / "src").mkdir()
|
||||
(self.top / "src/pick.ts").write_text("code", encoding="utf-8")
|
||||
(self.top / ".hidden").write_text("kept", encoding="utf-8")
|
||||
|
||||
def test_copies_every_entry_of_the_tree_into_a_scratch_folder_in_it(self):
|
||||
scratch, copy = scratch_copy(str(self.top))
|
||||
self.assertRegex(scratch, rf"^{self.top}/\.mutate-changes-[^/]+$")
|
||||
self.assertEqual(copy, f"{scratch}/copy")
|
||||
self.assertEqual(sorted(str(path.relative_to(copy)) for path in pathlib.Path(copy).rglob("*")), [".hidden", "src", "src/pick.ts"])
|
||||
self.assertEqual(pathlib.Path(copy, "src/pick.ts").read_text(encoding="utf-8"), "code")
|
||||
|
||||
def test_keeps_a_link_as_a_link(self):
|
||||
(self.top / "linked").symlink_to("src/missing.ts")
|
||||
_, copy = scratch_copy(str(self.top))
|
||||
self.assertEqual(os.readlink(os.path.join(copy, "linked")), "src/missing.ts")
|
||||
|
||||
def test_copies_a_folder_below_the_top_that_has_the_scratch_folders_name(self):
|
||||
first, _ = scratch_copy(str(self.top))
|
||||
(self.top / "src" / os.path.basename(first)).mkdir()
|
||||
_, copy = scratch_copy(str(self.top))
|
||||
self.assertTrue(os.path.isdir(os.path.join(copy, "src", os.path.basename(first))))
|
||||
|
||||
def test_fails_without_a_scratch_folder_left_where_the_tree_cannot_be_copied(self):
|
||||
with unittest.mock.patch("shutil.copytree", side_effect=OSError("No space left on device")):
|
||||
found = scratch_copy(str(self.top))
|
||||
self.assertIsInstance(found, Failure)
|
||||
self.assertRegex(found.reason, rf"^could not copy {self.top} into {self.top}/\.mutate-changes-[^/]+: No space left on device$")
|
||||
self.assertEqual(sorted(path.name for path in self.top.iterdir()), [".hidden", "src"])
|
||||
|
||||
def test_passes_on_that_no_scratch_folder_could_be_made(self):
|
||||
found = scratch_copy(str(self.top / "missing"))
|
||||
self.assertIsInstance(found, Failure)
|
||||
self.assertIn("could not make a scratch folder in ", found.reason)
|
||||
Reference in New Issue
Block a user