Skip to content

Commit 6c52551

Browse files
committed
Fix tests
1 parent c4d0e29 commit 6c52551

2 files changed

Lines changed: 33 additions & 39 deletions

File tree

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ def repo_dir(tmp_path_factory: pytest.TempPathFactory):
3131

3232
@pytest.fixture
3333
def repo(repo_dir):
34-
execute(repo_dir, "git init -b master")
35-
execute(repo_dir, "git config --local user.email 'tests@example.com'")
36-
execute(repo_dir, "git config --local user.name 'Tests runner'")
37-
execute(repo_dir, "git add .coveragerc")
34+
execute(repo_dir, "git", "init", "-b", "master")
35+
execute(repo_dir, "git", "config", "--local", "user.email", "tests@example.com")
36+
execute(repo_dir, "git", "config", "--local", "user.name", "Tests runner")
37+
execute(repo_dir, "git", "add", ".coveragerc")
3838
create_file(
3939
repo_dir,
4040
".gitignore",

tests/lib/util.py

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def rand_sha() -> str:
3131
return token_hex(8)
3232

3333

34-
def execute(cwd: str | os.PathLike, cmd: str, **kwargs) -> str:
34+
def execute(cwd: str | os.PathLike, *cmd: str, **kwargs) -> str:
3535
log.info("Executing '%s' at '%s'", cmd, cwd)
3636

3737
if "env" in kwargs:
@@ -40,11 +40,11 @@ def execute(cwd: str | os.PathLike, cmd: str, **kwargs) -> str:
4040
if pythonpath:
4141
kwargs["env"]["PYTHONPATH"] = pythonpath
4242

43-
return subprocess.check_output(cmd, cwd=cwd, shell=True, universal_newlines=True, **kwargs) # nosec
43+
return subprocess.check_output(cmd, cwd=cwd, universal_newlines=True, **kwargs) # nosec
4444

4545

4646
def get_full_sha(cwd: str | os.PathLike, **kwargs) -> str:
47-
return execute(cwd, "git rev-list -n 1 HEAD", **kwargs).strip()
47+
return execute(cwd, "git", "rev-list", "-n", "1", "HEAD", **kwargs).strip()
4848

4949

5050
def get_sha(cwd: str | os.PathLike, **kwargs) -> str:
@@ -57,18 +57,18 @@ def create_commit(
5757
dt: datetime | None = None,
5858
**kwargs,
5959
) -> str:
60-
options = ""
60+
options: list[str] = []
6161

6262
if dt is not None:
6363
# Store committer date in case it was set somewhere else
6464
original_committer_date = os.environ.get("GIT_COMMITTER_DATE", None)
6565

66-
options += f"--date {dt.isoformat()}"
66+
options.extend(["--date", dt.isoformat()])
6767
# The committer date is what is used to determine sort order for tags, etc
6868
os.environ["GIT_COMMITTER_DATE"] = dt.isoformat()
6969

7070
try:
71-
return_value = execute(cwd, f'git commit -m "{message}" {options}', **kwargs)
71+
return_value = execute(cwd, "git", "commit", "-m", message, *options, **kwargs)
7272
finally:
7373
# Return committer date env var to prior value if set
7474
if dt is not None:
@@ -89,21 +89,14 @@ def create_tag(
8989
commit: str | None = None,
9090
**kwargs,
9191
) -> str:
92-
options = ""
93-
if message:
94-
options += f' -a -m "{message}"'
95-
96-
if not commit:
97-
commit = ""
98-
99-
return execute(cwd, f"git tag {options} {tag} {commit}", **kwargs)
92+
message_options = ["-a", "-m", message] if message else []
93+
commit_options = [commit] if commit else []
94+
return execute(cwd, "git", "tag", *message_options, tag, *commit_options, **kwargs)
10095

10196

10297
def checkout_branch(cwd: str | os.PathLike, branch: str, *, new: bool = True, **kwargs) -> str:
103-
options = ""
104-
if new:
105-
options += " -b"
106-
return execute(cwd, f"git checkout {options} {branch}", **kwargs)
98+
options = ["-b"] if new else []
99+
return execute(cwd, "git", "checkout", *options, branch, **kwargs)
107100

108101

109102
def create_folder(
@@ -125,9 +118,9 @@ def create_folder(
125118
path.joinpath(rand_str()).touch()
126119

127120
if add:
128-
execute(cwd, f"git add {name}")
129-
log.info(execute(cwd, "git status"))
130-
log.info(execute(cwd, "git diff"))
121+
execute(cwd, "git", "add", name)
122+
log.info(execute(cwd, "git", "status"))
123+
log.info(execute(cwd, "git", "diff"))
131124

132125
if commit:
133126
create_commit(cwd, f"Add {name}")
@@ -156,9 +149,9 @@ def create_file(
156149
Path(cwd).joinpath(name).write_text(content)
157150

158151
if add:
159-
execute(cwd, f"git add {name}")
160-
log.info(execute(cwd, "git status"))
161-
log.info(execute(cwd, "git diff"))
152+
execute(cwd, "git", "add", name)
153+
log.info(execute(cwd, "git", "status"))
154+
log.info(execute(cwd, "git", "diff"))
162155

163156
if commit:
164157
create_commit(cwd, f"Add {name}")
@@ -302,32 +295,33 @@ def typed_config( # noqa: PLR0913
302295

303296

304297
def get_version_setup_py(cwd: str | os.PathLike, **kwargs) -> str:
305-
return execute(cwd, f"{sys.executable} setup.py --version", **kwargs).strip()
298+
return execute(cwd, sys.executable, "setup.py", "--version", **kwargs).strip()
306299

307300

308301
def get_version_module(cwd: str | os.PathLike, args: list[str] | None = None, **kwargs) -> str:
309-
args_str = " ".join(map(str, args or []))
310-
311302
return execute(
312303
cwd,
313-
f"{sys.executable} -m coverage run -m setuptools_git_versioning {args_str} -vv",
304+
sys.executable,
305+
"-m",
306+
"coverage",
307+
"run",
308+
"-m",
309+
"setuptools_git_versioning",
310+
*(args or []),
311+
"-vv",
314312
**kwargs,
315313
).strip()
316314

317315

318316
def get_version_script(cwd: str | os.PathLike, args: list[str] | None = None, **kwargs) -> str:
319-
args_str = " ".join(map(str, args or []))
320-
return execute(cwd, f"setuptools-git-versioning {args_str} -vv", **kwargs).strip()
317+
return execute(cwd, "setuptools-git-versioning", *(args or []), "-vv", **kwargs).strip()
321318

322319

323320
def get_version(cwd: str | os.PathLike, *, isolated: bool = False, **kwargs) -> str:
324-
cmd = f"{sys.executable} -m build -s"
325-
if not isolated:
326-
cmd += " --no-isolation"
327-
execute(cwd, cmd, **kwargs)
321+
options = [] if isolated else ["--no-isolation"]
322+
execute(cwd, sys.executable, "-m", "coverage", "run", "-m", "build", "-s", *options, **kwargs)
328323

329324
content = Path(cwd).joinpath("mypkg.egg-info/PKG-INFO").read_text().splitlines()
330-
331325
for line in content:
332326
if line.startswith("Version: "):
333327
return line.replace("Version: ", "").strip()

0 commit comments

Comments
 (0)