1 """Test the coverage plugin."""
6 from nose.plugins import PluginTester
7 from nose.plugins.cover import Coverage
9 support = os.path.join(os.path.dirname(__file__), 'support')
12 class TestCoveragePlugin(PluginTester, unittest.TestCase):
13 activate = "--with-coverage"
14 args = ['-v', '--cover-package=blah', '--cover-html', '--cover-min-percentage', '25']
15 plugins = [Coverage()]
16 suitepath = os.path.join(support, 'coverage')
19 self.cover_file = os.path.join(os.getcwd(), '.coverage')
20 self.cover_html_dir = os.path.join(os.getcwd(), 'cover')
21 if os.path.exists(self.cover_file):
22 os.unlink(self.cover_file)
23 if os.path.exists(self.cover_html_dir):
24 shutil.rmtree(self.cover_html_dir)
25 super(TestCoveragePlugin, self).setUp()
28 self.assertTrue("blah 4 3 25% 1" in self.output)
29 self.assertTrue("Ran 1 test in""" in self.output)
30 # Assert coverage html report exists
31 self.assertTrue(os.path.exists(os.path.join(self.cover_html_dir,
33 # Assert coverage data is saved
34 self.assertTrue(os.path.exists(self.cover_file))
37 class TestCoverageMinPercentagePlugin(PluginTester, unittest.TestCase):
38 activate = "--with-coverage"
39 args = ['-v', '--cover-package=blah', '--cover-min-percentage', '100']
40 plugins = [Coverage()]
41 suitepath = os.path.join(support, 'coverage')
44 self.cover_file = os.path.join(os.getcwd(), '.coverage')
45 self.cover_html_dir = os.path.join(os.getcwd(), 'cover')
46 if os.path.exists(self.cover_file):
47 os.unlink(self.cover_file)
48 if os.path.exists(self.cover_html_dir):
49 shutil.rmtree(self.cover_html_dir)
50 self.assertRaises(SystemExit,
51 super(TestCoverageMinPercentagePlugin, self).setUp)
57 class TestCoverageMinPercentageTOTALPlugin(PluginTester, unittest.TestCase):
58 activate = "--with-coverage"
59 args = ['-v', '--cover-package=blah', '--cover-package=moo',
60 '--cover-min-percentage', '100']
61 plugins = [Coverage()]
62 suitepath = os.path.join(support, 'coverage2')
65 self.cover_file = os.path.join(os.getcwd(), '.coverage')
66 self.cover_html_dir = os.path.join(os.getcwd(), 'cover')
67 if os.path.exists(self.cover_file):
68 os.unlink(self.cover_file)
69 if os.path.exists(self.cover_html_dir):
70 shutil.rmtree(self.cover_html_dir)
71 self.assertRaises(SystemExit,
72 super(TestCoverageMinPercentageTOTALPlugin, self).setUp)
77 if __name__ == '__main__':