Skip to content

Commit 7da9c3b

Browse files
committed
Refactor "not from cwd" test for readability
By using pathlib.Path instead of os.path functions.
1 parent 06bd2c7 commit 7da9c3b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

test/test_git.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import logging
1010
import os
1111
import os.path as osp
12+
from pathlib import Path
1213
import re
1314
import shutil
1415
import subprocess
@@ -150,14 +151,13 @@ def test_it_executes_git_not_from_cwd(self, rw_dir, case):
150151
if os.name == "nt":
151152
# Copy an actual binary executable that is not git. (On Windows, running
152153
# "hostname" only displays the hostname, it never tries to change it.)
153-
other_exe_path = os.path.join(os.environ["SystemRoot"], "system32", "hostname.exe")
154-
impostor_path = os.path.join(rw_dir, "git.exe")
154+
other_exe_path = Path(os.environ["SystemRoot"], "system32", "hostname.exe")
155+
impostor_path = Path(rw_dir, "git.exe")
155156
shutil.copy(other_exe_path, impostor_path)
156157
else:
157158
# Create a shell script that doesn't do anything.
158-
impostor_path = os.path.join(rw_dir, "git")
159-
with open(impostor_path, mode="w", encoding="utf-8") as file:
160-
print("#!/bin/sh", file=file)
159+
impostor_path = Path(rw_dir, "git")
160+
impostor_path.write_text("#!/bin/sh\n", encoding="utf-8")
161161
os.chmod(impostor_path, 0o755)
162162

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy