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

Test failure in ipywidgets 8 #244

Open
jasongrout opened this issue Aug 10, 2022 · 2 comments
Open

Test failure in ipywidgets 8 #244

jasongrout opened this issue Aug 10, 2022 · 2 comments

Comments

@jasongrout
Copy link
Member

@frenzymadness reported that nbclient tests fail when using the upcoming ipywidgets 8. The test notebook should be updated to reflect the change, as it is an expected change in ipywidgets behavior in ipywidgets 8.

See jupyter-widgets/ipywidgets#2750 (comment) and jupyter-widgets/ipywidgets#2750 (comment) for a short discussion of the issue.

@jasongrout
Copy link
Member Author

For convenience, here is the failure:

=================================== FAILURES ===================================
______________ test_run_all_notebooks[JupyterWidgets.ipynb-opts7] ______________

input_name = 'JupyterWidgets.ipynb', opts = {'kernel_name': 'python'}

    @pytest.mark.parametrize(
        ["input_name", "opts"],
        [
            ("Other Comms.ipynb", dict(kernel_name="python")),
            ("Clear Output.ipynb", dict(kernel_name="python")),
            ("Empty Cell.ipynb", dict(kernel_name="python")),
            ("Factorials.ipynb", dict(kernel_name="python")),
            ("HelloWorld.ipynb", dict(kernel_name="python")),
            ("Inline Image.ipynb", dict(kernel_name="python")),
            (
                "Interrupt.ipynb",
                dict(kernel_name="python", timeout=1, interrupt_on_timeout=True, allow_errors=True),
            ),
            ("JupyterWidgets.ipynb", dict(kernel_name="python")),
            ("Skip Exceptions with Cell Tags.ipynb", dict(kernel_name="python")),
            ("Skip Exceptions.ipynb", dict(kernel_name="python", allow_errors=True)),
            ("Skip Execution with Cell Tag.ipynb", dict(kernel_name="python")),
            ("SVG.ipynb", dict(kernel_name="python")),
            ("Unicode.ipynb", dict(kernel_name="python")),
            ("UnicodePy3.ipynb", dict(kernel_name="python")),
            ("update-display-id.ipynb", dict(kernel_name="python")),
            ("Check History in Memory.ipynb", dict(kernel_name="python")),
        ],
    )
    def test_run_all_notebooks(input_name, opts):
        """Runs a series of test notebooks and compares them to their actual output"""
        input_file = os.path.join(current_dir, 'files', input_name)
        input_nb, output_nb = run_notebook(input_file, opts, notebook_resources())
>       assert_notebooks_equal(input_nb, output_nb)

nbclient/tests/test_client.py:333: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

expected = {'cells': [{'cell_type': 'code', 'execution_count': 1, 'metadata': {}, 'outputs': [{'data': {'application/vnd.jupyter....del_name': 'LayoutModel', 'state': {}}}, 'version_major': 2, 'version_minor': 0}}}, 'nbformat': 4, 'nbformat_minor': 2}
actual = {'cells': [{'cell_type': 'code', 'metadata': {'execution': {'iopub.status.busy': '2022-08-09T19:28:42.615167Z', 'iopub...oltip': None, 'value': 'Hello World'}}}, 'version_major': 2, 'version_minor': 0}}}, 'nbformat': 4, 'nbformat_minor': 2}

    def assert_notebooks_equal(expected, actual):
        expected_cells = expected['cells']
        actual_cells = actual['cells']
        assert len(expected_cells) == len(actual_cells)
    
        for expected_cell, actual_cell in zip(expected_cells, actual_cells):
            # Uncomment these to help debug test failures better
            # from pprint import pprint
            # pprint(expected_cell)
            # pprint(actual_cell)
            expected_outputs = expected_cell.get('outputs', [])
            actual_outputs = actual_cell.get('outputs', [])
            normalized_expected_outputs = list(map(normalize_output, expected_outputs))
            normalized_actual_outputs = list(map(normalize_output, actual_outputs))
>           assert normalized_expected_outputs == normalized_actual_outputs
E           AssertionError: assert [{'data': {'application/vnd.jupyter.widget-view+json': {'model_id': '<MODEL_ID>',\n                                                        'version_major': 2,\n                                                        'version_minor': 0},\n           'text/plain': 'LabelvalueHelloWorld'},\n  'output_type': 'display_data'}] == [{'data': {'application/vnd.jupyter.widget-view+json': {'model_id': '<MODEL_ID>',\n                                                        'version_major': 2,\n                                                        'version_minor': 0},\n           'text/plain': 'LabelvalueHelloWorld'},\n  'execution_count': 1,\n  'output_type': 'execute_result'}]
E             At index 0 diff: {'data': {'application/vnd.jupyter.widget-view+json': {'model_id': '<MODEL_ID>', 'version_major': 2, 'version_minor': 0}, 'text/plain': 'LabelvalueHelloWorld'}, 'output_type': 'display_data'} != {'output_type': 'execute_result', 'data': {'text/plain': 'LabelvalueHelloWorld', 'application/vnd.jupyter.widget-view+json': {'version_major': 2, 'version_minor': 0, 'model_id': '<MODEL_ID>'}}, 'execution_count': 1}
E             Full diff:
E               [
E                {'data': {'application/vnd.jupyter.widget-view+json': {'model_id': '<MODEL_ID>',
E                                                                       'version_major': 2,
E                                                                       'version_minor': 0},
E                          'text/plain': 'LabelvalueHelloWorld'},
E             +   'output_type': 'display_data'},
E             -   'execution_count': 1,
E             -   'output_type': 'execute_result'},
E               ]

nbclient/tests/test_client.py:280: AssertionError

@jasongrout
Copy link
Member Author

Alternatively, I think you can change the code of that cell to display(widget) instead of relying on the automatic display of the widget, which I think should give the same output for ipywidgets 7 or ipywidgets 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant