diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_api.py | 186 | ||||
-rw-r--r-- | test/test_files.py | 7 |
2 files changed, 95 insertions, 98 deletions
diff --git a/test/test_api.py b/test/test_api.py index 8f270098..83f82f12 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -360,29 +360,17 @@ class UsingModulesMixin(object): super(UsingModulesMixin, self).tearDown() -class SourceOmitIncludeTest(UsingModulesMixin, CoverageTest): - """Test using `source`, `omit` and `include` when measuring code.""" - - def coverage_usepkgs_summary(self, **kwargs): - """Run coverage on usepkgs and return the line summary. +class OmitIncludeTestsMixin(UsingModulesMixin): + """Test methods for coverage methods taking include and omit.""" - Arguments are passed to the `coverage.coverage` constructor. - - """ - cov = coverage.coverage(**kwargs) - cov.start() - import usepkgs # pylint: disable=F0401,W0612 - cov.stop() - return cov.data.summary() - - def filenames_in_summary(self, summary, filenames): + def filenames_in(self, summary, filenames): """Assert the `filenames` are in the keys of `summary`.""" for filename in filenames.split(): self.assert_(filename in summary, "%s should be in %r" % (filename, summary) ) - def filenames_not_in_summary(self, summary, filenames): + def filenames_not_in(self, summary, filenames): """Assert the `filenames` are not in the keys of `summary`.""" for filename in filenames.split(): self.assert_(filename not in summary, @@ -390,100 +378,110 @@ class SourceOmitIncludeTest(UsingModulesMixin, CoverageTest): ) def test_nothing_specified(self): - lines = self.coverage_usepkgs_summary() - self.filenames_in_summary(lines, - "p1a.py p1b.py p2a.py p2b.py othera.py otherb.py osa.py osb.py" - ) - self.filenames_not_in_summary(lines, - "p1c.py" - ) + result = self.coverage_usepkgs() + self.filenames_in(result, "p1a p1b p2a p2b othera otherb osa osb") + self.filenames_not_in(result, "p1c") # Because there was no source= specified, we don't search for # unexecuted files. - def test_source_package(self): - lines = self.coverage_usepkgs_summary(source=["pkg1"]) - self.filenames_in_summary(lines, - "p1a.py p1b.py" - ) - self.filenames_not_in_summary(lines, - "p2a.py p2b.py othera.py otherb.py osa.py osb.py" - ) - # Because source= was specified, we do search for unexecuted files. - self.assertEqual(lines['p1c.py'], 0) - - def test_source_package_dotted(self): - lines = self.coverage_usepkgs_summary(source=["pkg1.p1b"]) - self.filenames_in_summary(lines, - "p1b.py" - ) - self.filenames_not_in_summary(lines, - "p1a.py p1c.py p2a.py p2b.py othera.py otherb.py osa.py osb.py" - ) - def test_include(self): - lines = self.coverage_usepkgs_summary(include=["*/p1a.py"]) - self.filenames_in_summary(lines, - "p1a.py" - ) - self.filenames_not_in_summary(lines, - "p1b.py p1c.py p2a.py p2b.py othera.py otherb.py osa.py osb.py" - ) + result = self.coverage_usepkgs(include=["*/p1a.py"]) + self.filenames_in(result, "p1a") + self.filenames_not_in(result, "p1b p1c p2a p2b othera otherb osa osb") def test_include_2(self): - lines = self.coverage_usepkgs_summary(include=["*a.py"]) - self.filenames_in_summary(lines, - "p1a.py p2a.py othera.py osa.py" - ) - self.filenames_not_in_summary(lines, - "p1b.py p1c.py p2b.py otherb.py osb.py" - ) + result = self.coverage_usepkgs(include=["*a.py"]) + self.filenames_in(result, "p1a p2a othera osa") + self.filenames_not_in(result, "p1b p1c p2b otherb osb") def test_include_as_string(self): - lines = self.coverage_usepkgs_summary(include="*a.py") - self.filenames_in_summary(lines, - "p1a.py p2a.py othera.py osa.py" - ) - self.filenames_not_in_summary(lines, - "p1b.py p1c.py p2b.py otherb.py osb.py" - ) + result = self.coverage_usepkgs(include="*a.py") + self.filenames_in(result, "p1a p2a othera osa") + self.filenames_not_in(result, "p1b p1c p2b otherb osb") def test_omit(self): - lines = self.coverage_usepkgs_summary(omit=["*/p1a.py"]) - self.filenames_in_summary(lines, - "p1b.py p2a.py p2b.py" - ) - self.filenames_not_in_summary(lines, - "p1a.py p1c.py" - ) + result = self.coverage_usepkgs(omit=["*/p1a.py"]) + self.filenames_in(result, "p1b p2a p2b") + self.filenames_not_in(result, "p1a p1c") def test_omit_2(self): - lines = self.coverage_usepkgs_summary(omit=["*a.py"]) - self.filenames_in_summary(lines, - "p1b.py p2b.py otherb.py osb.py" - ) - self.filenames_not_in_summary(lines, - "p1a.py p1c.py p2a.py othera.py osa.py" - ) + result = self.coverage_usepkgs(omit=["*a.py"]) + self.filenames_in(result, "p1b p2b otherb osb") + self.filenames_not_in(result, "p1a p1c p2a othera osa") def test_omit_as_string(self): - lines = self.coverage_usepkgs_summary(omit="*a.py") - self.filenames_in_summary(lines, - "p1b.py p2b.py otherb.py osb.py" - ) - self.filenames_not_in_summary(lines, - "p1a.py p1c.py p2a.py othera.py osa.py" - ) + result = self.coverage_usepkgs(omit="*a.py") + self.filenames_in(result, "p1b p2b otherb osb") + self.filenames_not_in(result, "p1a p1c p2a othera osa") def test_omit_and_include(self): - lines = self.coverage_usepkgs_summary( - include=["*/p1*"], omit=["*/p1a.py"] - ) - self.filenames_in_summary(lines, - "p1b.py" - ) - self.filenames_not_in_summary(lines, - "p1a.py p1c.py p2a.py p2b.py" - ) + result = self.coverage_usepkgs( include=["*/p1*"], omit=["*/p1a.py"]) + self.filenames_in(result, "p1b") + self.filenames_not_in(result, "p1a p1c p2a p2b") + + +class SourceOmitIncludeTest(OmitIncludeTestsMixin, CoverageTest): + """Test using `source`, `omit` and `include` when measuring code.""" + + def coverage_usepkgs(self, **kwargs): + """Run coverage on usepkgs and return the line summary. + + Arguments are passed to the `coverage.coverage` constructor. + + """ + cov = coverage.coverage(**kwargs) + cov.start() + import usepkgs # pylint: disable=F0401,W0612 + cov.stop() + summary = cov.data.summary() + for k, v in summary.items(): + assert k.endswith(".py") + summary[k[:-3]] = v + return summary + + def test_source_package(self): + lines = self.coverage_usepkgs(source=["pkg1"]) + self.filenames_in(lines, "p1a p1b") + self.filenames_not_in(lines, "p2a p2b othera otherb osa osb") + # Because source= was specified, we do search for unexecuted files. + self.assertEqual(lines['p1c'], 0) + + def test_source_package_dotted(self): + lines = self.coverage_usepkgs(source=["pkg1.p1b"]) + self.filenames_in(lines, "p1b") + self.filenames_not_in(lines, "p1a p1c p2a p2b othera otherb osa osb") + + +class ReportIncludeOmitTest(OmitIncludeTestsMixin, CoverageTest): + """Tests of the report include/omit functionality.""" + + def coverage_usepkgs(self, **kwargs): + """Try coverage.report().""" + cov = coverage.coverage() + cov.start() + import usepkgs # pylint: disable=F0401,W0612 + cov.stop() + report = StringIO() + cov.report(file=report, **kwargs) + return report.getvalue() + + +class XmlIncludeOmitTest(OmitIncludeTestsMixin, CoverageTest): + """Tests of the xml include/omit functionality. + + This also takes care of the HTML and annotate include/omit, by virtue + of the structure of the code. + + """ + + def coverage_usepkgs(self, **kwargs): + """Try coverage.xml_report().""" + cov = coverage.coverage() + cov.start() + import usepkgs # pylint: disable=F0401,W0612 + cov.stop() + cov.xml_report(outfile="-", **kwargs) + return self.stdout() class AnalysisTest(CoverageTest): diff --git a/test/test_files.py b/test/test_files.py index f2f3581e..207274a2 100644 --- a/test/test_files.py +++ b/test/test_files.py @@ -3,7 +3,7 @@ import os, sys from coverage.files import FileLocator, TreeMatcher, FnmatchMatcher -from coverage.files import PathAliases, find_python_files +from coverage.files import PathAliases, find_python_files, abs_file from coverage.backward import set # pylint: disable=W0622 from coverage.misc import CoverageException @@ -43,10 +43,10 @@ class FileLocatorTest(CoverageTest): # Technically, this test doesn't do that on Windows, but drive # letters make that impractical to acheive. fl = FileLocator() - d = fl.abs_file(os.curdir) + d = abs_file(os.curdir) trick = os.path.splitdrive(d)[1].lstrip(os.path.sep) rel = os.path.join('sub', trick, 'file1.py') - self.assertEqual(fl.relative_filename(fl.abs_file(rel)), rel) + self.assertEqual(fl.relative_filename(abs_file(rel)), rel) class MatcherTest(CoverageTest): @@ -168,4 +168,3 @@ class FindPythonFilesTest(CoverageTest): "sub/a.py", "sub/b.py", "sub/ssub/__init__.py", "sub/ssub/s.py", ]) - |