summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Szakmeister <john@szakmeister.net>2013-03-17 02:14:39 -0700
committerJohn Szakmeister <john@szakmeister.net>2013-03-17 02:14:39 -0700
commit846382d4c78e6e18c7026477f86c9a7cbace414f (patch)
tree4e74f15d27c04708b70e9fef99da48b8c5668c80
parent657e4a9174ccaacd42d07648eba81f32a77e94b3 (diff)
parentf914095be88d01cbbd585dbf694cc884b9ca48f0 (diff)
downloadnose-846382d4c78e6e18c7026477f86c9a7cbace414f.tar.gz
Merge pull request #639 from jszakmeister/coverage-fixes
Fix --cover-min-percentage for both single and multiple packages
-rw-r--r--functional_tests/test_coverage_plugin.py79
-rw-r--r--nose/plugins/cover.py15
2 files changed, 91 insertions, 3 deletions
diff --git a/functional_tests/test_coverage_plugin.py b/functional_tests/test_coverage_plugin.py
index d58a519..b4069bf 100644
--- a/functional_tests/test_coverage_plugin.py
+++ b/functional_tests/test_coverage_plugin.py
@@ -71,6 +71,59 @@ class TestCoverageMinPercentagePlugin(PluginTester, unittest.TestCase):
pass
+class TestCoverageMinPercentageSinglePackagePlugin(
+ PluginTester, unittest.TestCase):
+ activate = "--with-coverage"
+ args = ['-v', '--cover-package=blah', '--cover-html',
+ '--cover-min-percentage', '100']
+ plugins = [Coverage()]
+ suitepath = os.path.join(support, 'coverage')
+
+ def setUp(self):
+ if not hasCoverage:
+ raise unittest.SkipTest('coverage not available; skipping')
+
+ self.cover_file = os.path.join(os.getcwd(), '.coverage')
+ self.cover_html_dir = os.path.join(os.getcwd(), 'cover')
+ if os.path.exists(self.cover_file):
+ os.unlink(self.cover_file)
+ if os.path.exists(self.cover_html_dir):
+ shutil.rmtree(self.cover_html_dir)
+ self.assertRaises(SystemExit,
+ super(TestCoverageMinPercentageSinglePackagePlugin,
+ self).setUp)
+
+ def runTest(self):
+ pass
+
+
+class TestCoverageMinPercentageSinglePackageWithBranchesPlugin(
+ PluginTester, unittest.TestCase):
+ activate = "--with-coverage"
+ args = ['-v', '--cover-package=blah', '--cover-branches',
+ '--cover-html', '--cover-min-percentage', '100']
+ plugins = [Coverage()]
+ suitepath = os.path.join(support, 'coverage')
+
+ def setUp(self):
+ if not hasCoverage:
+ raise unittest.SkipTest('coverage not available; skipping')
+
+ self.cover_file = os.path.join(os.getcwd(), '.coverage')
+ self.cover_html_dir = os.path.join(os.getcwd(), 'cover')
+ if os.path.exists(self.cover_file):
+ os.unlink(self.cover_file)
+ if os.path.exists(self.cover_html_dir):
+ shutil.rmtree(self.cover_html_dir)
+ self.assertRaises(
+ SystemExit,
+ super(TestCoverageMinPercentageSinglePackageWithBranchesPlugin,
+ self).setUp)
+
+ def runTest(self):
+ pass
+
+
class TestCoverageMinPercentageTOTALPlugin(PluginTester, unittest.TestCase):
activate = "--with-coverage"
args = ['-v', '--cover-package=blah', '--cover-package=moo',
@@ -94,5 +147,31 @@ class TestCoverageMinPercentageTOTALPlugin(PluginTester, unittest.TestCase):
def runTest(self):
pass
+
+class TestCoverageMinPercentageWithBranchesTOTALPlugin(
+ PluginTester, unittest.TestCase):
+ activate = "--with-coverage"
+ args = ['-v', '--cover-package=blah', '--cover-package=moo',
+ '--cover-branches', '--cover-min-percentage', '100']
+ plugins = [Coverage()]
+ suitepath = os.path.join(support, 'coverage2')
+
+ def setUp(self):
+ if not hasCoverage:
+ raise unittest.SkipTest('coverage not available; skipping')
+
+ self.cover_file = os.path.join(os.getcwd(), '.coverage')
+ self.cover_html_dir = os.path.join(os.getcwd(), 'cover')
+ if os.path.exists(self.cover_file):
+ os.unlink(self.cover_file)
+ if os.path.exists(self.cover_html_dir):
+ shutil.rmtree(self.cover_html_dir)
+ self.assertRaises(
+ SystemExit,
+ super(TestCoverageMinPercentageWithBranchesTOTALPlugin, self).setUp)
+
+ def runTest(self):
+ pass
+
if __name__ == '__main__':
unittest.main()
diff --git a/nose/plugins/cover.py b/nose/plugins/cover.py
index d041251..5ff6dce 100644
--- a/nose/plugins/cover.py
+++ b/nose/plugins/cover.py
@@ -117,10 +117,10 @@ class Coverage(Plugin):
self.coverPackages = []
if options.cover_packages:
if isinstance(options.cover_packages, (list, tuple)):
- cover_packages = options.cover_packages
+ cover_packages = options.cover_packages
else:
cover_packages = [options.cover_packages]
- for pkgs in [tolist(x) for x in cover_packages]:
+ for pkgs in [tolist(x) for x in cover_packages]:
self.coverPackages.extend(pkgs)
self.coverInclusive = options.cover_inclusive
if self.coverPackages:
@@ -180,7 +180,16 @@ class Coverage(Plugin):
if self.coverMinPercentage:
f = StringIO.StringIO()
self.coverInstance.report(modules, file=f)
- m = re.search(r'-------\s\w+\s+\d+\s+\d+\s+(\d+)%\s+\d*\s{0,1}$', f.getvalue())
+
+ multiPackageRe = (r'-------\s\w+\s+\d+\s+\d+(?:\s+\d+\s+\d+)?'
+ r'\s+(\d+)%\s+\d*\s{0,1}$')
+ singlePackageRe = (r'-------\s[\w./]+\s+\d+\s+\d+(?:\s+\d+\s+\d+)?'
+ r'\s+(\d+)%(?:\s+[-\d, ]+)\s{0,1}$')
+
+ m = re.search(multiPackageRe, f.getvalue())
+ if m is None:
+ m = re.search(singlePackageRe, f.getvalue())
+
if m:
percentage = int(m.groups()[0])
if percentage < self.coverMinPercentage: