Skip to content

Tests fail without ipywidgets #912

@stephanlachnit

Description

@stephanlachnit

test_interactive is not skipped if ipywidgets is not available. Was no problem in version 2.21.3. Related PR: #873

Log:

I: pybuild base:240: cd /<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_iminuit/build; python3.11 -m pytest tests
........................................................................ [ 11%]
........................................................................ [ 23%]
...........................................FFF.......................... [ 35%]
........................................................................ [ 47%]
........................................................................ [ 59%]
............................................................s........... [ 71%]
........................................................................ [ 83%]
...........................................X............................ [ 95%]
............................                                             [100%]
=================================== FAILURES ===================================
_______________________________ test_interactive _______________________________

    @pytest.mark.filterwarnings("ignore::DeprecationWarning")
    def test_interactive():
>       import ipywidgets
E       ModuleNotFoundError: No module named 'ipywidgets'

tests/test_draw.py:140: ModuleNotFoundError
___________________________ test_interactive_raises ____________________________

    @pytest.mark.filterwarnings("ignore::DeprecationWarning")
    def test_interactive_raises():
        def raiser(args):
            raise ValueError
    
        m = Minuit(lambda x, y: 0, 0, 1)
    
        # by default do not raise
>       m.interactive(raiser)

tests/test_draw.py:232: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = (Param(number=0, name='x', value=0.0, error=0.1, merror=None, is_const=False, is_fixed=False, lower_limit=None, upper_...r=1, name='y', value=1.0, error=0.01, merror=None, is_const=False, is_fixed=False, lower_limit=None, upper_limit=None))
plot = <function test_interactive_raises.<locals>.raiser at 0x7f9e52ec25c0>
raise_on_exception = False, kwargs = {}

    def interactive(
        self,
        plot: Callable = None,
        raise_on_exception=False,
        **kwargs,
    ):
        """
        Return fitting widget (requires ipywidgets, IPython, matplotlib).
    
        A fitting widget is returned which can be displayed and manipulated in a
        Jupyter notebook to find good starting parameters and to debug the fit.
    
        Parameters
        ----------
        plot : Callable, optional
            To visualize the fit, interactive tries to access the visualize method on
            the cost function, which accepts the current model parameters as an
            array-like and potentially further keyword arguments, and draws a
            visualization into the current matplotlib axes. If the cost function does
            not provide a visualize method or if you want to override it, pass the
            function here.
        raise_on_exception : bool, optional
            The default is to catch exceptions in the plot function and convert them
            into a plotted message. In unit tests, raise_on_exception should be set to
            True to allow detecting errors.
        **kwargs :
            Any other keyword arguments are forwarded to the plot function.
    
        Examples
        --------
        .. plot:: plots/interactive.py
            :include-source:
        """
        with warnings.catch_warnings():
            # ipywidgets produces deprecation warnings through use of internal APIs :(
            warnings.simplefilter("ignore")
            try:
>               from ipywidgets import (
                    HBox,
                    VBox,
                    Output,
                    FloatSlider,
                    Button,
                    ToggleButton,
                    Layout,
                    Dropdown,
                )
E               ModuleNotFoundError: No module named 'ipywidgets'
E               
E               Please install ipywidgets, IPython, and matplotlib to enable interactive

iminuit/minuit.py:2236: ModuleNotFoundError
_______________________ test_interactive_with_array_func _______________________

    @pytest.mark.filterwarnings("ignore::DeprecationWarning")
    def test_interactive_with_array_func():
        def cost(par):
            return par[0] ** 2 + (par[1] / 2) ** 2
    
        class TraceArgs:
            nargs = 0
    
            def __call__(self, par):
                self.nargs = len(par)
    
        trace_args = TraceArgs()
        m = Minuit(cost, (1, 2))
>       m.interactive(trace_args)

tests/test_draw.py:251: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = (Param(number=0, name='x0', value=1.0, error=0.01, merror=None, is_const=False, is_fixed=False, lower_limit=None, uppe...=1, name='x1', value=2.0, error=0.02, merror=None, is_const=False, is_fixed=False, lower_limit=None, upper_limit=None))
plot = <test_draw.test_interactive_with_array_func.<locals>.TraceArgs object at 0x7f9e53d51690>
raise_on_exception = False, kwargs = {}

    def interactive(
        self,
        plot: Callable = None,
        raise_on_exception=False,
        **kwargs,
    ):
        """
        Return fitting widget (requires ipywidgets, IPython, matplotlib).
    
        A fitting widget is returned which can be displayed and manipulated in a
        Jupyter notebook to find good starting parameters and to debug the fit.
    
        Parameters
        ----------
        plot : Callable, optional
            To visualize the fit, interactive tries to access the visualize method on
            the cost function, which accepts the current model parameters as an
            array-like and potentially further keyword arguments, and draws a
            visualization into the current matplotlib axes. If the cost function does
            not provide a visualize method or if you want to override it, pass the
            function here.
        raise_on_exception : bool, optional
            The default is to catch exceptions in the plot function and convert them
            into a plotted message. In unit tests, raise_on_exception should be set to
            True to allow detecting errors.
        **kwargs :
            Any other keyword arguments are forwarded to the plot function.
    
        Examples
        --------
        .. plot:: plots/interactive.py
            :include-source:
        """
        with warnings.catch_warnings():
            # ipywidgets produces deprecation warnings through use of internal APIs :(
            warnings.simplefilter("ignore")
            try:
>               from ipywidgets import (
                    HBox,
                    VBox,
                    Output,
                    FloatSlider,
                    Button,
                    ToggleButton,
                    Layout,
                    Dropdown,
                )
E               ModuleNotFoundError: No module named 'ipywidgets'
E               
E               Please install ipywidgets, IPython, and matplotlib to enable interactive

iminuit/minuit.py:2236: ModuleNotFoundError
=========================== short test summary info ============================
SKIPPED [1] tests/test_without_ipywidgets.py:5: could not import 'ipywidgets': No module named 'ipywidgets'
SKIPPED [1] tests/test_repr.py:347: could not import 'unicodeitplus': No module named 'unicodeitplus'
XPASS tests/test_tabulate.py::test_matrix https://github.com/scikit-hep/iminuit/issues/840
FAILED tests/test_draw.py::test_interactive - ModuleNotFoundError: No module ...
FAILED tests/test_draw.py::test_interactive_raises - ModuleNotFoundError: No ...
FAILED tests/test_draw.py::test_interactive_with_array_func - ModuleNotFoundE...
3 failed, 599 passed, 2 skipped, 1 xpassed in 11.83s
E: pybuild pybuild:388: test: plugin pyproject failed with: exit code=1: cd /<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_iminuit/build; python3.11 -m pytest tests

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions