Skip to content

Commit

Permalink
Refactor "not from cwd" test for readability
Browse files Browse the repository at this point in the history
By using pathlib.Path instead of os.path functions.
  • Loading branch information
EliahKagan committed Dec 26, 2023
1 parent 06bd2c7 commit 7da9c3b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging
import os
import os.path as osp
from pathlib import Path
import re
import shutil
import subprocess
Expand Down Expand Up @@ -150,14 +151,13 @@ def test_it_executes_git_not_from_cwd(self, rw_dir, case):
if os.name == "nt":
# Copy an actual binary executable that is not git. (On Windows, running
# "hostname" only displays the hostname, it never tries to change it.)
other_exe_path = os.path.join(os.environ["SystemRoot"], "system32", "hostname.exe")
impostor_path = os.path.join(rw_dir, "git.exe")
other_exe_path = Path(os.environ["SystemRoot"], "system32", "hostname.exe")
impostor_path = Path(rw_dir, "git.exe")
shutil.copy(other_exe_path, impostor_path)
else:
# Create a shell script that doesn't do anything.
impostor_path = os.path.join(rw_dir, "git")
with open(impostor_path, mode="w", encoding="utf-8") as file:
print("#!/bin/sh", file=file)
impostor_path = Path(rw_dir, "git")
impostor_path.write_text("#!/bin/sh\n", encoding="utf-8")
os.chmod(impostor_path, 0o755)

with cwd(rw_dir) if chdir_to_repo else contextlib.nullcontext():
Expand Down

0 comments on commit 7da9c3b

Please sign in to comment.