Skip to content

Commit

Permalink
black format
Browse files Browse the repository at this point in the history
  • Loading branch information
ericleonardis committed Dec 21, 2024
1 parent a06c954 commit fb35ff2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion sleap/gui/widgets/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def _toVal(self, x: float, center=False) -> float:
@property
def _slider_width(self) -> float:
"""Returns visual width of slider."""
return self.box_rect.width()
return self.box_rect.width()

@property
def slider_visible_value_range(self) -> float:
Expand Down
22 changes: 14 additions & 8 deletions tests/gui/test_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,20 @@ def test_slider(qtbot, centered_pair_predictions):
slider.setEnabled(True)
assert slider.enabled()


@pytest.mark.parametrize(
"slider_width, x_value, min_value, max_value",
[
# Values within range
(1000, 500, 0, 1000), # Midpoint with no offset
(800, 400, 0, 800), # Exact midpoint within smaller range
(1000, 500, 0, 1000), # Midpoint with no offset
(800, 400, 0, 800), # Exact midpoint within smaller range
(1500, 750, 100, 1200), # Midpoint with offset range
(2000, 1000, 50, 1950), # Large width and offset range
# Values below range (no clamping expected)
(1000, -100, 0, 1000), # Below minimum
# Values above range (no clamping expected)
(1000, 1200, 0, 1000), # Above maximum
]
],
)
def test_toVal(qtbot, slider_width, x_value, min_value, max_value):
"""
Expand Down Expand Up @@ -84,6 +83,7 @@ def test_toVal(qtbot, slider_width, x_value, min_value, max_value):
# Assert that the raw transformation matches the expected value
assert slider._toVal(x_value) == expected_value


def test_slider_width_property(qtbot):
"""
Test the _slider_width property to ensure it accurately reflects
Expand All @@ -94,11 +94,17 @@ def test_slider_width_property(qtbot):
# Test various box_rect widths
for width in [800, 1000, 1200, 1500]:
slider.box_rect.setWidth(width) # Simulate setting the visual width
assert slider._slider_width == width, f"Expected _slider_width to be {width}, but got {slider._slider_width}"
assert (
slider._slider_width == width
), f"Expected _slider_width to be {width}, but got {slider._slider_width}"

# Test edge cases with very small and large widths
slider.box_rect.setWidth(0)
assert slider._slider_width == 0, "Expected _slider_width to be 0 when box_rect width is 0"
assert (
slider._slider_width == 0
), "Expected _slider_width to be 0 when box_rect width is 0"

slider.box_rect.setWidth(10000)
assert slider._slider_width == 10000, "Expected _slider_width to handle large values correctly"
assert (
slider._slider_width == 10000
), "Expected _slider_width to handle large values correctly"

0 comments on commit fb35ff2

Please sign in to comment.