summaryrefslogtreecommitdiff
path: root/test/test_parser.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-11-16 22:16:09 -0500
committerNed Batchelder <ned@nedbatchelder.com>2009-11-16 22:16:09 -0500
commit120fcf1560e9b735dbf72ed173c717eef1fff514 (patch)
tree87fd8b195c8216da26d3ab934c29de7f0b651921 /test/test_parser.py
parent7bdce80a45920e3888ac0366fdbfb54c6604eba6 (diff)
downloadpython-coveragepy-git-120fcf1560e9b735dbf72ed173c717eef1fff514.tar.gz
Classes shouldn't be marked as branches. Fixes #32.
Diffstat (limited to 'test/test_parser.py')
-rw-r--r--test/test_parser.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/test_parser.py b/test/test_parser.py
new file mode 100644
index 00000000..5a66f873
--- /dev/null
+++ b/test/test_parser.py
@@ -0,0 +1,36 @@
+"""Tests for Coverage.py's code parsing."""
+
+import os, sys, textwrap
+
+sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k
+from coveragetest import CoverageTest
+
+from coverage.parser import CodeParser
+
+
+class ParserTest(CoverageTest):
+ """Tests for Coverage.py's code parsing."""
+
+ def parse_source(self, text):
+ """Parse `text` as source, and return the `CodeParser` used."""
+ text = textwrap.dedent(text)
+ cp = CodeParser(text)
+ cp.parse_source()
+ return cp
+
+ def test_exit_counts(self):
+ cp = self.parse_source("""\
+ # check some basic branch counting
+ class Foo:
+ def foo(self, a):
+ if a:
+ return 5
+ else:
+ return 7
+
+ class Bar:
+ pass
+ """)
+ self.assertEqual(cp.exit_counts(), {
+ 2:1, 3:1, 4:2, 5:1, 7:1, 9:1, 10:1
+ })