Skip to content

Commit

Permalink
refactor(test): use parametrize instead of loops
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Oct 9, 2022
1 parent 12776ba commit 5be6aca
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions tests/test_files.py
Expand Up @@ -357,37 +357,34 @@ def test_paths_are_os_corrected(self, rel_yn):
r'.\mysrc\sub\a.py',
)

def test_windows_on_linux(self, rel_yn):
# Try the paths in both orders.
lin = "*/project/module/"
win = "*\\project\\module\\"
lin_win_paths = [[lin, win], [win, lin]]

@pytest.mark.parametrize("paths", lin_win_paths)
def test_windows_on_linux(self, paths, rel_yn):
# https://github.com/nedbat/coveragepy/issues/618
lin = "*/project/module/"
win = "*\\project\\module\\"

# Try the paths in both orders.
for paths in [[lin, win], [win, lin]]:
aliases = PathAliases(relative=rel_yn)
for path in paths:
aliases.add(path, "project/module")
self.assert_mapped(
aliases,
"C:\\a\\path\\somewhere\\coveragepy_test\\project\\module\\tests\\file.py",
"project/module/tests/file.py",
)

def test_linux_on_windows(self, rel_yn):
aliases = PathAliases(relative=rel_yn)
for path in paths:
aliases.add(path, "project/module")
self.assert_mapped(
aliases,
"C:\\a\\path\\somewhere\\coveragepy_test\\project\\module\\tests\\file.py",
"project/module/tests/file.py",
)

@pytest.mark.parametrize("paths", lin_win_paths)
def test_linux_on_windows(self, paths, rel_yn):
# https://github.com/nedbat/coveragepy/issues/618
lin = "*/project/module/"
win = "*\\project\\module\\"

# Try the paths in both orders.
for paths in [[lin, win], [win, lin]]:
aliases = PathAliases(relative=rel_yn)
for path in paths:
aliases.add(path, "project\\module")
self.assert_mapped(
aliases,
"C:/a/path/somewhere/coveragepy_test/project/module/tests/file.py",
"project\\module\\tests\\file.py",
)
aliases = PathAliases(relative=rel_yn)
for path in paths:
aliases.add(path, "project\\module")
self.assert_mapped(
aliases,
"C:/a/path/somewhere/coveragepy_test/project/module/tests/file.py",
"project\\module\\tests\\file.py",
)

def test_multiple_wildcard(self, rel_yn):
aliases = PathAliases(relative=rel_yn)
Expand Down

0 comments on commit 5be6aca

Please sign in to comment.