Skip to content

Commit

Permalink
fix: fix issues with testing helper and config
Browse files Browse the repository at this point in the history
    * chore: add faulthandler_timeout to avoid the process hangs on without any information
    * fix: teardown the named directory cause the process stucks when lots of the files in the named directory
    * refactor: log more for locating directory and remove the invoking command function
  • Loading branch information
vanpipy committed Nov 14, 2023
1 parent 58c5b50 commit c84d917
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions .pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
minversion = 7.4
addopts = -ra -q
testpaths = tests
faulthandler_timeout = 5
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ def named_temp_repo(request):
dirname = request.param
repo = create_repo(dirname)
init_repo_git_status(repo)
return repo
yield repo
repo.teardown()
28 changes: 14 additions & 14 deletions tests/helper.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import os, subprocess, stat, shutil, tempfile, git
import os, subprocess, shutil, tempfile
from git import Repo

CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
GIT_EXTRAS_BIN = os.path.join(CURRENT_DIR, "..", "bin")
GIT_EXTRAS_HELPER = os.path.join(CURRENT_DIR, "..", "helper")

def invoke_git_extras_command(name, *params):
script = [os.path.join(GIT_EXTRAS_BIN, name), *params]
print(f"Run the script \"{script}\"")
return subprocess.run(script, capture_output=True)
GIT_EXTRAS_BIN = os.path.abspath(os.path.join(CURRENT_DIR, "..", "bin"))
GIT_EXTRAS_HELPER = os.path.abspath(os.path.join(CURRENT_DIR, "..", "helper"))

class TempRepository:
def __init__(self, repo_work_dir = None):
Expand All @@ -18,7 +14,7 @@ def __init__(self, repo_work_dir = None):
repo_work_dir = os.path.join(self._system_tmpdir, repo_work_dir)
self._cwd = repo_work_dir
self._tempdirname = self._cwd[len(self._system_tmpdir) + 1:]
self._git_repo = git.Repo.init(repo_work_dir, b="default")
self._git_repo = Repo.init(repo_work_dir, b="default")
self._files = []

def switch_cwd_under_repo(self):
Expand Down Expand Up @@ -69,12 +65,14 @@ def teardown(self):

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

def invoke_installed_extras_command(self, name, *params):
command_name = "git-" + name
print(f"Invoke the git-extras command - {command_name}")
print(f"Invoke the git-extras command - {command_name} at {self._cwd}")
origin_extras_command = os.path.join(GIT_EXTRAS_BIN, command_name)
temp_extras_command = os.path.join(self._cwd, command_name)
helpers = [
Expand All @@ -94,7 +92,9 @@ def invoke_installed_extras_command(self, name, *params):
whole.extend(rest)
whole.insert(0, first)
t.write("\n".join(whole))
print("Update file {temp_extras_command}:\n{t.read()}")
print(f"Update file {temp_extras_command}")
os.chmod(temp_extras_command, 0o775)

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

0 comments on commit c84d917

Please sign in to comment.