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:
@@ -2,10 +2,10 @@ import pathlib
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import unittest.mock
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from test_env import assert_not_root
|
||||
from do_epic.config import DoEpicConfig
|
||||
from failure import Failure
|
||||
from do_epic.repos import locate, Located, Unsure
|
||||
@@ -14,9 +14,9 @@ from project_config.doubles import write_config
|
||||
|
||||
|
||||
class FakeGit:
|
||||
"""git as locate calls it: origins maps a checkout to its origin URL, cloned holds each `clone` that worked, and refused names a URL whose clone fails after it made the checkout's `.git`, as a stopped git does."""
|
||||
def __init__(self, origins: dict[str, str | Failure], refused: str | None = None) -> None:
|
||||
self.origins, self.refused = origins, refused
|
||||
"""git as locate calls it: origins maps a checkout to its origin URL, cloned holds each `clone` that worked, and refused names a URL whose clone fails after it made the checkout's `.git`, as a stopped git does. Where locked, that clone also takes away the right to remove what it made."""
|
||||
def __init__(self, origins: dict[str, str | Failure], refused: str | None = None, locked: bool = False) -> None:
|
||||
self.origins, self.refused, self.locked = origins, refused, locked
|
||||
self.cloned: list[tuple[str, str]] = []
|
||||
self.clone_timeouts: list[float | None] = []
|
||||
self.clone_options: list[tuple[str, ...]] = []
|
||||
@@ -30,6 +30,8 @@ class FakeGit:
|
||||
url, destination = args[clone + 2:clone + 4]
|
||||
pathlib.Path(destination, ".git").mkdir(parents=True)
|
||||
if url == self.refused:
|
||||
if self.locked:
|
||||
pathlib.Path(destination).chmod(0o500)
|
||||
return Failure("git clone: repository not found")
|
||||
self.cloned.append((url, destination))
|
||||
self.clone_timeouts.append(timeout)
|
||||
@@ -110,9 +112,12 @@ class LocateTest(unittest.TestCase):
|
||||
self.assertIn(f"{self.billing} has an origin, billing, with no host and owner to put another repo under", self.unsure(FakeGit(self.origins)))
|
||||
|
||||
def test_asks_all_the_same_where_the_leftovers_of_a_failed_clone_cannot_be_removed(self) -> None:
|
||||
assert_not_root(self)
|
||||
self.configure()
|
||||
with unittest.mock.patch("do_epic.repos.shutil.rmtree", side_effect=lambda path, ignore_errors: None if ignore_errors is True else self.fail("rmtree must ignore errors")):
|
||||
self.assertIn("cannot clone", self.unsure(FakeGit(self.origins, refused="git@github.com:acme/ledger")))
|
||||
left = self.home / "code" / "ledger"
|
||||
self.addCleanup(lambda: left.chmod(0o700))
|
||||
self.assertIn("cannot clone", self.unsure(FakeGit(self.origins, refused="git@github.com:acme/ledger", locked=True)))
|
||||
self.assertTrue((left / ".git").is_dir())
|
||||
|
||||
def test_asks_where_the_clone_fails_naming_the_url_and_the_reason(self) -> None:
|
||||
self.configure()
|
||||
|
||||
Reference in New Issue
Block a user