diff options
author | Mickie Betz <mbetz08@cmc.edu> | 2015-04-14 16:53:30 -0400 |
---|---|---|
committer | Mickie Betz <mbetz08@cmc.edu> | 2015-04-14 16:53:30 -0400 |
commit | 90189c05e6e8716b6cc6f78cf3e1e98f9fa045c1 (patch) | |
tree | 6374ec819976f1bd6bee55c223e301022ceee9ab | |
parent | e0ad5837194a4a8cd1a2ddf392c5b0db6a80e705 (diff) | |
download | python-coveragepy-git-90189c05e6e8716b6cc6f78cf3e1e98f9fa045c1.tar.gz |
Including generator yield statements when doing end of code calculations issue 324
-rw-r--r-- | coverage/parser.py | 2 | ||||
-rw-r--r-- | tests/test_parser.py | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/coverage/parser.py b/coverage/parser.py index f488367d..91b685ce 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -308,7 +308,7 @@ OPS_CODE_END = _opcode_set('RETURN_VALUE') # Opcodes that unconditionally end the code chunk. OPS_CHUNK_END = _opcode_set( 'JUMP_ABSOLUTE', 'JUMP_FORWARD', 'RETURN_VALUE', 'RAISE_VARARGS', - 'BREAK_LOOP', 'CONTINUE_LOOP', + 'BREAK_LOOP', 'CONTINUE_LOOP', 'YIELD_VALUE', ) # Opcodes that unconditionally begin a new code chunk. By starting new chunks diff --git a/tests/test_parser.py b/tests/test_parser.py index 244d4c70..a39820e6 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -34,6 +34,19 @@ class PythonParserTest(CoverageTest): 2:1, 3:1, 4:2, 5:1, 7:1, 9:1, 10:1 }) + def test_generator_exit_counts(self): + parser = self.parse_source("""\ + # generators yield lines should only have one exit count + def gen(input): + for n in inp: + yield (i * 2 for i in range(n)) + + list(gen([1,2,3])) + """) + self.assertEqual(parser.exit_counts(), { + 2:1, 3:2, 4:1, 6:1 + }) + def test_try_except(self): parser = self.parse_source("""\ try: |