summaryrefslogtreecommitdiff
path: root/tests/test_summary_class.py
diff options
context:
space:
mode:
authorDan Wandschneider <daniel.wandschneider@schrodinger.com>2016-06-08 19:51:54 -0400
committerDan Wandschneider <daniel.wandschneider@schrodinger.com>2016-06-08 19:51:54 -0400
commit0c39e2f5774b78ca5025e8ffe0fbde4ab2e86abf (patch)
tree896561bd5b768fa8ec02d2f115774241c0c3f3c5 /tests/test_summary_class.py
parentbdec9312cb755ec28bf20713823628c353cdfcd9 (diff)
downloadpython-coveragepy-git-0c39e2f5774b78ca5025e8ffe0fbde4ab2e86abf.tar.gz
Add unit-level test for the SummaryReporter
Tests configuration of the report method of SummaryReader
Diffstat (limited to 'tests/test_summary_class.py')
-rw-r--r--tests/test_summary_class.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/test_summary_class.py b/tests/test_summary_class.py
new file mode 100644
index 00000000..93e025c4
--- /dev/null
+++ b/tests/test_summary_class.py
@@ -0,0 +1,53 @@
+# coding: utf8
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+
+"""Test text-based summary reporter for coverage.py"""
+
+import collections
+import unittest
+import os.path
+try:
+ from cStringIO import StringIO
+except ImportError:
+ from StringIO import StringIO
+from coverage import summary, data, control, config
+
+LINES_1 = {
+ __file__: {-1: 1, 7: 1},
+ os.path.join(os.path.dirname(__file__), 'helpers.py'): {-1: 1, 7: 1},
+}
+
+
+class TestSummaryReporterConfiguration(unittest.TestCase):
+ def get_coverage_data(self, lines=LINES_1):
+ """Get a CoverageData object that includes the requested lines."""
+ data1 = data.CoverageData()
+ data1.add_lines(lines)
+ return data1
+
+ def get_summary_text(self, coverage_data, options):
+ """Get text output from the SummaryReporter."""
+ cov = control.Coverage()
+ cov.data = coverage_data
+ printer = summary.SummaryReporter(cov, options)
+ destination = StringIO()
+ printer.report([], destination)
+ return destination.getvalue()
+
+ def test_defaults(self):
+ """Run the report with no configuration options."""
+ data = self.get_coverage_data()
+ opts = config.CoverageConfig()
+ report = self.get_summary_text(data, opts)
+ self.assertNotIn('Missing', report)
+ self.assertNotIn('Branch', report)
+
+ def test_print_missing(self):
+ """Run the report printing the missing lines."""
+ data = self.get_coverage_data()
+ opts = config.CoverageConfig()
+ opts.from_args(show_missing=True)
+ report = self.get_summary_text(data, opts)
+ self.assertIn('Missing', report)
+ self.assertNotIn('Branch', report)