Skip to content

Commit ee050a4

Browse files
Make CI jobs use matrix.os value and fix tests for macOS & Windows (#211)
* Make CI jobs use matrix.os value and fix config Signed-off-by: Christophe Bedard <[email protected]> * Do macOS-specific setup Signed-off-by: Christophe Bedard <[email protected]> * Disable Windows CI job Signed-off-by: Christophe Bedard <[email protected]> * Re-enable Windows job Signed-off-by: Christophe Bedard <[email protected]> * Fix tests on Windows Signed-off-by: Christophe Bedard <[email protected]> * reorder functions to minimize diff * reduce logic change, keep comparing strings, not bytes Co-authored-by: Dirk Thomas <[email protected]>
1 parent 9186775 commit ee050a4

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
jobs:
99
build:
1010

11-
runs-on: ubuntu-latest
11+
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
1414
os: [ubuntu-latest]
@@ -29,8 +29,13 @@ jobs:
2929
run: |
3030
python -m pip install --upgrade pip setuptools wheel
3131
python -m pip install --upgrade PyYAML
32+
- name: Install dependencies (macOS)
33+
run: |
34+
brew install subversion mercurial
35+
if: matrix.os == 'macos-latest'
3236
- name: Test with pytest
3337
run: |
3438
pip install --upgrade coverage flake8 flake8-docstrings flake8-import-order pytest
3539
git config --global --add init.defaultBranch master
36-
PYTHONPATH=`pwd` pytest -s -v test
40+
git config --global --add advice.detachedHead true
41+
${{ matrix.os == 'windows-latest' && 'set PYTHONPATH=%cd% &&' || 'PYTHONPATH=`pwd`' }} pytest -s -v test

test/test_commands.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
from vcstool.clients.git import GitClient # noqa: E402
1010
from vcstool.util import rmtree # noqa: E402
1111

12+
file_uri_scheme = 'file://' if sys.platform != 'win32' else 'file:///'
13+
1214
REPOS_FILE = os.path.join(os.path.dirname(__file__), 'list.repos')
13-
REPOS_FILE_URL = 'file://' + REPOS_FILE
15+
REPOS_FILE_URL = file_uri_scheme + REPOS_FILE
1416
REPOS2_FILE = os.path.join(os.path.dirname(__file__), 'list2.repos')
1517
TEST_WORKSPACE = os.path.join(
1618
os.path.dirname(os.path.dirname(__file__)), 'test_workspace')
@@ -189,6 +191,11 @@ def test_pull_api(self):
189191
invocation.
190192
"""
191193
output = output.replace(pull_warning, '')
194+
# the output was retrieved through a different way here
195+
output = adapt_command_output(output.encode()).decode()
196+
if sys.platform == 'win32':
197+
# it does not include carriage return characters on Windows
198+
output = output.replace('\n', '\r\n')
192199
expected = get_expected_output('pull').decode()
193200
assert output == expected
194201

@@ -216,6 +223,12 @@ def test_reimport(self):
216223
output = run_command(
217224
'import', ['--force', '--input', REPOS_FILE, '.'])
218225
expected = get_expected_output('reimport_force')
226+
# on Windows, the "Already on 'master'" message is after the
227+
# "Your branch is up to date with ..." message, so remove it
228+
# from both output and expected strings
229+
if sys.platform == 'win32':
230+
output = output.replace(b"Already on 'master'\r\n", b'')
231+
expected = expected.replace(b"Already on 'master'\r\n", b'')
219232
# newer git versions don't append three dots after the commit hash
220233
assert output == expected or output == expected.replace(b'... ', b' ')
221234

@@ -352,6 +365,11 @@ def run_command(command, args=None, subfolder=None):
352365
output = subprocess.check_output(
353366
[sys.executable, script] + (args or []),
354367
stderr=subprocess.STDOUT, cwd=cwd, env=env)
368+
return adapt_command_output(output, cwd)
369+
370+
371+
def adapt_command_output(output, cwd=None):
372+
assert type(output) == bytes
355373
# replace message from older git versions
356374
output = output.replace(
357375
b'git checkout -b new_branch_name',
@@ -386,6 +404,23 @@ def run_command(command, args=None, subfolder=None):
386404
# replace GitHub SSH clone URL
387405
output = output.replace(
388406
b'[email protected]:', b'https://github.com/')
407+
if sys.platform == 'win32':
408+
if cwd:
409+
# on Windows, git prints full path to repos
410+
# in some messages, so make it relative
411+
cwd_abs = os.path.abspath(cwd).replace('\\', '/')
412+
output = output.replace(cwd_abs.encode(), b'.')
413+
# replace path separators in specific paths;
414+
# this is less likely to cause wrong test results
415+
paths_to_replace = [
416+
(b'.\\immutable', b'./immutable'),
417+
(b'.\\vcstool', b'./vcstool'),
418+
(b'.\\without_version', b'./without_version'),
419+
(b'\\hash', b'/hash'),
420+
(b'\\tag', b'/tag'),
421+
]
422+
for before, after in paths_to_replace:
423+
output = output.replace(before, after)
389424
return output
390425

391426

0 commit comments

Comments
 (0)