Merge pull request #14 from kevinveenbirkenbach/fix/branch-cleanup-held-once-codacy
fix(branch): close the Codacy issues of the held-once read
This commit is contained in:
3 files changed
+6
-89
No files matched your search
@@ -4,13 +4,13 @@ import io
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from contextlib import ExitStack, redirect_stderr, redirect_stdout
|
||||
from unittest.mock import patch
|
||||
|
||||
from pkgmgr.actions.branch import gc
|
||||
from pkgmgr.core.git import run
|
||||
|
||||
AUTHOR = {
|
||||
"GIT_AUTHOR_NAME": "t",
|
||||
@@ -20,10 +20,9 @@ AUTHOR = {
|
||||
}
|
||||
MERGED = 12
|
||||
REGISTRATIONS = 40
|
||||
GIT = shutil.which("git")
|
||||
|
||||
|
||||
@unittest.skipUnless(GIT, "git builds the repository under test")
|
||||
@unittest.skipUnless(shutil.which("git"), "git builds the repository under test")
|
||||
class TestHeldBranchesReadOnce(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
@@ -34,21 +33,14 @@ class TestHeldBranchesReadOnce(unittest.TestCase):
|
||||
home = os.path.join(self.root, "home")
|
||||
os.makedirs(home)
|
||||
clean = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")}
|
||||
patcher = patch.dict(os.environ, {**clean, "HOME": home}, clear=True)
|
||||
patcher = patch.dict(os.environ, {**clean, **AUTHOR, "HOME": home}, clear=True)
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
self.repo = os.path.join(self.root, "repo")
|
||||
self._shape()
|
||||
|
||||
def git(self, *args: str) -> str:
|
||||
return subprocess.run(
|
||||
[GIT, "-c", "commit.gpgsign=false", *args],
|
||||
cwd=self.repo,
|
||||
env={**os.environ, **AUTHOR},
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
).stdout.strip()
|
||||
return run(["-c", "commit.gpgsign=false", *args], cwd=self.repo)
|
||||
|
||||
def _write(self, path: str, text: str) -> None:
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
@@ -57,8 +49,8 @@ class TestHeldBranchesReadOnce(unittest.TestCase):
|
||||
|
||||
def _shape(self) -> None:
|
||||
origin = os.path.join(self.root, "origin.git")
|
||||
subprocess.run([GIT, "init", "-q", "--bare", "-b", "main", origin], check=True)
|
||||
subprocess.run([GIT, "init", "-q", "-b", "main", self.repo], check=True)
|
||||
run(["init", "-q", "--bare", "-b", "main", origin], cwd=self.root)
|
||||
run(["init", "-q", "-b", "main", self.repo], cwd=self.root)
|
||||
self.git("remote", "add", "origin", origin)
|
||||
self._write(os.path.join(self.repo, "c1"), "c1")
|
||||
self.git("add", "c1")
|
||||
|
||||
Reference in new issue
Block a user