Skip to content

Commit cf3a7a6

Browse files
committed
Attempt at reporting failure position
1 parent f900e8f commit cf3a7a6

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

mathics/builtin/trace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def eval_set(self, value, evaluation):
591591
"""Set[$TrackLocations, value_]"""
592592
if value is SymbolTrue or value is SymbolFalse:
593593
evaluation.definitions.set_ownvalue("System`$TrackLocations", value)
594-
mathics.core.parser.parser.TRACK_LOCATIONS = value.to_python()
594+
mathics_scanner.location.TRACK_LOCATIONS = value.to_python()
595595
else:
596596
evaluation.message("$TrackLocations", "bool", value)
597597
return value

test/builtin/drawing/test_plot.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,20 +215,26 @@ def test_plot(str_expr, msgs, str_expected, fail_msg):
215215

216216
def check_structure(result, expected):
217217
"""Check that expected is a prefix of result at every node"""
218+
218219
# print_expr_tree(result)
219220
# print_expr_tree(expected)
220-
assert result.get_head() == expected.get_head(), "heads must match"
221+
222+
def msg(s):
223+
pos = getattr(getattr(expected, "location", None), "start_pos", None)
224+
return f"in str_expected at pos {pos or '?'}: {s}"
225+
226+
assert result.get_head() == expected.get_head(), msg("heads must match")
221227
assert hasattr(result, "elements") == hasattr(
222228
expected, "elements"
223-
), "either both or none must have elements"
229+
), msg("either both or none must have elements")
224230
if hasattr(expected, "elements"):
225231
for i, e in enumerate(expected.elements):
226232
assert (
227233
len(result.elements) > i
228-
), f"expected at least {i} elements, found only {len(result.elements)}"
234+
), msg("result has too few elements")
229235
check_structure(result.elements[i], e)
230236
else:
231-
assert str(result) == str(expected), f"leaves don't match"
237+
assert str(result) == str(expected), msg("leaves don't match")
232238

233239

234240
@pytest.mark.parametrize(
@@ -305,6 +311,11 @@ def check_structure(result, expected):
305311
],
306312
)
307313
def test_plot_structure(str_expr, str_expected):
314+
315+
# TODO: unfortunately this only adds location information to the top-level expression
316+
# so not very useful
317+
session.evaluate("Set[$TrackLocations, True]")
318+
308319
expr = session.parse(str_expr)
309320
result = expr.evaluate(session.evaluation)
310321
expected = session.parse(str_expected)

0 commit comments

Comments
 (0)