Example #1
0
def test_open_with_dialog_choices_raises(make_napari_viewer):
    viewer = make_napari_viewer()

    get_settings().plugins.extension2reader = {}
    with pytest.raises(ValueError):
        open_with_dialog_choices(
            display_name='Fake Plugin',
            persist=True,
            extension='.fake',
            readers={'fake-plugin': 'Fake Plugin'},
            paths=['my-file.fake'],
            stack=False,
            qt_viewer=viewer.window._qt_viewer,
        )
    # settings weren't saved because reading failed
    assert not get_settings().plugins.extension2reader
Example #2
0
def test_open_with_dialog_choices_persist(builtins, make_napari_viewer,
                                          tmp_path):
    pth = tmp_path / 'my-file.npy'
    np.save(pth, np.random.random((10, 10)))

    viewer = make_napari_viewer()
    open_with_dialog_choices(
        display_name=builtins.display_name,
        persist=True,
        extension='.npy',
        readers={builtins.name: builtins.display_name},
        paths=[str(pth)],
        stack=False,
        qt_viewer=viewer.window._qt_viewer,
    )
    assert len(viewer.layers) == 1
    # make sure extension was saved with *
    assert get_settings().plugins.extension2reader['*.npy'] == builtins.name
Example #3
0
def test_open_with_dialog_choices_persist(make_napari_viewer, tmp_path):
    pth = tmp_path / 'my-file.npy'
    np.save(pth, np.random.random((10, 10)))
    display_name = 'builtins'
    persist = True
    extension = '.npy'
    readers = {'builtins': 'builtins'}
    paths = [str(pth)]
    stack = False

    with restore_settings_on_exit():
        viewer = make_napari_viewer()
        open_with_dialog_choices(
            display_name,
            persist,
            extension,
            readers,
            paths,
            stack,
            viewer.window._qt_viewer,
        )
        assert len(viewer.layers) == 1
        assert get_settings().plugins.extension2reader['.npy'] == 'builtins'
Example #4
0
def test_open_with_dialog_choices_raises(make_napari_viewer):
    pth = 'my-file.fake'
    display_name = 'Fake Plugin'
    persist = True
    extension = '.fake'
    readers = {'fake-plugin': 'Fake Plugin'}
    paths = [str(pth)]
    stack = False

    with restore_settings_on_exit():
        viewer = make_napari_viewer()
        get_settings().plugins.extension2reader = {}
        with pytest.raises(ValueError):
            open_with_dialog_choices(
                display_name,
                persist,
                extension,
                readers,
                paths,
                stack,
                viewer.window._qt_viewer,
            )
        # settings weren't saved because reading failed
        get_settings().plugins.extension2reader == {}