From f98a0c4e18b921964cb2b4f5ac46a79262f7948e Mon Sep 17 00:00:00 2001 From: Seb M'Caw Date: Wed, 28 Aug 2024 13:13:16 +0000 Subject: [PATCH] Fix tests --- testsuite/drivers/helpers.py | 17 +++++++++++++---- .../tests/pin/branch-remote-protocols/test.yaml | 3 --- testsuite/tests/publish/private-indexes/test.py | 8 ++++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/testsuite/drivers/helpers.py b/testsuite/drivers/helpers.py index 986a9db66..b651c4295 100644 --- a/testsuite/drivers/helpers.py +++ b/testsuite/drivers/helpers.py @@ -304,7 +304,7 @@ def __exit__(self, exc_type, exc_val, exc_tb): for key in substitution_dict: args = [arg.replace(key, substitution_dict[key]) for arg in args] # Run git -p = subprocess.run(['{actual_git_path}'] + args, capture_output=True) +p = subprocess.run([r'{actual_git_path}'] + args, capture_output=True) # Output substitutions stdout, stderr = p.stdout.decode(), p.stderr.decode() for key in substitution_dict: @@ -340,12 +340,15 @@ def __enter__(self): substitution_dict=self._substitution_dict, actual_git_path=shutil.which("git") ) - # Write the script to somewhere on PATH + # Add the directory to PATH try: os.mkdir(self._mock_git_dir) except FileExistsError: pass - os.environ["PATH"] = f'{self._mock_git_dir}:{os.environ["PATH"]}' + os.environ["PATH"] = ( + f'{self._mock_git_dir}{os.pathsep}{os.environ["PATH"]}' + ) + # Write the script to the directory wrapper_descriptor = os.open( os.path.join(self._mock_git_dir, "git"), flags=(os.O_WRONLY | os.O_CREAT | os.O_EXCL), @@ -353,11 +356,17 @@ def __enter__(self): ) with open(wrapper_descriptor, "w") as f: f.write(wrapper_script) + # On Windows, use a .bat file to make executable without ".exe" suffix + if on_windows(): + with open(os.path.join(self._mock_git_dir, "git.bat"), "w") as f: + f.write(f"python {os.path.join(self._mock_git_dir, 'git')} %*") def __exit__(self, type, value, traceback): # Restore PATH os.environ["PATH"] = os.environ["PATH"].replace( - f'{self._mock_git_dir}:', '', 1 + f'{self._mock_git_dir}{os.pathsep}', '', 1 ) # Delete the wrapper script os.remove(os.path.join(self._mock_git_dir, "git")) + if on_windows(): + os.remove(os.path.join(self._mock_git_dir, "git.bat")) diff --git a/testsuite/tests/pin/branch-remote-protocols/test.yaml b/testsuite/tests/pin/branch-remote-protocols/test.yaml index ee8ead706..32c747b3f 100644 --- a/testsuite/tests/pin/branch-remote-protocols/test.yaml +++ b/testsuite/tests/pin/branch-remote-protocols/test.yaml @@ -1,4 +1 @@ driver: python-script -control: - - [SKIP, "skip_linux", "Test is Linux-only"] -indexes: {} diff --git a/testsuite/tests/publish/private-indexes/test.py b/testsuite/tests/publish/private-indexes/test.py index d3eacb0f1..29fb0db74 100644 --- a/testsuite/tests/publish/private-indexes/test.py +++ b/testsuite/tests/publish/private-indexes/test.py @@ -15,8 +15,8 @@ INDEX_PATH = os.path.join(os.getcwd(), "my_index", "index") -def run(*args): - subprocess.run(*args).check_returncode() +def run(*args, **kwargs): + subprocess.run(*args, **kwargs).check_returncode() def test( args, @@ -83,7 +83,7 @@ def test( local_path = os.path.abspath(os.path.join("..", "..", "local", "xxx")) os.makedirs(local_path) os.chdir(local_path) - run(["git", "clone", url, local_path]) + run(f"git clone {url} {local_path}", shell=True) # Run alr p = run_alr_interactive( @@ -93,7 +93,7 @@ def test( ], input=num_confirms * ["y"], complain_on_error=expect_success, - timeout=3, + timeout=10, ) # Check output matches