Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb-MCaw committed Aug 28, 2024
1 parent 28f27cb commit a67762c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
16 changes: 13 additions & 3 deletions testsuite/drivers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
import shutil
import stat
import sys
from subprocess import run
from zipfile import ZipFile

Expand Down Expand Up @@ -318,6 +319,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):

class MockGit:
"""
NON-WINDOWS-ONLY
A context manager which mocks the git command with string substitutions.
The string substitutions are specified by the dictionary substitution_dict.
Expand All @@ -335,17 +337,25 @@ def __init__(self, substitution_dict, mock_git_dir):
self._mock_git_dir = mock_git_dir

def __enter__(self):
# Mocking on Windows would require git.exe wrapper
if on_windows():
print('SKIP: git mocking unavailable on Windows')
sys.exit(0)

# Create a wrapper script for git
wrapper_script = GIT_WRAPPER_TEMPLATE.format(
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),
Expand All @@ -357,7 +367,7 @@ def __enter__(self):
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"))
3 changes: 0 additions & 3 deletions testsuite/tests/pin/branch-remote-protocols/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
driver: python-script
control:
- [SKIP, "skip_linux", "Test is Linux-only"]
indexes: {}
2 changes: 1 addition & 1 deletion testsuite/tests/publish/private-indexes/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test(
],
input=num_confirms * ["y"],
complain_on_error=expect_success,
timeout=3,
timeout=10,
)

# Check output matches
Expand Down

0 comments on commit a67762c

Please sign in to comment.