Skip to content

Commit eff7237

Browse files
committed
refactor(test): use parametrize instead of loops
1 parent 3e81b93 commit eff7237

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

tests/test_files.py

+26-29
Original file line numberDiff line numberDiff line change
@@ -357,37 +357,34 @@ def test_paths_are_os_corrected(self, rel_yn):
357357
r'.\mysrc\sub\a.py',
358358
)
359359

360-
def test_windows_on_linux(self, rel_yn):
360+
# Try the paths in both orders.
361+
lin = "*/project/module/"
362+
win = "*\\project\\module\\"
363+
lin_win_paths = [[lin, win], [win, lin]]
364+
365+
@pytest.mark.parametrize("paths", lin_win_paths)
366+
def test_windows_on_linux(self, paths, rel_yn):
361367
# https://github.com/nedbat/coveragepy/issues/618
362-
lin = "*/project/module/"
363-
win = "*\\project\\module\\"
364-
365-
# Try the paths in both orders.
366-
for paths in [[lin, win], [win, lin]]:
367-
aliases = PathAliases(relative=rel_yn)
368-
for path in paths:
369-
aliases.add(path, "project/module")
370-
self.assert_mapped(
371-
aliases,
372-
"C:\\a\\path\\somewhere\\coveragepy_test\\project\\module\\tests\\file.py",
373-
"project/module/tests/file.py",
374-
)
375-
376-
def test_linux_on_windows(self, rel_yn):
368+
aliases = PathAliases(relative=rel_yn)
369+
for path in paths:
370+
aliases.add(path, "project/module")
371+
self.assert_mapped(
372+
aliases,
373+
"C:\\a\\path\\somewhere\\coveragepy_test\\project\\module\\tests\\file.py",
374+
"project/module/tests/file.py",
375+
)
376+
377+
@pytest.mark.parametrize("paths", lin_win_paths)
378+
def test_linux_on_windows(self, paths, rel_yn):
377379
# https://github.com/nedbat/coveragepy/issues/618
378-
lin = "*/project/module/"
379-
win = "*\\project\\module\\"
380-
381-
# Try the paths in both orders.
382-
for paths in [[lin, win], [win, lin]]:
383-
aliases = PathAliases(relative=rel_yn)
384-
for path in paths:
385-
aliases.add(path, "project\\module")
386-
self.assert_mapped(
387-
aliases,
388-
"C:/a/path/somewhere/coveragepy_test/project/module/tests/file.py",
389-
"project\\module\\tests\\file.py",
390-
)
380+
aliases = PathAliases(relative=rel_yn)
381+
for path in paths:
382+
aliases.add(path, "project\\module")
383+
self.assert_mapped(
384+
aliases,
385+
"C:/a/path/somewhere/coveragepy_test/project/module/tests/file.py",
386+
"project\\module\\tests\\file.py",
387+
)
391388

392389
def test_multiple_wildcard(self, rel_yn):
393390
aliases = PathAliases(relative=rel_yn)

0 commit comments

Comments
 (0)