diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/modules/usepkgs.py | 2 | ||||
-rw-r--r-- | test/othermods/__init__.py | 0 | ||||
-rw-r--r-- | test/othermods/othera.py | 2 | ||||
-rw-r--r-- | test/othermods/otherb.py | 2 | ||||
-rw-r--r-- | test/othermods/sub/__init__.py | 0 | ||||
-rw-r--r-- | test/othermods/sub/osa.py | 2 | ||||
-rw-r--r-- | test/othermods/sub/osb.py | 2 | ||||
-rw-r--r-- | test/test_api.py | 103 |
8 files changed, 86 insertions, 27 deletions
diff --git a/test/modules/usepkgs.py b/test/modules/usepkgs.py index 208e3f30..93c7d904 100644 --- a/test/modules/usepkgs.py +++ b/test/modules/usepkgs.py @@ -1,2 +1,4 @@ import pkg1.p1a, pkg1.p1b import pkg2.p2a, pkg2.p2b +import othermods.othera, othermods.otherb +import othermods.sub.osa, othermods.sub.osb diff --git a/test/othermods/__init__.py b/test/othermods/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/othermods/__init__.py diff --git a/test/othermods/othera.py b/test/othermods/othera.py new file mode 100644 index 00000000..78896928 --- /dev/null +++ b/test/othermods/othera.py @@ -0,0 +1,2 @@ +o = 1 +p = 2 diff --git a/test/othermods/otherb.py b/test/othermods/otherb.py new file mode 100644 index 00000000..2bd8a441 --- /dev/null +++ b/test/othermods/otherb.py @@ -0,0 +1,2 @@ +q = 3 +r = 4 diff --git a/test/othermods/sub/__init__.py b/test/othermods/sub/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/othermods/sub/__init__.py diff --git a/test/othermods/sub/osa.py b/test/othermods/sub/osa.py new file mode 100644 index 00000000..0139d28b --- /dev/null +++ b/test/othermods/sub/osa.py @@ -0,0 +1,2 @@ +s = 5 +t = 6 diff --git a/test/othermods/sub/osb.py b/test/othermods/sub/osb.py new file mode 100644 index 00000000..b024b148 --- /dev/null +++ b/test/othermods/sub/osb.py @@ -0,0 +1,2 @@ +u = 7 +v = 8 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" + ) |