Skip to content

Commit

Permalink
Fix tests on Windows
Browse files Browse the repository at this point in the history
Convert parths to posix where git expects it.
  • Loading branch information
Kentzo committed Nov 14, 2018
1 parent 9cc9263 commit 8e40ff4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
4 changes: 1 addition & 3 deletions git_archive_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def walk_git_files(self, repo_path=''):
continue

for main_repo_submodule_file_path in self.walk_git_files(main_repo_submodule_path):
repo_submodule_file_path = main_repo_submodule_file_path.replace(repo_path, "", 1).strip("/") # relative to repo_path
repo_submodule_file_path = path.relpath(main_repo_submodule_file_path, repo_path) # relative to repo_path
if self.is_file_excluded(repo_abspath, repo_submodule_file_path):
continue

Expand Down Expand Up @@ -398,8 +398,6 @@ def read_attrs(process, repo_file_path):
repo_file_attrs = {}

for path, attr, value in read_attrs(process, repo_file_path):
assert path == repo_file_path
assert attr in attrs
repo_file_attrs[attr] = value

yield repo_file_attrs
Expand Down
27 changes: 17 additions & 10 deletions test_git_archive_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ def makedirs(p):
raise


def as_posix(p):
if sys.platform.startswith('win32'):
return str(p).replace('\\', '/')
else:
return str(p)


@pytest.fixture
def git_env(tmpdir_factory):
"""
Expand All @@ -42,7 +49,7 @@ def git_env(tmpdir_factory):
with tmpdir_factory.getbasetemp().join('.gitconfig').open('w+') as f:
f.writelines([
'[core]\n',
'attributesfile = {0}/.gitattributes\n'.format(tmpdir_factory.getbasetemp()),
'attributesfile = {0}\n'.format(as_posix(tmpdir_factory.getbasetemp().join('.gitattributes'))),
'[user]\n',
'name = git-archive-all\n',
'email = [email protected]\n',
Expand Down Expand Up @@ -98,15 +105,15 @@ def add_file(self, rel_path, contents):
with open(file_path, 'w') as f:
f.write(contents)

check_call(['git', 'add', file_path], cwd=self.path)
check_call(['git', 'add', as_posix(os.path.normpath(file_path))], cwd=self.path)
return file_path

def add_dir(self, rel_path, contents):
dir_path = os.path.join(self.path, rel_path)
makedirs(dir_path)

for k, v in contents.items():
self.add(os.path.join(dir_path, k), v)
self.add(as_posix(os.path.normpath(os.path.join(dir_path, k))), v)

check_call(['git', 'add', dir_path], cwd=self.path)
return dir_path
Expand All @@ -117,7 +124,7 @@ def add_submodule(self, rel_path, contents):
r.init()
r.add_dir('.', contents)
r.commit('init')
check_call(['git', 'submodule', 'add', submodule_path], cwd=self.path)
check_call(['git', 'submodule', 'add', as_posix(os.path.normpath(submodule_path))], cwd=self.path)
return submodule_path

def commit(self, message):
Expand Down Expand Up @@ -250,7 +257,7 @@ def archive(self, path):

@pytest.mark.parametrize('contents', [
pytest.param(base, id='No Ignore'),
pytest.param(base_quoted, id='No Ignore (Quoted)'),
pytest.param(base_quoted, id='No Ignore (Quoted)', marks=pytest.mark.skipif(sys.platform.startswith('win32'), reason="Invalid Windows filename.")),
pytest.param(ignore_in_root, id='Ignore in Root'),
pytest.param(ignore_in_submodule, id='Ignore in Submodule'),
pytest.param(ignore_in_nested_submodule, id='Ignore in Nested Submodule'),
Expand All @@ -259,11 +266,11 @@ def archive(self, path):
pytest.param(ignore_in_nested_submodule_from_submodule, id='Ignore in Nested Submodule from Submodule'),
pytest.param(unset_export_ignore, id='-export-ignore'),
pytest.param(unicode_base, id='No Ignore (Unicode)'),
pytest.param(unicode_quoted, id='No Ignore (Quoted Unicode)'),
pytest.param(unicode_quoted, id='No Ignore (Quoted Unicode)', marks=pytest.mark.skipif(sys.platform.startswith('win32'), reason="Invalid Windows filename.")),
pytest.param(brackets_base, id='Brackets'),
pytest.param(brackets_quoted, id="Brackets (Quoted)"),
pytest.param(quote_base, id="Quote"),
pytest.param(quote_quoted, id="Quote (Quoted)")
pytest.param(brackets_quoted, id="Brackets (Quoted)", marks=pytest.mark.skipif(sys.platform.startswith('win32'), reason="Invalid Windows filename.")),
pytest.param(quote_base, id="Quote", marks=pytest.mark.skipif(sys.platform.startswith('win32'), reason="Invalid Windows filename.")),
pytest.param(quote_quoted, id="Quote (Quoted)", marks=pytest.mark.skipif(sys.platform.startswith('win32'), reason="Invalid Windows filename."))
])
def test_ignore(contents, tmpdir, git_env, monkeypatch):
"""
Expand All @@ -290,7 +297,7 @@ def make_expected(contents):
e[k] = v.contents
elif v.kind in ('dir', 'submodule') and not v.excluded:
for nested_k, nested_v in make_expected(v.contents).items():
e[os.path.join(k, nested_k)] = nested_v
e[as_posix(os.path.join(k, nested_k))] = nested_v

return e

Expand Down

0 comments on commit 8e40ff4

Please sign in to comment.