diff --git a/lumicks/pylake/tests/test_scalebar.py b/lumicks/pylake/tests/test_scalebar.py index 650f1e157..3b356a352 100644 --- a/lumicks/pylake/tests/test_scalebar.py +++ b/lumicks/pylake/tests/test_scalebar.py @@ -1,5 +1,3 @@ -import json - import numpy as np import pytest import matplotlib.pyplot as plt @@ -25,7 +23,7 @@ def _validate_elements(ref_elements, item): else: ref_elements.pop(idx) else: - raise AssertionError("Missing element") + raise AssertionError(f"Missing element {item}") @pytest.mark.parametrize( @@ -35,32 +33,32 @@ def _validate_elements(ref_elements, item): # All entries ( 1, 2, "x", "y", "upper right", "white", 2, 2, 16, - ["Text(0, 0, 'y')", "Text(0, 0, 'x')", "Rectangle(xy=(0, 2), width=1, height=0, angle=0)", "Rectangle(xy=(0, 0), width=0, height=2, angle=0)", "Text(0, 0, 'x')"] + ("Text(0, 0, 'y')", "Text(0, 0, 'x')", "Rectangle(xy=(0, 2), width=1, height=0, angle=0)", "Rectangle(xy=(0, 0), width=0, height=2, angle=0)", "Text(0, 0, 'x')"), ), # No label for x ( 1, 2, None, "y", "upper right", "white", 2, 2, 16, - ["Text(0, 0, 'y')", "Rectangle(xy=(0, 2), width=1, height=0, angle=0)", "Rectangle(xy=(0, 0), width=0, height=2, angle=0)"] + ("Text(0, 0, 'y')", "Rectangle(xy=(0, 2), width=1, height=0, angle=0)", "Rectangle(xy=(0, 0), width=0, height=2, angle=0)"), ), # No label for y ( 1, 2, "x", None, "upper right", "white", 2, 2, 16, - ["Rectangle(xy=(0, 2), width=1, height=0, angle=0)", "Rectangle(xy=(0, 0), width=0, height=2, angle=0)", "Text(0, 0, 'x')"] + ("Rectangle(xy=(0, 2), width=1, height=0, angle=0)", "Rectangle(xy=(0, 0), width=0, height=2, angle=0)", "Text(0, 0, 'x')"), ), # No labels ( 1, 2, None, None, "upper right", "white", 2, 2, 16, - ["Rectangle(xy=(0, 2), width=1, height=0, angle=0)", "Rectangle(xy=(0, 0), width=0, height=2, angle=0)"] + ("Rectangle(xy=(0, 2), width=1, height=0, angle=0)", "Rectangle(xy=(0, 0), width=0, height=2, angle=0)"), ), # Only one axis ( 1, 0, "x", "y", "upper right", "white", 2, 2, 16, - ["Rectangle(xy=(0, 0), width=1, height=0, angle=0)", "Text(0, 0, 'x')"], + ("Rectangle(xy=(0, 0), width=1, height=0, angle=0)", "Text(0, 0, 'x')"), ), # Only one axis ( 0, 2, "x", "y", "upper right", "white", 2, 2, 16, - ["Text(0, 0, 'y')", "Rectangle(xy=(0, 0), width=0, height=2, angle=0)"], + ("Text(0, 0, 'y')", "Rectangle(xy=(0, 0), width=0, height=2, angle=0)"), ), # fmt:on ], @@ -75,9 +73,12 @@ def test_scalebar( axes.transData, size_x, size_y, label_x, label_y, loc, color, separation, barwidth, fontsize ) - _validate_elements(reference, box) - if reference: - raise AssertionError(f"Not all elements were accounted for: {reference}") + # Note that _validate_elements pops items from this list (hence we copy to prevent mutating the + # input parametrization) + reference_list = list(reference) + _validate_elements(reference_list, box) + if reference_list: + raise AssertionError(f"Not all elements were accounted for: {reference_list}") def validate_args(refs):