style(scripts): format the scripts and their tests with ruff
Output of `ruff format` and nothing else, in its own commit so the diff is reviewable (#112). The ruff-check hook is skipped for this commit only: its findings are fixed in the next one. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
This commit is contained in:
1 parent
557f573df2
commit
db1c1e176f
12 files changed
+1520
-427
No files matched your search
@@ -54,14 +54,20 @@ exit 0
|
||||
"""
|
||||
|
||||
|
||||
@unittest.skipUnless(shutil.which("bash") and shutil.which("git"), "bash and git are required")
|
||||
@unittest.skipUnless(
|
||||
shutil.which("bash") and shutil.which("git"), "bash and git are required"
|
||||
)
|
||||
class DevSetupTest(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.tmp = Path(tempfile.mkdtemp(prefix="kamino-devsetup-"))
|
||||
self.addCleanup(shutil.rmtree, self.tmp, True)
|
||||
self.stubs = self.tmp / "stubs"
|
||||
self.stubs.mkdir()
|
||||
for name, body in (("python", PYTHON_STUB), ("pip", PIP_STUB), ("pre-commit", PRECOMMIT_STUB)):
|
||||
for name, body in (
|
||||
("python", PYTHON_STUB),
|
||||
("pip", PIP_STUB),
|
||||
("pre-commit", PRECOMMIT_STUB),
|
||||
):
|
||||
path = self.stubs / name
|
||||
path.write_text(body)
|
||||
path.chmod(0o755)
|
||||
@@ -80,9 +86,15 @@ class DevSetupTest(unittest.TestCase):
|
||||
"KAMINO_PYTHON": str(self.stubs / "python"),
|
||||
}
|
||||
|
||||
def git(self, repo: Path, *args: str, check: bool = True) -> subprocess.CompletedProcess:
|
||||
return subprocess.run(["git", "-C", str(repo), *args], env=self.env, check=check,
|
||||
capture_output=True)
|
||||
def git(
|
||||
self, repo: Path, *args: str, check: bool = True
|
||||
) -> subprocess.CompletedProcess:
|
||||
return subprocess.run(
|
||||
["git", "-C", str(repo), *args],
|
||||
env=self.env,
|
||||
check=check,
|
||||
capture_output=True,
|
||||
)
|
||||
|
||||
def make_repo(self, name: str = "repo") -> Path:
|
||||
repo = self.tmp / name
|
||||
@@ -92,13 +104,23 @@ class DevSetupTest(unittest.TestCase):
|
||||
self.git(repo, "init", "--quiet")
|
||||
return repo
|
||||
|
||||
def run_setup(self, repo: Path, cwd: Path | None = None, **extra: str) -> subprocess.CompletedProcess:
|
||||
def run_setup(
|
||||
self, repo: Path, cwd: Path | None = None, **extra: str
|
||||
) -> subprocess.CompletedProcess:
|
||||
env = {**self.env, **extra}
|
||||
return subprocess.run(["bash", str(repo / "scripts" / "dev-setup.sh")], env=env,
|
||||
cwd=str(cwd or repo), capture_output=True, text=True, check=False)
|
||||
return subprocess.run(
|
||||
["bash", str(repo / "scripts" / "dev-setup.sh")],
|
||||
env=env,
|
||||
cwd=str(cwd or repo),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
|
||||
def hooks_z(self, repo: Path) -> bytes:
|
||||
return self.git(repo, "config", "--local", "-z", "--get-all", "core.hooksPath", check=False).stdout
|
||||
return self.git(
|
||||
repo, "config", "--local", "-z", "--get-all", "core.hooksPath", check=False
|
||||
).stdout
|
||||
|
||||
def add_hooks_path(self, repo: Path, *values: str) -> None:
|
||||
for value in values:
|
||||
@@ -164,7 +186,9 @@ class DevSetupTest(unittest.TestCase):
|
||||
|
||||
def test_multi_valued_setting_is_restored(self) -> None:
|
||||
repo = self.make_repo()
|
||||
self.add_hooks_path(repo, ".git/hooks", str(repo / ".git" / "hooks"), "./.git/hooks/")
|
||||
self.add_hooks_path(
|
||||
repo, ".git/hooks", str(repo / ".git" / "hooks"), "./.git/hooks/"
|
||||
)
|
||||
before = self.hooks_z(repo)
|
||||
result = self.run_setup(repo)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
@@ -223,8 +247,10 @@ class DevSetupTest(unittest.TestCase):
|
||||
result = self.run_setup(repo, cwd=other)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertFalse((other / ".venv").exists())
|
||||
self.assertEqual(os.listdir(other / ".git" / "hooks"),
|
||||
[n for n in os.listdir(other / ".git" / "hooks") if n.endswith(".sample")])
|
||||
self.assertEqual(
|
||||
os.listdir(other / ".git" / "hooks"),
|
||||
[n for n in os.listdir(other / ".git" / "hooks") if n.endswith(".sample")],
|
||||
)
|
||||
self.assertTrue((repo / ".venv").is_dir())
|
||||
self.assertTrue(self.hook(repo).exists())
|
||||
|
||||
@@ -234,8 +260,14 @@ class DevSetupTest(unittest.TestCase):
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
workdir = self.tmp / "hookcwd"
|
||||
workdir.mkdir()
|
||||
hook = subprocess.run([str(self.hook(repo))], env={**self.env}, cwd=str(workdir),
|
||||
capture_output=True, text=True, check=False)
|
||||
hook = subprocess.run(
|
||||
[str(self.hook(repo))],
|
||||
env={**self.env},
|
||||
cwd=str(workdir),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
self.assertEqual(hook.returncode, 0, hook.stderr)
|
||||
lines = hook.stdout.splitlines()
|
||||
self.assertEqual(lines[0], "hook-ran")
|
||||
|
||||
Reference in new issue
Block a user