Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor "not from cwd" test for readability
By using pathlib.Path instead of os.path functions.
  • Loading branch information
EliahKagan committed Dec 26, 2023
commit 7da9c3b45a19302b346474ea3fdcda1594c33b08
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