diff options
-rw-r--r-- | tests/coveragetest.py | 21 | ||||
-rw-r--r-- | tests/helpers.py | 6 | ||||
-rw-r--r-- | tests/test_api.py | 10 |
3 files changed, 19 insertions, 18 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py index 65678d52..415dd4ab 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -22,7 +22,7 @@ from coverage.backward import StringIO, import_local_file, string_class, shlex_q from coverage.cmdline import CoverageScript from tests.helpers import arcs_to_arcz_repr, arcz_to_arcs, assert_count_equal -from tests.helpers import run_command +from tests.helpers import nice_file, run_command from tests.mixins import PytestBase, StdStreamCapturingMixin, SysPathModulesMixin, TempDirMixin @@ -262,15 +262,10 @@ class CoverageTest( finally: cov._warn = original_warn - def nice_file(self, *fparts): - """Canonicalize the file name composed of the parts in `fparts`.""" - fname = os.path.join(*fparts) - return os.path.normcase(os.path.abspath(os.path.realpath(fname))) - def assert_same_files(self, flist1, flist2): """Assert that `flist1` and `flist2` are the same set of file names.""" - flist1_nice = [self.nice_file(f) for f in flist1] - flist2_nice = [self.nice_file(f) for f in flist2] + flist1_nice = [nice_file(f) for f in flist1] + flist2_nice = [nice_file(f) for f in flist2] assert_count_equal(flist1_nice, flist2_nice) def assert_exists(self, fname): @@ -393,8 +388,8 @@ class CoverageTest( if env.JYTHON: pythonpath_name = "JYTHONPATH" # pragma: only jython - testmods = self.nice_file(self.working_root(), 'tests/modules') - zipfile = self.nice_file(self.working_root(), 'tests/zipmods.zip') + testmods = nice_file(self.working_root(), "tests/modules") + zipfile = nice_file(self.working_root(), "tests/zipmods.zip") pypath = os.getenv(pythonpath_name, '') if pypath: pypath += os.pathsep @@ -407,7 +402,7 @@ class CoverageTest( def working_root(self): """Where is the root of the coverage.py working tree?""" - return os.path.dirname(self.nice_file(coverage.__file__, "..")) + return os.path.dirname(nice_file(coverage.__file__, "..")) def report_from_command(self, cmd): """Return the report from the `cmd`, with some convenience added.""" @@ -451,8 +446,8 @@ class UsingModulesMixin(object): super(UsingModulesMixin, self).setup_test() # Parent class saves and restores sys.path, we can just modify it. - sys.path.append(self.nice_file(TESTS_DIR, 'modules')) - sys.path.append(self.nice_file(TESTS_DIR, 'moremodules')) + sys.path.append(nice_file(TESTS_DIR, "modules")) + sys.path.append(nice_file(TESTS_DIR, "moremodules")) def command_line(args): diff --git a/tests/helpers.py b/tests/helpers.py index c916c8a2..262d9301 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -93,6 +93,12 @@ def make_file(filename, text="", bytes=b"", newline=None): return filename +def nice_file(*fparts): + """Canonicalize the file name composed of the parts in `fparts`.""" + fname = os.path.join(*fparts) + return os.path.normcase(os.path.abspath(os.path.realpath(fname))) + + class CheckUniqueFilenames(object): """Asserts the uniqueness of file names passed to a function.""" def __init__(self, wrapped): diff --git a/tests/test_api.py b/tests/test_api.py index e7f02738..f24beaf4 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -22,7 +22,7 @@ from coverage.files import abs_file, relative_filename from coverage.misc import CoverageException from tests.coveragetest import CoverageTest, TESTS_DIR, UsingModulesMixin -from tests.helpers import assert_count_equal, change_dir +from tests.helpers import assert_count_equal, change_dir, nice_file class ApiTest(CoverageTest): @@ -879,7 +879,7 @@ class SourceIncludeOmitTest(IncludeOmitTestsMixin, CoverageTest): assert lines['p1c'] == 0 def test_source_package_as_dir(self): - os.chdir(self.nice_file(TESTS_DIR, 'modules')) + os.chdir(nice_file(TESTS_DIR, "modules")) assert os.path.isdir("pkg1") lines = self.coverage_usepkgs(source=["pkg1"]) self.filenames_in(lines, "p1a p1b") @@ -905,7 +905,7 @@ class SourceIncludeOmitTest(IncludeOmitTestsMixin, CoverageTest): # the search for unexecuted files, and given a score of 0%. # The omit arg is by path, so need to be in the modules directory. - os.chdir(self.nice_file(TESTS_DIR, 'modules')) + os.chdir(nice_file(TESTS_DIR, "modules")) lines = self.coverage_usepkgs(source=["pkg1"], omit=["pkg1/p1b.py"]) self.filenames_in(lines, "p1a") self.filenames_not_in(lines, "p1b") @@ -920,7 +920,7 @@ class SourceIncludeOmitTest(IncludeOmitTestsMixin, CoverageTest): def test_ambiguous_source_package_as_dir(self): # pkg1 is a directory and a pkg, since we cd into tests/modules/ambiguous - os.chdir(self.nice_file(TESTS_DIR, 'modules', "ambiguous")) + os.chdir(nice_file(TESTS_DIR, "modules", "ambiguous")) # pkg1 defaults to directory because tests/modules/ambiguous/pkg1 exists lines = self.coverage_usepkgs(source=["pkg1"]) self.filenames_in(lines, "ambiguous") @@ -928,7 +928,7 @@ class SourceIncludeOmitTest(IncludeOmitTestsMixin, CoverageTest): def test_ambiguous_source_package_as_package(self): # pkg1 is a directory and a pkg, since we cd into tests/modules/ambiguous - os.chdir(self.nice_file(TESTS_DIR, 'modules', "ambiguous")) + os.chdir(nice_file(TESTS_DIR, "modules", "ambiguous")) lines = self.coverage_usepkgs(source_pkgs=["pkg1"]) self.filenames_in(lines, "p1a p1b") self.filenames_not_in(lines, "p2a p2b othera otherb osa osb ambiguous") |