Exemple #1
0
 def controller(self):
     self.image_view = pds_image_view_canvas.PDSImageViewCanvas()
     self.image_view.set_image(self.image)
     self.model = histogram.HistogramModel(self.image_view)
     self.model.register(self.view)
     controller = histogram.HistogramController(self.model, self.view)
     return controller
Exemple #2
0
 def hist_widget(self, qtbot):
     self.image_view = pds_image_view_canvas.PDSImageViewCanvas()
     self.image_view.set_image(self.image)
     self.model = histogram.HistogramModel(self.image_view)
     hist_widget = histogram.HistogramWidget(self.model)
     qtbot.addWidget(hist_widget)
     hist_widget.show()
     return hist_widget
Exemple #3
0
class TestHistogramController(object):

    image_view = pds_image_view_canvas.PDSImageViewCanvas()
    image = pdsspect_image_set.ImageStamp(FILE_1)
    image_view.set_image(image)
    view = MockView()
    model = histogram.HistogramModel(image_view, view)
    model.register(view)

    @pytest.fixture
    def controller(self):
        self.image_view = pds_image_view_canvas.PDSImageViewCanvas()
        self.image_view.set_image(self.image)
        self.model = histogram.HistogramModel(self.image_view)
        self.model.register(self.view)
        controller = histogram.HistogramController(self.model, self.view)
        return controller

    def test_set_cut_low(self, controller):
        controller.set_cut_low(24)
        assert self.model.cut_low == 24
        assert self.model.view_cuts[0] == 24

    def test_set_cut_high(self, controller):
        controller.set_cut_high(42)
        assert self.model.cut_high == 42
        assert self.model.view_cuts[1] == 42

    def test_set_cuts(self, controller):
        controller.set_cuts(10, 100)
        assert self.model.cut_low == 10
        assert self.model.cut_high == 100
        assert self.model.cuts == (10, 100)
        assert self.model.view_cuts == (10, 100)

    def test_set_bins(self, controller):
        controller.set_bins(50)
        assert self.model.bins == 50

    def test_controller_restore(self, controller):
        def_cuts = self.model.view_cuts
        self.model.cuts = 24, 42
        self.image_view.cut_levels(*def_cuts)
        controller.restore()
        assert self.model.cuts != (24, 42)
        assert self.model.cuts == def_cuts
        assert self.model.view_cuts == def_cuts
Exemple #4
0
class TestHistogramWidget(object):

    image_view = pds_image_view_canvas.PDSImageViewCanvas()
    image = pdsspect_image_set.ImageStamp(FILE_1)
    image_view.set_image(image)
    model = histogram.HistogramModel(image_view)

    @pytest.fixture
    def hist_widget(self, qtbot):
        self.image_view = pds_image_view_canvas.PDSImageViewCanvas()
        self.image_view.set_image(self.image)
        self.model = histogram.HistogramModel(self.image_view)
        hist_widget = histogram.HistogramWidget(self.model)
        qtbot.addWidget(hist_widget)
        hist_widget.show()
        return hist_widget

    def test_histogram_widget_change_cut_low(self, hist_widget):
        new_cut_low = self.model.cut_low - 3
        self.model._cut_low = new_cut_low
        hist_widget.change_cut_low()
        assert float(hist_widget._cut_low_box.text()) == new_cut_low
        new_cut_low += 1.2
        self.model._cut_low = new_cut_low
        hist_widget.change_cut_low()
        assert float(hist_widget._cut_low_box.text()) == new_cut_low

    def test_histogram_widget_change_cut_high(self, hist_widget):
        new_cut_high = round(self.model.cut_high + 3, 3)
        self.model._cut_high = new_cut_high
        hist_widget.change_cut_high()
        assert float(hist_widget._cut_high_box.text()) == new_cut_high
        new_cut_high -= 1.2
        self.model._cut_high = new_cut_high
        hist_widget.change_cut_high()
        assert float(hist_widget._cut_high_box.text()) == new_cut_high

    def test_histogram_widget_change_cuts(self, hist_widget):
        new_cut_high = round(self.model.cut_high + 3, 3)
        self.model._cut_high = new_cut_high
        new_cut_low = round(self.model.cut_low - 3, 3)
        self.model._cut_low = new_cut_low
        hist_widget.change_cuts()
        assert float(hist_widget._cut_low_box.text()) == new_cut_low
        assert float(hist_widget._cut_high_box.text()) == new_cut_high
        new_cut_high -= 1.2
        self.model._cut_high = new_cut_high
        new_cut_low += 1.2
        self.model._cut_low = new_cut_low
        hist_widget.change_cuts()
        assert float(hist_widget._cut_low_box.text()) == new_cut_low
        assert float(hist_widget._cut_high_box.text()) == new_cut_high

    def test_histogram_widget_change_bins(self, hist_widget):
        new_bins = self.model.bins + 20
        self.model._bins = new_bins
        hist_widget.change_bins()
        assert int(hist_widget._bins_box.text()) == new_bins

    def test_histogram_widget_keyPressEvent(self, hist_widget, qtbot):
        # Change only cut low
        new_cut_low = self.model.cut_low - 3
        hist_widget._cut_low_box.setText("%.3f" % (new_cut_low))
        qtbot.keyPress(hist_widget, QtCore.Qt.Key_Return)
        assert self.model.cut_low == new_cut_low
        # Change only cut high
        new_cut_high = self.model.cut_high + 3
        hist_widget._cut_high_box.setText("%.3f" % (new_cut_high))
        qtbot.keyPress(hist_widget, QtCore.Qt.Key_Return)
        assert self.model.cut_high == new_cut_high
        # Change both cuts
        new_cut_low += 1.5
        new_cut_high -= 1.5
        hist_widget._cut_low_box.setText("%.3f" % (new_cut_low))
        hist_widget._cut_high_box.setText("%.3f" % (new_cut_high))
        qtbot.keyPress(hist_widget, QtCore.Qt.Key_Return)
        assert self.model.cut_low == new_cut_low
        assert self.model.cut_high == new_cut_high
        # Change the bins
        new_bins = self.model.bins + 50
        hist_widget._bins_box.setText("%d" % (new_bins))
        qtbot.keyPress(hist_widget, QtCore.Qt.Key_Return)
        assert self.model.bins == new_bins
        assert self.model.cut_low == new_cut_low
        assert self.model.cut_high == new_cut_high
        # Change all
        new_cut_low += 1.5
        new_cut_high -= 1.5
        hist_widget._cut_low_box.setText("%.3f" % (new_cut_low))
        hist_widget._cut_high_box.setText("%.3f" % (new_cut_high))
        new_bins -= 25
        hist_widget._bins_box.setText("%d" % (new_bins))
        qtbot.keyPress(hist_widget, QtCore.Qt.Key_Return)
        assert self.model.bins == new_bins
        assert self.model.cut_low == new_cut_low
        assert self.model.cut_high == new_cut_high
        # Test Warnings
        hist_widget._cut_low_box.setText('foo')
        qtbot.keyPress(hist_widget, QtCore.Qt.Key_Return)
        assert hist_widget._cut_low_box.text() == "%.3f" % (new_cut_low)
        hist_widget._bins_box.setText('bar')
        qtbot.keyPress(hist_widget, QtCore.Qt.Key_Return)
        assert hist_widget._bins_box.text() == "%d" % (new_bins)
Exemple #5
0
 def model(self):
     self.image_view = pds_image_view_canvas.PDSImageViewCanvas()
     self.image_view.set_image(self.image)
     return histogram.HistogramModel(self.image_view)
Exemple #6
0
class TestHistogram(object):
    image_view = pds_image_view_canvas.PDSImageViewCanvas()
    image = pdsspect_image_set.ImageStamp(FILE_1)
    image_view.set_image(image)
    model = histogram.HistogramModel(image_view)

    @pytest.fixture
    def hist(self, qtbot):
        self.image_view = pds_image_view_canvas.PDSImageViewCanvas()
        self.image_view.set_image(self.image)
        self.model = histogram.HistogramModel(self.image_view)
        hist = histogram.Histogram(self.model)
        qtbot.addWidget(hist)
        hist.show()
        return hist

    def test_init(self, hist):
        assert hist.model == self.model
        assert hist in self.model._views
        assert hist.sizePolicy().hasHeightForWidth()
        assert hist._right_vline is None
        assert hist._left_vline is None

    def test_set_vlines(self, hist):
        assert hist._right_vline is None
        assert hist._left_vline is None
        hist._set_vlines()
        assert isinstance(hist._left_vline, Line2D)
        assert isinstance(hist._right_vline, Line2D)
        assert hist._left_vline.get_xdata()[0] == self.model.cut_low
        assert hist._right_vline.get_xdata()[0] == self.model.cut_high
        assert hist._left_vline.get_xdata()[1] == self.model.cut_low
        assert hist._right_vline.get_xdata()[1] == self.model.cut_high

    def test_change_cut_low(self, hist):
        hist._set_vlines()
        self.model._cut_low = 24
        hist.change_cut_low(draw=True)
        assert hist._left_vline.get_xdata()[0] == 24
        assert hist._right_vline.get_xdata()[0] == self.model.cut_high
        assert hist._left_vline.get_xdata()[1] == 24
        assert hist._right_vline.get_xdata()[1] == self.model.cut_high

    def test_change_cut_high(self, hist):
        hist._set_vlines()
        self.model._cut_high = 42
        hist.change_cut_high(draw=True)
        assert hist._right_vline.get_xdata()[0] == 42
        assert hist._left_vline.get_xdata()[0] == self.model.cut_low
        assert hist._right_vline.get_xdata()[1] == 42
        assert hist._left_vline.get_xdata()[1] == self.model.cut_low

    def test_change_cuts(self, hist):
        self.model._cut_low = 24
        self.model._cut_high = 42
        with pytest.raises(AttributeError):
            hist.change_cuts()
            assert hist._left_vline.get_xdata()[0] == 24
        with pytest.raises(AttributeError):
            hist.change_cuts()
            assert hist._right_vline.get_xdata()[0] == 42
        hist._set_vlines()
        self.model._cut_low = 24
        self.model._cut_high = 42
        hist.change_cuts()
        assert hist._left_vline.get_xdata()[0] == 24
        assert hist._right_vline.get_xdata()[0] == 42
        assert hist._left_vline.get_xdata()[1] == 24
        assert hist._right_vline.get_xdata()[1] == 42

    def test_change_bins(self, hist):
        hist.set_data()
        assert self.model.bins == 100
        assert len(hist._ax.patches) == 100
        self.model._bins = 50
        hist.change_bins()
        assert len(hist._ax.patches) == 50

    # def test_histogram_move_line(qtbot):
    #     """Testing the move line is much more difficult than I thought
    #     Passing in the correct data points is very tough and I can't
    #     figure out exactly how to do so."""

    def test_warn(self, hist):
        assert not hist.warn('foo', 'bar')