diff --git a/django_coverage_plugin/plugin.py b/django_coverage_plugin/plugin.py index 41a091c..54e35af 100644 --- a/django_coverage_plugin/plugin.py +++ b/django_coverage_plugin/plugin.py @@ -112,6 +112,14 @@ def filename_for_frame(frame): except (KeyError, AttributeError): return None + def lines_for_node(n): + try: + startLine = n.token.lineno + count = len(n.s.splitlines(True)) if isinstance(n, TextNode) else 0 + return startLine, startLine + count + except AttributeError: + return None + def position_for_node(node): try: return node.token.position @@ -127,6 +135,9 @@ def filename_for_frame(frame): except (KeyError, AttributeError, IndexError): return None + def lines_for_node(node): + return None + def position_for_node(node): return node.source[1] @@ -249,7 +260,8 @@ def line_number_range(self, frame): position = position_for_node(render_self) if position is None: - return -1, -1 + lines = lines_for_node(render_self) + return lines if lines else (-1, -1) if SHOW_TRACING: print("{!r}: {}".format(render_self, position))