summaryrefslogtreecommitdiff
path: root/test/test_results.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-11-02 11:31:08 -0500
committerNed Batchelder <ned@nedbatchelder.com>2009-11-02 11:31:08 -0500
commit27e7dda1e731e0c66c3dba498cc2b38992f238dd (patch)
tree4b87d47cc265f9e7a979b58480ade31c63b1b784 /test/test_results.py
parentf7e817bef94e2372008b82c9b4c9b75162c77c3e (diff)
downloadpython-coveragepy-27e7dda1e731e0c66c3dba498cc2b38992f238dd.tar.gz
Test and refactor Numbers.
Diffstat (limited to 'test/test_results.py')
-rw-r--r--test/test_results.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/test_results.py b/test/test_results.py
new file mode 100644
index 0000000..d70a3b8
--- /dev/null
+++ b/test/test_results.py
@@ -0,0 +1,35 @@
+"""Tests for Coverage.py's results analysis."""
+
+import os, sys
+
+from coverage.results import Numbers
+
+sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k
+from coveragetest import CoverageTest
+
+
+class NumbersTest(CoverageTest):
+ """Tests for Coverage.py's numeric measurement summaries."""
+ def test_basic(self):
+ n1 = Numbers(n_files=1, n_statements=200, n_missing=20)
+ self.assertEqual(n1.n_statements, 200)
+ self.assertEqual(n1.n_run, 180)
+ self.assertEqual(n1.percent_covered, 90)
+
+ def test_addition(self):
+ n1 = Numbers(n_files=1, n_statements=200, n_missing=20)
+ n2 = Numbers(n_files=1, n_statements=10, n_missing=8)
+ n3 = n1 + n2
+ self.assertEqual(n3.n_files, 2)
+ self.assertEqual(n3.n_statements, 210)
+ self.assertEqual(n3.n_run, 182)
+ self.assertAlmostEqual(n3.percent_covered, 86.666666666)
+
+ def test_sum(self):
+ n1 = Numbers(n_files=1, n_statements=200, n_missing=20)
+ n2 = Numbers(n_files=1, n_statements=10, n_missing=8)
+ n3 = sum([n1, n2])
+ self.assertEqual(n3.n_files, 2)
+ self.assertEqual(n3.n_statements, 210)
+ self.assertEqual(n3.n_run, 182)
+ self.assertAlmostEqual(n3.percent_covered, 86.666666666)