Skip to content

Commit da79cee

Browse files
committed
refactor(helper): log more for locating directory and remove the invoking command function
1 parent d4e3539 commit da79cee

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

tests/helper.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import os, subprocess, stat, shutil, tempfile, git
1+
import os, subprocess, shutil, tempfile
2+
from git import Repo
23

34
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
4-
GIT_EXTRAS_BIN = os.path.join(CURRENT_DIR, "..", "bin")
5-
GIT_EXTRAS_HELPER = os.path.join(CURRENT_DIR, "..", "helper")
6-
7-
def invoke_git_extras_command(name, *params):
8-
script = [os.path.join(GIT_EXTRAS_BIN, name), *params]
9-
print(f"Run the script \"{script}\"")
10-
return subprocess.run(script, capture_output=True)
5+
GIT_EXTRAS_BIN = os.path.abspath(os.path.join(CURRENT_DIR, "..", "bin"))
6+
GIT_EXTRAS_HELPER = os.path.abspath(os.path.join(CURRENT_DIR, "..", "helper"))
117

128
class TempRepository:
139
def __init__(self, repo_work_dir = None):
@@ -18,7 +14,7 @@ def __init__(self, repo_work_dir = None):
1814
repo_work_dir = os.path.join(self._system_tmpdir, repo_work_dir)
1915
self._cwd = repo_work_dir
2016
self._tempdirname = self._cwd[len(self._system_tmpdir) + 1:]
21-
self._git_repo = git.Repo.init(repo_work_dir, b="default")
17+
self._git_repo = Repo.init(repo_work_dir, b="default")
2218
self._files = []
2319

2420
def switch_cwd_under_repo(self):
@@ -69,12 +65,14 @@ def teardown(self):
6965

7066
def invoke_extras_command(self, name, *params):
7167
command_name = "git-" + name
72-
print(f"Invoke the git-extras command - {command_name}")
73-
return invoke_git_extras_command(command_name, *params)
68+
print(f"Invoke the git-extras command - {command_name} at {self._cwd}")
69+
script = [os.path.join(GIT_EXTRAS_BIN, command_name), *list(params)]
70+
print(f"Run the script \"{' '.join(script)}\"")
71+
return subprocess.run(script, capture_output=True)
7472

7573
def invoke_installed_extras_command(self, name, *params):
7674
command_name = "git-" + name
77-
print(f"Invoke the git-extras command - {command_name}")
75+
print(f"Invoke the git-extras command - {command_name} at {self._cwd}")
7876
origin_extras_command = os.path.join(GIT_EXTRAS_BIN, command_name)
7977
temp_extras_command = os.path.join(self._cwd, command_name)
8078
helpers = [
@@ -94,7 +92,9 @@ def invoke_installed_extras_command(self, name, *params):
9492
whole.extend(rest)
9593
whole.insert(0, first)
9694
t.write("\n".join(whole))
97-
print("Update file {temp_extras_command}:\n{t.read()}")
95+
print(f"Update file {temp_extras_command}")
9896
os.chmod(temp_extras_command, 0o775)
9997

100-
return subprocess.run([temp_extras_command, *params], capture_output=True)
98+
script = [temp_extras_command, *params]
99+
print(f"Run the script \"{script}\"")
100+
return subprocess.run(script, capture_output=True)

0 commit comments

Comments
 (0)