Beispiel #1
0
 def setup_method(self, method):
     self.data = mock_data()
     self.session = simple_session()
     self.collect = self.session.data_collection
     self.hub = self.session.hub
     self.collect.append(self.data)
     self.widget = HistogramWidget(self.session)
Beispiel #2
0
def test_resample_on_zoom():

    # For images where the aspect ratio of pixels is fixed to be square, when
    # the user zooms in, the limits of the axes are actually changed twice by
    # matplotlib - a second time when the aspect ratio is enforced. So we need
    # to make sure that we update the modest_image when this is the case.

    session = simple_session()

    np.random.seed(12345)

    data = Data(x=np.random.random((2048, 2048)), label='image')
    session.data_collection.append(data)

    image = ImageViewer(session=session)
    image.add_data(data)

    image.show()

    try:
        device_ratio = image.axes.figure.canvas.devicePixelRatio()
    except AttributeError:
        device_ratio = 1.

    image.axes.figure.canvas.key_press_event('o')
    image.axes.figure.canvas.button_press_event(200 * device_ratio, 200 * device_ratio, 1)
    image.axes.figure.canvas.motion_notify_event(400 * device_ratio, 210 * device_ratio)
    image.axes.figure.canvas.button_release_event(400 * device_ratio, 210 * device_ratio, 1)

    return image.axes.figure
Beispiel #3
0
 def setup_method(self, method):
     self.data = mock_data()
     self.session = simple_session()
     self.collect = self.session.data_collection
     self.hub = self.session.hub
     self.collect.append(self.data)
     self.widget = HistogramWidget(self.session)
Beispiel #4
0
def test_duplicate_shortcut():
    session = simple_session()
    with warnings.catch_warnings(record=True) as w:
        ExampleViewer2(session)
    assert len(w) == 1
    assert str(w[0].message) == ("Tools 'TEST1' and 'TEST2' have the same "
                                 "shortcut ('A'). Ignoring shortcut for 'TEST2'")
Beispiel #5
0
def test_resample_on_zoom():

    # For images where the aspect ratio of pixels is fixed to be square, when
    # the user zooms in, the limits of the axes are actually changed twice by
    # matplotlib - a second time when the aspect ratio is enforced. So we need
    # to make sure that we update the modest_image when this is the case.

    session = simple_session()

    np.random.seed(12345)

    data = Data(x=np.random.random((2048, 2048)), label='image')
    session.data_collection.append(data)

    image = ImageViewer(session=session)
    image.add_data(data)

    image.show()

    try:
        device_ratio = image.axes.figure.canvas.devicePixelRatio()
    except AttributeError:
        device_ratio = 1.

    image.axes.figure.canvas.key_press_event('o')
    image.axes.figure.canvas.button_press_event(200 * device_ratio,
                                                200 * device_ratio, 1)
    image.axes.figure.canvas.motion_notify_event(400 * device_ratio,
                                                 210 * device_ratio)
    image.axes.figure.canvas.button_release_event(400 * device_ratio,
                                                  210 * device_ratio, 1)

    return image.axes.figure
def test_toolbar(tmpdir):
    session = simple_session()
    with warnings.catch_warnings(record=True) as w:
        viewer = ExampleViewer(session)
        toolbar = viewer.toolbar

        # test save tool
        with patch('qtpy.compat.getsavefilename') as fd:
            fd.return_value = tmpdir.join('test.png').strpath, 'jnk'
            toolbar.actions['vispy:save'].trigger()

        # test rotate tool
        toolbar.actions['vispy:rotate'].toggle()
        assert toolbar.active_tool.tool_id == 'vispy:rotate'
        # TODO: assert a mode here
        toolbar.actions['vispy:rotate'].toggle()
        assert toolbar.active_tool is None

        # test record tool
        try:
            import imageio  # noqa
            toolbar.actions['vispy:record'].toggle()
            assert toolbar.active_tool.tool_id == 'vispy:record'
            toolbar.actions['vispy:record'].toggle()
            assert toolbar.active_tool.tool_id is None
        except ImportError:
            print('Imageio package needed')

    assert len(w) == 0
Beispiel #7
0
def test_duplicate_shortcut():
    session = simple_session()
    with warnings.catch_warnings(record=True) as w:
        ExampleViewer2(session)
    assert len(w) == 1
    assert str(
        w[0].message) == ("Tools 'TEST1' and 'TEST2' have the same "
                          "shortcut ('A'). Ignoring shortcut for 'TEST2'")
Beispiel #8
0
    def setup_method(self, method):
        s = simple_session()
        self.hub = s.hub
        self.data = core.Data(label='d1', x=[1, 2, 3])
        self.dc = s.data_collection
        self.dc.append(self.data)

        self.w = DendroWidget(s)
Beispiel #9
0
    def test_unregister_on_close(self):
        session = simple_session()
        hub = session.hub

        w = self.widget_cls(session)
        w.register_to_hub(hub)
        with patch.object(DataViewer, 'unregister') as unregister:
            w.close()
        unregister.assert_called_once_with(hub)
Beispiel #10
0
    def test_unregister_on_close(self):
        session = simple_session()
        hub = session.hub

        w = self.widget_cls(session)
        w.register_to_hub(hub)
        with patch.object(DataViewer, 'unregister') as unregister:
            w.close()
        unregister.assert_called_once_with(hub)
Beispiel #11
0
    def setup_method(self, method):
        setup.reset_mock()
        settings_changed.reset_mock()
        plot_subset.reset_mock()
        plot_data.reset_mock()
        make_selector.reset_mock()

        self.data = Data(x=[1, 2, 3], y=[2, 3, 4])
        self.session = simple_session()
        self.dc = self.session.data_collection
        self.dc.append(self.data)
Beispiel #12
0
    def setup_method(self, method):
        setup.reset_mock()
        settings_changed.reset_mock()
        plot_subset.reset_mock()
        plot_data.reset_mock()
        make_selector.reset_mock()

        self.data = Data(x=[1, 2, 3], y=[2, 3, 4])
        self.session = simple_session()
        self.dc = self.session.data_collection
        self.dc.append(self.data)
def test_volume_viewer():

    # Create fake data
    data = Data(primary=np.arange(1000).reshape((10,10,10)))

    # Create fake session
    session = simple_session()
    session.data_collection.append(data)

    w = VispyVolumeViewer(session)
    w.add_data(data)
    w.show()
Beispiel #14
0
def test_combo_box_updates():

    # Regression test for a bug that caused combo boxes to not be updated
    # correctly when switching between different datasets.

    session = simple_session()
    hub = session.hub
    dc = session.data_collection

    data1 = core.Data(label='im1',
                      x=[[1, 2], [3, 4]],
                      y=[[2, 3], [4, 5]])

    data2 = core.Data(label='im2',
                      a=[[1, 2], [3, 4]],
                      b=[[2, 3], [4, 5]])

    dc.append(data1)
    dc.append(data2)

    widget = ImageWidget(session)
    widget.register_to_hub(hub)

    widget.add_data(data1)

    assert widget.client.display_data is data1

    assert widget.data.label == 'im1'
    assert widget.attribute.label == 'x'

    widget.add_data(data2)

    assert widget.client.display_data is data2

    assert widget.data.label == 'im2'
    assert widget.attribute.label == 'a'

    widget.attribute = data2.find_component_id('b')

    with pytest.raises(ValueError) as exc:
        widget.attribute = data1.find_component_id('x')
    assert exc.value.args[0] == "Cannot find data 'x' in combo box"

    widget.data = data1
    assert widget.attribute.label == 'x'

    widget.attribute = data1.find_component_id('y')

    with pytest.raises(ValueError) as exc:
        widget.attribute = data2.find_component_id('a')
    assert exc.value.args[0] == "Cannot find data 'a' in combo box"

    assert widget.client.display_data is data1
Beispiel #15
0
def test_volume_viewer():

    # Create fake data
    data = Data(primary=np.arange(1000).reshape((10, 10, 10)))

    # Create fake session
    session = simple_session()
    session.data_collection.append(data)

    w = VispyVolumeViewer(session)
    w.add_data(data)
    w.show()
Beispiel #16
0
def test_style_dialog():

    # This is in part a regression test for a bug in Python 3. It is not a
    # full test of StyleDialog.

    session = simple_session()
    hub = session.hub
    collect = session.data_collection

    image = Data(label='im', x=[[1, 2], [3, 4]], y=[[2, 3], [4, 5]])

    pos = QtCore.QPoint(10, 10)
    st = NonBlockingStyleDialog.dropdown_editor(image, pos)
Beispiel #17
0
    def setup_method(self, method):
        self.session = simple_session()
        self.hub = self.session.hub
        self.collect = self.session.data_collection

        self.im = core.Data(label='im', x=[[1, 2], [3, 4]], y=[[2, 3], [4, 5]])
        self.cube = core.Data(label='cube',
                              x=[[[1, 2], [3, 4]], [[1, 2], [3, 4]]],
                              y=[[[1, 2], [3, 4]], [[1, 2], [3, 4]]])
        self.widget = self.widget_cls(self.session)
        self.connect_to_hub()
        self.collect.append(self.im)
        self.collect.append(self.cube)
Beispiel #18
0
def test_style_dialog():

    # This is in part a regression test for a bug in Python 3. It is not a
    # full test of StyleDialog.

    session = simple_session()
    hub = session.hub
    collect = session.data_collection

    image = Data(label="im", x=[[1, 2], [3, 4]], y=[[2, 3], [4, 5]])

    pos = QtCore.QPoint(10, 10)
    st = NonBlockingStyleDialog.dropdown_editor(image, pos)
Beispiel #19
0
    def setup_method(self, method):

        self.data = Data(label='d1', x=[3.4, 2.3, -1.1, 0.3], y=['a', 'b', 'c', 'a'])

        self.session = simple_session()
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)

        self.viewer = HistogramViewer(self.session)

        self.data_collection.register_to_hub(self.hub)
        self.viewer.register_to_hub(self.hub)
Beispiel #20
0
    def setup_method(self, method):

        self.setup_data()

        session = simple_session()
        session.data_collection.append(self.data)

        self.image = ImageWidget(session)
        self.image.add_data(self.data)
        self.image.data = self.data
        self.image.attribute = self.data.id['x']
        self.mode = self.image.toolbar.tools['spectrum']
        self.tool = self.mode._tool
        self.tool.show = lambda *args: None
Beispiel #21
0
    def setup_method(self, method):

        self.data = self.init_data()

        self.session = simple_session()
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)

        self.viewer = self.viewer_cls(self.session)

        self.data_collection.register_to_hub(self.hub)
        self.viewer.register_to_hub(self.hub)
    def setup_method(self, method):

        self.setup_data()

        session = simple_session()
        session.data_collection.append(self.data)

        self.image = ImageViewer(session)
        self.image.add_data(self.data)
        self.image.data = self.data
        self.image.attribute = self.data.id['x']
        self.mode = self.image.toolbar.tools['spectrum']
        self.tool = self.mode._tool
        self.tool.show = lambda *args: None
    def setup_method(self, method):

        self.data = Data(label='d1', x=[3.4, 2.3, -1.1, 0.3], y=['a', 'b', 'c', 'a'])

        self.session = simple_session()
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)

        self.viewer = HistogramViewer(self.session)

        self.data_collection.register_to_hub(self.hub)
        self.viewer.register_to_hub(self.hub)
Beispiel #24
0
def test_combo_box_updates():

    # Regression test for a bug that caused combo boxes to not be updated
    # correctly when switching between different datasets.

    session = simple_session()
    hub = session.hub
    dc = session.data_collection

    data1 = core.Data(label='im1', x=[[1, 2], [3, 4]], y=[[2, 3], [4, 5]])

    data2 = core.Data(label='im2', a=[[1, 2], [3, 4]], b=[[2, 3], [4, 5]])

    dc.append(data1)
    dc.append(data2)

    widget = ImageWidget(session)
    widget.register_to_hub(hub)

    widget.add_data(data1)

    assert widget.client.display_data is data1

    assert widget.data.label == 'im1'
    assert widget.attribute.label == 'x'

    widget.add_data(data2)

    assert widget.client.display_data is data2

    assert widget.data.label == 'im2'
    assert widget.attribute.label == 'a'

    widget.attribute = data2.find_component_id('b')

    with pytest.raises(ValueError) as exc:
        widget.attribute = data1.find_component_id('x')
    assert exc.value.args[0] == "Cannot find data 'x' in combo box"

    widget.data = data1
    assert widget.attribute.label == 'x'

    widget.attribute = data1.find_component_id('y')

    with pytest.raises(ValueError) as exc:
        widget.attribute = data2.find_component_id('a')
    assert exc.value.args[0] == "Cannot find data 'a' in combo box"

    assert widget.client.display_data is data1
Beispiel #25
0
 def setup_method(self, method):
     s = simple_session()
     self.hub = s.hub
     self.d1 = core.Data(x=[1, 2, 3], y=[2, 3, 4],
                         z=[3, 4, 5], w=[4, 5, 6])
     self.d1.label = 'd1'
     self.d2 = core.Data(x=[1, 2, 3], y=[2, 3, 4],
                         z=[3, 4, 5], w=[4, 5, 6])
     self.d2.label = 'd2'
     self.data = [self.d1, self.d2]
     self.collect = s.data_collection
     self.collect.append(self.data)
     self.widget = ScatterWidget(s)
     self.session = s
     self.connect_to_hub()
Beispiel #26
0
    def setup_method(self, method):
        self.session = simple_session()
        self.hub = self.session.hub
        self.collect = self.session.data_collection

        self.im = core.Data(label='im',
                            x=[[1, 2], [3, 4]],
                            y=[[2, 3], [4, 5]])
        self.cube = core.Data(label='cube',
                              x=[[[1, 2], [3, 4]], [[1, 2], [3, 4]]],
                              y=[[[1, 2], [3, 4]], [[1, 2], [3, 4]]])
        self.widget = self.widget_cls(self.session)
        self.connect_to_hub()
        self.collect.append(self.im)
        self.collect.append(self.cube)
Beispiel #27
0
 def setup_method(self, method):
     s = simple_session()
     self.hub = s.hub
     self.d1 = core.Data(x=[1, 2, 3], y=[2, 3, 4],
                         z=[3, 4, 5], w=[4, 5, 6])
     self.d1.label = 'd1'
     self.d2 = core.Data(x=[1, 2, 3], y=[2, 3, 4],
                         z=[3, 4, 5], w=[4, 5, 6])
     self.d2.label = 'd2'
     self.data = [self.d1, self.d2]
     self.collect = s.data_collection
     self.collect.append(self.data)
     self.widget = ScatterWidget(s)
     self.session = s
     self.connect_to_hub()
def test_scatter_viewer():

    # Create fake data
    data = make_test_data()

    # Create fake session
    session = simple_session()
    session.data_collection.append(data)

    w = VispyScatterViewer(session)
    w.add_data(data)
    w.show()
    w._options_widget.show()

    # Get layer artist style editor
    layer_artist, style_widget = w._view.layout_style_widgets.popitem()
def test_scatter_viewer():

    # Create fake data
    data = make_test_data()

    # Create fake session
    session = simple_session()
    session.data_collection.append(data)

    w = VispyScatterViewer(session)
    w.add_data(data)
    w.show()
    w._options_widget.show()

    # Get layer artist style editor
    layer_artist, style_widget = w._view.layout_style_widgets.popitem()
Beispiel #30
0
    def setup_method(self, method):

        self.setup_data()

        session = simple_session()
        session.data_collection.append(self.data)

        self.image = ImageWidget(session)
        self.image.add_data(self.data)
        self.image.data = self.data
        self.image.attribute = self.data.id['x']
        for tool in self.image._tools:
            if isinstance(tool, SpectrumTool):
                self.tool = tool
                break
        else:
            raise Exception("SpectrumTool not found")
        self.tool.show = lambda *args: None
Beispiel #31
0
    def setup_method(self, method):

        self.setup_data()

        session = simple_session()
        session.data_collection.append(self.data)

        self.image = ImageWidget(session)
        self.image.add_data(self.data)
        self.image.data = self.data
        self.image.attribute = self.data.id['x']
        for tool in self.image._tools:
            if isinstance(tool, SpectrumTool):
                self.tool = tool
                break
        else:
            raise Exception("SpectrumTool not found")
        self.tool.show = lambda *args: None
Beispiel #32
0
    def setup_method(self, method):

        self.data = Data(label='d1', x=[3.4, 2.3, -1.1, 0.3],
                         y=[3.2, 3.3, 3.4, 3.5], z=['a', 'b', 'c', 'a'])
        self.data_2d = Data(label='d2', a=[[1, 2], [3, 4]], b=[[5, 6], [7, 8]],
                            x=[[3, 5], [5.4, 1]], y=[[1.2, 4], [7, 8]])

        self.session = simple_session()
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)
        self.data_collection.append(self.data_2d)

        self.viewer = ScatterViewer(self.session)

        self.data_collection.register_to_hub(self.hub)
        self.viewer.register_to_hub(self.hub)
def test_volumeviewer_toolbar():
    session = simple_session()
    v = VispyVolumeViewer(session)
    data = make_test_data()
    session.data_collection.append(data)
    v.add_data(data)
    assert v.toolbar is not None

    toolbar = v.toolbar

    # test rotate tool
    toolbar.actions['vispy:rotate'].toggle()
    assert toolbar.active_tool.tool_id == 'vispy:rotate'
    # TODO: assert a mode here
    toolbar.actions['vispy:rotate'].toggle()
    assert toolbar.active_tool is None

    # test lasso selection tool
    toolbar.actions['vispy:lasso'].toggle()
    assert 'vispy:lasso' in toolbar.active_tool.tool_id
    lasso = toolbar.active_tool
    # event = QTest.mouseMove(viewer._vispy_widget)

    # TODO: add a real mouse move event so content in lasso.move() is called
    lasso.press(MouseEvent('mouse_press'))
    lasso.move(MouseEvent('mouse_move'))
    lasso.release(MouseEvent('mouse_release'))
    assert toolbar.tools['vispy:lasso'] == lasso

    # add point selection test
    # set to perspective mode
    toolbar.actions['volume3d:floodfill'].toggle()
    assert 'volume3d:floodfill' in toolbar.active_tool.tool_id
    point = toolbar.active_tool
    # event = QTest.mouseMove(viewer._vispy_widget)

    # TODO: add a real mouse move event so content in lasso.move() is called
    point.press(MouseEvent('mouse_press'))
    point.move(MouseEvent('mouse_move'))
    point.release(MouseEvent('mouse_release'))
    assert toolbar.tools['volume3d:floodfill'] == point

    v.close()
def test_volumeviewer_toolbar():
    session = simple_session()
    v = VispyVolumeViewer(session)
    data = make_test_data()
    v.add_data(data)
    assert v.toolbar is not None

    toolbar = v.toolbar

    # test rotate tool
    toolbar.actions['vispy:rotate'].toggle()
    assert toolbar.active_tool.tool_id == 'vispy:rotate'
    # TODO: assert a mode here
    toolbar.actions['vispy:rotate'].toggle()
    assert toolbar.active_tool is None

    # test lasso selection tool
    toolbar.actions['vispy:lasso'].toggle()
    assert 'vispy:lasso' in toolbar.active_tool.tool_id
    lasso = toolbar.active_tool
    # event = QTest.mouseMove(viewer._vispy_widget)

    # TODO: add a real mouse move event so content in lasso.move() is called
    lasso.press(MouseEvent('mouse_press'))
    lasso.move(MouseEvent('mouse_move'))
    lasso.release(MouseEvent('mouse_release'))
    assert toolbar.tools['vispy:lasso'] == lasso

    # add point selection test
    # set to perspective mode
    toolbar.actions['volume3d:point'].toggle()
    assert 'volume3d:point' in toolbar.active_tool.tool_id
    point = toolbar.active_tool
    # event = QTest.mouseMove(viewer._vispy_widget)

    # TODO: add a real mouse move event so content in lasso.move() is called
    point.press(MouseEvent('mouse_press'))
    point.move(MouseEvent('mouse_move'))
    point.release(MouseEvent('mouse_release'))
    assert toolbar.tools['volume3d:point'] == point
Beispiel #35
0
    def setup_method(self, method):

        self.data = Data(label='d1',
                         x=[3.4, 2.3, -1.1, 0.3],
                         y=[3.2, 3.3, 3.4, 3.5],
                         z=['a', 'b', 'c', 'a'])
        self.data_2d = Data(label='d2',
                            a=[[1, 2], [3, 4]],
                            b=[[5, 6], [7, 8]],
                            x=[[3, 5], [5.4, 1]],
                            y=[[1.2, 4], [7, 8]])

        self.session = simple_session()
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)
        self.data_collection.append(self.data_2d)

        self.viewer = ScatterViewer(self.session)

        self.data_collection.register_to_hub(self.hub)
        self.viewer.register_to_hub(self.hub)
Beispiel #36
0
def _make_widget(viewer):
    s = simple_session()
    return viewer._widget_cls(s)
Beispiel #37
0
 def setup_method(self, method):
     self.session = simple_session()
     self.viewer = ExampleViewer(self.session)
     self._called_back = False
Beispiel #38
0
def _make_widget(viewer):
    s = simple_session()
    return viewer._widget_cls(s)
Beispiel #39
0
 def setup_method(self, method):
     self.data = Data(x=[1, 2, 3], y=[2, 3, 4])
     self.session = simple_session()
     self.dc = self.session.data_collection
     self.dc.append(self.data)
Beispiel #40
0
 def setup_method(self, method):
     self.session = simple_session()
     self.viewer = ExampleViewer(self.session)
     self._called_back = False
Beispiel #41
0
def test_duplicate_shortcut():
    session = simple_session()
    expected_warning = ("Tools 'TEST1' and 'TEST2' have the same "
                        r"shortcut \('A'\). Ignoring shortcut for 'TEST2'")
    with pytest.warns(UserWarning, match=expected_warning):
        ExampleViewer2(session)
Beispiel #42
0
 def setup_method(self, method):
     self.data = Data(x=[1, 2, 3], y=[2, 3, 4])
     self.session = simple_session()
     self.dc = self.session.data_collection
     self.dc.append(self.data)