diff options
author | Arthur Rio <arthurio@users.noreply.github.com> | 2022-08-06 13:06:25 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-06 12:06:25 -0700 |
commit | 41602b5ecfe602c53cef84fec249ed07dbd89538 (patch) | |
tree | 77c6066c147f274d257906e70109ed2366cfd040 /tests/test_files.py | |
parent | eaf55921248211a81be231d7d20d73460cb369fb (diff) | |
download | python-coveragepy-git-41602b5ecfe602c53cef84fec249ed07dbd89538.tar.gz |
fix: paths were wrong when running from root (#1403)
* Fix paths when running coverage from root
* Add simple tests
* Use nested pattern for older python versions
Diffstat (limited to 'tests/test_files.py')
-rw-r--r-- | tests/test_files.py | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/tests/test_files.py b/tests/test_files.py index 5588c373..28a98fb8 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -5,17 +5,14 @@ import os import os.path +from unittest import mock import pytest -from coverage import env -from coverage import files +from coverage import env, files from coverage.exceptions import ConfigError -from coverage.files import ( - TreeMatcher, FnmatchMatcher, ModuleMatcher, PathAliases, - find_python_files, abs_file, actual_path, flat_rootname, fnmatches_to_regex, -) - +from coverage.files import (FnmatchMatcher, ModuleMatcher, PathAliases, TreeMatcher, abs_file, + actual_path, find_python_files, flat_rootname, fnmatches_to_regex) from tests.coveragetest import CoverageTest @@ -67,6 +64,19 @@ class FilesTest(CoverageTest): assert 'sub/proj1/file1.py' in files.CANONICAL_FILENAME_CACHE assert files.canonical_filename('sub/proj1/file1.py') == self.abs_path('file1.py') + @pytest.mark.parametrize( + ["curdir", "sep"], [ + ("/", "/"), + ("X:\\", "\\"), + ] + ) + def test_relative_dir_for_root(self, curdir, sep): + with mock.patch.object(files.os, 'curdir', new=curdir): + with mock.patch.object(files.os, 'sep', new=sep): + with mock.patch('coverage.files.os.path.normcase', return_value=curdir): + files.set_relative_directory() + assert files.relative_directory() == curdir + @pytest.mark.parametrize("original, flat", [ ("abc.py", "abc_py"), |