From 120fcf1560e9b735dbf72ed173c717eef1fff514 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 16 Nov 2009 22:16:09 -0500 Subject: Classes shouldn't be marked as branches. Fixes #32. --- test/test_parser.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/test_parser.py (limited to 'test/test_parser.py') 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 + }) -- cgit v1.2.1