diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2011-03-21 21:40:07 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2011-03-21 21:40:07 -0400 |
commit | 8cb2411f3ed6db02f7a7dd60883c8dd698b5a69f (patch) | |
tree | 25fbf9dd1a32ae0ecefa84af8d9ee2c077b31848 /test/test_api.py | |
parent | dbb18122b857053130a1bc6e39bfcd4445abec53 (diff) | |
download | python-coveragepy-git-8cb2411f3ed6db02f7a7dd60883c8dd698b5a69f.tar.gz |
--omit and --include now interpret their values more usefully. Fixes #121.
Diffstat (limited to 'test/test_api.py')
-rw-r--r-- | test/test_api.py | 103 |
1 files changed, 76 insertions, 27 deletions
diff --git a/test/test_api.py b/test/test_api.py index aee0734a..ccd7a29e 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -304,7 +304,14 @@ class SourceOmitIncludeTest(CoverageTest): def setUp(self): super(SourceOmitIncludeTest, self).setUp() # Parent class saves and restores sys.path, we can just modify it. - sys.path.append(self.nice_file(os.path.dirname(__file__), 'modules')) + #sys.path.append(self.nice_file(os.path.dirname(__file__), 'modules')) + self.old_dir = os.getcwd() + os.chdir(self.nice_file(os.path.dirname(__file__), 'modules')) + sys.path.append(".") + + def tearDown(self): + os.chdir(self.old_dir) + super(SourceOmitIncludeTest, self).tearDown() def coverage_usepkgs_summary(self, **kwargs): """Run coverage on usepkgs and return the line summary. @@ -318,52 +325,94 @@ class SourceOmitIncludeTest(CoverageTest): cov.stop() return cov.data.summary() + def filenames_in_summary(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): + """Assert the `filenames` are not in the keys of `summary`.""" + for filename in filenames.split(): + self.assert_(filename not in summary, + "%s should not be in %r" % (filename, summary) + ) + def test_nothing_specified(self): lines = self.coverage_usepkgs_summary() - self.assertEqual(lines['p1a.py'], 3) - self.assertEqual(lines['p1b.py'], 3) - self.assertEqual(lines['p2a.py'], 3) - self.assertEqual(lines['p2b.py'], 3) + 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" + ) # Because there was no source= specified, we don't search for # unexecuted files. - self.assert_('p1c.py' not in lines) def test_source_package(self): lines = self.coverage_usepkgs_summary(source=["pkg1"]) - self.assertEqual(lines['p1a.py'], 3) - self.assertEqual(lines['p1b.py'], 3) - self.assert_('p2a.py' not in lines) - self.assert_('p2b.py' not in lines) + 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.assert_('p1a.py' not in lines) - self.assertEqual(lines['p1b.py'], 3) - self.assert_('p2a.py' not in lines) - self.assert_('p2b.py' not in lines) - self.assert_('p1c.py' not in lines) + 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.assertEqual(lines['p1a.py'], 3) - self.assert_('p1b.py' not in lines) - self.assert_('p2a.py' not in lines) - self.assert_('p2b.py' not in lines) + 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" + ) + + 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" + ) def test_omit(self): lines = self.coverage_usepkgs_summary(omit=["*/p1a.py"]) - self.assert_('p1a.py' not in lines) - self.assertEqual(lines['p1b.py'], 3) - self.assertEqual(lines['p2a.py'], 3) - self.assertEqual(lines['p2b.py'], 3) + self.filenames_in_summary(lines, + "p1b.py p2a.py p2b.py" + ) + self.filenames_not_in_summary(lines, + "p1a.py p1c.py" + ) + + 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" + ) def test_omit_and_include(self): lines = self.coverage_usepkgs_summary( include=["*/p1*"], omit=["*/p1a.py"] ) - self.assert_('p1a.py' not in lines) - self.assertEqual(lines['p1b.py'], 3) - self.assert_('p2a.py' not in lines) - self.assert_('p2b.py' not in lines) + self.filenames_in_summary(lines, + "p1b.py" + ) + self.filenames_not_in_summary(lines, + "p1a.py p1c.py p2a.py p2b.py" + ) |