diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-10-20 11:59:35 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-10-20 11:59:35 -0400 |
commit | 7f53916e61839c18b3e06f56e898f1df55afed1d (patch) | |
tree | f39577426803b0cd4661fe732c3d02fb9cce14f3 /coverage | |
parent | 832ee468e711e6d33fb49fb718e60a85c970a8ef (diff) | |
download | python-coveragepy-git-7f53916e61839c18b3e06f56e898f1df55afed1d.tar.gz |
More exception flow testing. This stuff is kind of involved...
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/collector.py | 2 | ||||
-rw-r--r-- | coverage/control.py | 5 | ||||
-rw-r--r-- | coverage/parser.py | 21 |
3 files changed, 21 insertions, 7 deletions
diff --git a/coverage/collector.py b/coverage/collector.py index bc700279..36788438 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -70,6 +70,7 @@ class PyTracer: # Record an executed line. if self.cur_file_data is not None: if self.arcs: + #print "lin", self.last_line, frame.f_lineno self.cur_file_data[(self.last_line, frame.f_lineno)] = None else: self.cur_file_data[frame.f_lineno] = None @@ -80,6 +81,7 @@ class PyTracer: # Leaving this function, pop the filename stack. self.cur_file_data, self.last_line = self.data_stack.pop() elif event == 'exception': + #print "exc", self.last_line, frame.f_lineno self.last_exc_back = frame.f_back return self._trace diff --git a/coverage/control.py b/coverage/control.py index 5e857aa6..da773d3e 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -384,5 +384,8 @@ class Analysis: def arcs_unpredicted(self): possible = self.arc_possibilities() executed = self.arcs_executed() - unpredicted = [e for e in executed if e not in possible] + # Exclude arcs here which connect a line to itself. They can occur + # in executed data in some cases. This is where they can cause trouble, + # and here is where it's the least burden to remove them. + unpredicted = [e for e in executed if e not in possible and e[0] != e[1]] return sorted(unpredicted) diff --git a/coverage/parser.py b/coverage/parser.py index 74490189..7b899d12 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -173,8 +173,13 @@ class CodeParser: ## Opcodes that guide the ByteParser. +def _opcode(name): + """Return the opcode by name from the opcode module.""" + return opcode.opmap[name] + def _opcode_set(*names): - return set([opcode.opmap[name] for name in names]) + """Return a set of opcodes by the names in `names`.""" + return set([_opcode(name) for name in names]) # Opcodes that leave the code object. OPS_CODE_END = _opcode_set('RETURN_VALUE') @@ -191,12 +196,13 @@ OPS_PUSH_BLOCK = _opcode_set('SETUP_LOOP', 'SETUP_EXCEPT', 'SETUP_FINALLY') # Opcodes that pop a block from the block stack. OPS_POP_BLOCK = _opcode_set('POP_BLOCK') -# Opcodes that break a loop. -OPS_BREAK = _opcode_set('BREAK_LOOP') - # Opcodes that have a jump destination, but aren't really a jump. OPS_NO_JUMP = _opcode_set('SETUP_EXCEPT', 'SETUP_FINALLY') +# Individual opcodes we need below. +OP_BREAK_LOOP = _opcode('BREAK_LOOP') +OP_END_FINALLY = _opcode('END_FINALLY') + class ByteParser: """Parse byte codes to understand the structure of code.""" @@ -352,12 +358,15 @@ class ByteParser: block_stack.pop() elif bc.op in OPS_CHUNK_END: # This opcode forces the end of the chunk. - if bc.op in OPS_BREAK: + if bc.op == OP_BREAK_LOOP: # A break is implicit: jump where the top of the # block_stack points. chunk.exits.add(block_stack[-1]) chunk = None - + elif bc.op == OP_END_FINALLY: + if block_stack: + chunk.exits.add(block_stack[-1]) + if chunks: chunks[-1].length = bc.next_offset - chunks[-1].byte for i in range(len(chunks)-1): |