summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/coveragetest.py4
-rw-r--r--test/modules/pkg1/__init__.py0
-rw-r--r--test/modules/pkg1/p1a.py5
-rw-r--r--test/modules/pkg1/p1b.py3
-rw-r--r--test/modules/pkg2/__init__.py0
-rw-r--r--test/modules/pkg2/p2a.py3
-rw-r--r--test/modules/pkg2/p2b.py3
-rw-r--r--test/modules/usepkgs.py2
-rw-r--r--test/test_api.py115
9 files changed, 73 insertions, 62 deletions
diff --git a/test/coveragetest.py b/test/coveragetest.py
index 4dd87559..52fde87a 100644
--- a/test/coveragetest.py
+++ b/test/coveragetest.py
@@ -148,10 +148,10 @@ class CoverageTest(TestCase):
def import_local_file(self, modname):
"""Import a local file as a module.
-
+
Opens a file in the current directory named `modname`.py, imports it
as `modname`, and returns the module object.
-
+
"""
modfile = modname + '.py'
f = open(modfile, 'r')
diff --git a/test/modules/pkg1/__init__.py b/test/modules/pkg1/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/modules/pkg1/__init__.py
diff --git a/test/modules/pkg1/p1a.py b/test/modules/pkg1/p1a.py
new file mode 100644
index 00000000..be5fcdd3
--- /dev/null
+++ b/test/modules/pkg1/p1a.py
@@ -0,0 +1,5 @@
+import os, sys
+
+# Invoke functions in os and sys so we can see if we measure code there.
+x = sys.getcheckinterval()
+y = os.getcwd()
diff --git a/test/modules/pkg1/p1b.py b/test/modules/pkg1/p1b.py
new file mode 100644
index 00000000..59d6fb54
--- /dev/null
+++ b/test/modules/pkg1/p1b.py
@@ -0,0 +1,3 @@
+x = 1
+y = 2
+z = 3
diff --git a/test/modules/pkg2/__init__.py b/test/modules/pkg2/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/modules/pkg2/__init__.py
diff --git a/test/modules/pkg2/p2a.py b/test/modules/pkg2/p2a.py
new file mode 100644
index 00000000..b606711d
--- /dev/null
+++ b/test/modules/pkg2/p2a.py
@@ -0,0 +1,3 @@
+q = 1
+r = 1
+s = 1
diff --git a/test/modules/pkg2/p2b.py b/test/modules/pkg2/p2b.py
new file mode 100644
index 00000000..7a34e2c6
--- /dev/null
+++ b/test/modules/pkg2/p2b.py
@@ -0,0 +1,3 @@
+t = 1
+u = 1
+v = 1
diff --git a/test/modules/usepkgs.py b/test/modules/usepkgs.py
new file mode 100644
index 00000000..208e3f30
--- /dev/null
+++ b/test/modules/usepkgs.py
@@ -0,0 +1,2 @@
+import pkg1.p1a, pkg1.p1b
+import pkg2.p2a, pkg2.p2b
diff --git a/test/test_api.py b/test/test_api.py
index 9a29103f..70ea1883 100644
--- a/test/test_api.py
+++ b/test/test_api.py
@@ -280,73 +280,68 @@ class ApiTest(CoverageTest):
cov.report()
-class OmitIncludeTest(CoverageTest):
- """Test using `omit` and `include` when measuring code."""
+class SourceOmitIncludeTest(CoverageTest):
+ """Test using `source`, `omit` and `include` when measuring code."""
- def test_nothing_specified(self):
- self.make_file("a.py", """\
- a = 1
- """)
- self.make_file("b.py", """\
- import a
- b = 1
- """)
+ run_in_temp_dir = False
- cov = coverage.coverage()
- cov.start()
- self.import_local_file("b")
- cov.stop()
- lines = cov.data.summary()
- self.assertEqual(lines['a.py'], 1)
- self.assertEqual(lines['b.py'], 2)
+ 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'))
- def test_include(self):
- self.make_file("a.py", """\
- a = 1
- """)
- self.make_file("b.py", """\
- import a
- b = 1
- """)
+ def coverage_usepkgs_summary(self, **kwargs):
+ """Run coverage on usepkgs and return the line summary.
- cov = coverage.coverage(include=["a.py"])
+ Arguments are passed to the `coverage.coverage` constructor.
+
+ """
+ cov = coverage.coverage(**kwargs)
cov.start()
- self.import_local_file("b")
+ import usepkgs # pylint: disable-msg=F0401,W0612
cov.stop()
- lines = cov.data.summary()
- self.assertEqual(lines['a.py'], 1)
- self.assert_('b.py' not in lines)
+ return cov.data.summary()
- def test_omit(self):
- self.make_file("a.py", """\
- a = 1
- """)
- self.make_file("b.py", """\
- import a
- b = 1
- """)
+ 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)
+
+ 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)
+
+ 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)
- cov = coverage.coverage(omit=["a*"])
- cov.start()
- self.import_local_file("b")
- cov.stop()
- lines = cov.data.summary()
- self.assert_('a.py' not in lines)
- self.assertEqual(lines['b.py'], 2)
+ 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)
- def test_omit_and_include(self):
- self.make_file("aa.py", """\
- a = 1
- """)
- self.make_file("ab.py", """\
- import aa
- b = 1
- """)
+ 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)
- cov = coverage.coverage(include=["a*"], omit=["aa.py"])
- cov.start()
- self.import_local_file("ab")
- cov.stop()
- lines = cov.data.summary()
- self.assert_('aa.py' not in lines)
- self.assertEqual(lines['ab.py'], 2)
+ 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)