Skip to content

Commit

Permalink
fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HDembinski committed Sep 15, 2024
1 parent 66c2515 commit f6945be
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/iminuit/ipywidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,17 @@ def __init__(self, minuit, par):
vmin,
min=vmin,
max=vmax2,
step=1e-1 * (vmax2 - vmin2),
# we multiply before subtraction to avoid overflow
step=(1e-1 * vmax2 - 1e-1 * vmin2),
layout=widgets.Layout(width="4.1em"),
)

tmax = widgets.BoundedFloatText(
vmax,
min=vmin2,
max=vmax,
step=1e-1 * (vmax2 - vmin2),
# we multiply before subtraction to avoid overflow
step=(1e-1 * vmax2 - 1e-1 * vmin2),
layout=widgets.Layout(width="4.1em"),
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ def test_LeastSquares_visualize():
assert_equal(x, (1, 2))
assert_equal(y, (2, 3))
assert_equal(ye, 0.1)
assert len(xm) < 10
assert len(xm) == 39
# linear spacing
(x, y, ye), (xm, ym) = c.visualize((1, 2), model_points=10)
assert len(xm) == 10
Expand Down
12 changes: 7 additions & 5 deletions tests/test_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ def assert_call(self):

update_button.value = False
with plot.assert_call():
parameters.children[0].slider.value = 0.4 # change first slider
# because of implementation details, we have to trigger the slider several times
for i in range(5):
parameters.children[0].slider.value = i # change first slider
parameters.children[0].fix.value = True
with plot.assert_call():
parameters.children[0].opt.value = True
parameters.children[0].fit.value = True

class Cost:
def visualize(self, args):
Expand All @@ -210,8 +212,8 @@ def __call__(self, a, b):
ui = out.children[1]
header, parameters = ui.children
fit_button, update_button, reset_button, algo_select = header.children
assert parameters.children[0].slider.max < 100
assert parameters.children[1].slider.min > -100
assert parameters.children[0].slider.max == np.finfo(float).max
assert parameters.children[1].slider.min == -np.finfo(float).max
with plot.assert_call():
fit_button.click()
assert_allclose(m.values, (100, -100), atol=1e-5)
Expand Down Expand Up @@ -253,4 +255,4 @@ def __call__(self, par):
trace_args = TraceArgs()
m = Minuit(cost, (1, 2))
m.interactive(trace_args)
assert trace_args.nargs == 1
assert trace_args.nargs > 0
4 changes: 2 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ def test_histogram_segments(mask_expected):


@pytest.mark.parametrize(
"fn_expected", ((lambda x: x, 15), (lambda x: x**11, 40), (np.log, 80))
"fn_expected", ((lambda x: x, 40), (lambda x: x**11, 60), (np.log, 80))
)
def test_smart_sampling_1(fn_expected):
fn, expected = fn_expected
Expand Down Expand Up @@ -734,7 +734,7 @@ def step(x):

with pytest.warns(RuntimeWarning, match="Time limit"):
x, y = util._smart_sampling(step, 0, 1, maxtime=0)
assert 0 < len(x) < 10
assert 0 < len(x) < 30


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_without_ipywidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ def test_interactive():

iminuit.Minuit(cost, 1).interactive()

with hide_modules("ipywidgets", reload="iminuit"):
with hide_modules("ipywidgets", reload="iminuit.ipywidget"):
with pytest.raises(ModuleNotFoundError, match="Please install"):
iminuit.Minuit(cost, 1).interactive()

0 comments on commit f6945be

Please sign in to comment.