Skip to content
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

Add more tests for sliders with empty ranges #2216

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changes/2216.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add more tests for sliders with empty ranges
66 changes: 54 additions & 12 deletions core/tests/widgets/test_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,36 +229,44 @@ def test_range(slider, on_change, min, max, value):


@pytest.mark.parametrize(
"new_min, new_max",
"new_min, new_value, new_max",
[
[-5, 10], # less than old min
[5, 10], # more than old min, less than max
[15, 15], # more than max
[-5, 5, 10], # less than old min
[5, 5, 10], # more than old min
[6, 6, 10], # more than old min and value
[15, 15, 15], # more than old min, value and max
],
)
def test_min_clipping(slider, new_min, new_max):
def test_min_clipping(slider, new_min, new_value, new_max):
slider.tick_count = None
slider.min = 0
slider.value = 5
slider.max = 10

slider.min = new_min
assert slider.min == new_min
assert slider.value == new_value
assert slider.max == new_max


@pytest.mark.parametrize(
"new_max, new_min",
"new_min, new_value, new_max",
[
[15, 0], # less than old max
[5, 0], # less than old max, more than min
[-5, -5], # less than min
[0, 5, 15], # more than old max
[0, 5, 5], # less than old max
[0, 4, 4], # less than old max and value
[-5, -5, -5], # less than old max, value and min
],
)
def test_max_clipping(slider, new_max, new_min):
def test_max_clipping(slider, new_min, new_value, new_max):
slider.tick_count = None
slider.min = 0
slider.value = 5
slider.max = 10

slider.max = new_max
assert slider.min == new_min
assert slider.value == new_value
assert slider.max == new_max


Expand Down Expand Up @@ -429,14 +437,31 @@ def test_int_impl_continuous():
assert impl.int_value == int_value
assert impl.get_value() == value

# Check a range that doesn't start at zero.
# Range that doesn't start at zero
impl.set_min(-0.4)
assert impl.get_min() == pytest.approx(-0.4)
impl.set_max(0.6)
assert impl.get_max() == pytest.approx(0.6)
impl.set_value(0.5)
assert impl.get_value() == 0.5
assert impl.int_value == 9000
assert impl.int_max == 10000

# Empty range
impl.set_min(0)
impl.set_max(0)
impl.set_value(0)
assert impl.get_value() == 0
assert impl.int_value == 0
assert impl.int_max == 10000

# Empty range that doesn't start at zero
impl.set_min(1)
impl.set_max(1)
impl.set_value(1)
assert impl.get_value() == 1
assert impl.int_value == 0
assert impl.int_max == 10000


def test_int_impl_discrete():
Expand Down Expand Up @@ -467,14 +492,31 @@ def test_int_impl_discrete():
assert impl.get_value() == value
assert impl.int_value == int_value

# Check a range that doesn't start at zero.
# Range that doesn't start at zero
impl.set_min(-0.4)
assert impl.get_min() == pytest.approx(-0.4)
impl.set_max(0.6)
assert impl.get_max() == pytest.approx(0.6)
impl.set_value(0.5)
assert impl.get_value() == 0.5
assert impl.int_value == 7
assert impl.int_max == 8

# Empty range
impl.set_min(0)
impl.set_max(0)
impl.set_value(0)
assert impl.get_value() == 0
assert impl.int_value == 0
assert impl.int_max == 8

# Empty range that doesn't start at zero
impl.set_min(1)
impl.set_max(1)
impl.set_value(1)
assert impl.get_value() == 1
assert impl.int_value == 0
assert impl.int_max == 8


@pytest.mark.parametrize(
Expand Down