Skip to content

Commit

Permalink
Address msys/mingw vs native windows path diffs
Browse files Browse the repository at this point in the history
… in system tests, with a very naive conversion function
  • Loading branch information
abravalheri committed Jul 28, 2019
1 parent 7d82a20 commit 86c88d5
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tests/system/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

import inspect
import os
import re
import shutil
from contextlib import contextmanager
from glob import glob
from os.path import dirname
from os.path import join as path_join
from pathlib import Path
from shutil import copyfile

import pytest
Expand Down Expand Up @@ -50,6 +52,8 @@
"https://bugs.python.org/issue993766 "
"see #244")

WINFILE_REGEX = re.compile(r"^\\(\w)\\(.*)$", re.MULTILINE)


untar = shell.ShellCommand(
("gtar" if command_exists("gtar") else "tar") + " xvzkf")
Expand All @@ -58,6 +62,27 @@
# https://xkcd.com/1168/


def _windows_path(path):
path = str(Path(path))
return WINFILE_REGEX.sub(path, r"\1:\\\2")


def path_in(path1, path2, is_win=IS_WIN):
if is_win:
path1 = _windows_path(path1).lower()
path2 = _windows_path(path2).lower()

return str(path1) in str(path2)


if IS_WIN:
assert path_in(
r"C:\Users\U\AppData\Local\Temp\pytest-0\popen-gw2\.ven",
"/c/Users/U/AppData/Local/Temp/pytest-0/popen-gw2/.ven/Scripts/demo",
)
# ^ Meta-test to ensure path_in works


@pytest.fixture
def demoapp(tmpfolder, venv):
return DemoApp(tmpfolder, venv)
Expand Down Expand Up @@ -117,7 +142,7 @@ def check_not_installed(self):

def check_inside_venv(self):
cmd_path = self.venv.run('which', self.name)
if str(self.venv.path) not in cmd_path:
if not path_in(self.venv.path, cmd_path):
raise RuntimeError('{} should be installed inside the venv ({}), '
'but path is {}'
.format(self.name, self.venv.path, cmd_path))
Expand Down

0 comments on commit 86c88d5

Please sign in to comment.