Skip to content

Use the lineno attribute of TextNode.token if TextNode.position is unavailable #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion django_coverage_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]

Expand Down Expand Up @@ -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))
Expand Down