def test_setPlotConfiguration(self, qtbot, mocker):
        cxp = Centroid1dPlotWidget()
        cyp = Centroid1dPlotWidget()
        csp = CentroidScatterPlotWidget()
        qtbot.addWidget(cxp)
        qtbot.addWidget(cyp)
        qtbot.addWidget(csp)
        p1cc = PlotCentroidController(cxp, cyp, csp)
        p1cc.setup(self.bufferSize, self.roiFps)
        mockXSetConfiguration = mocker.patch.object(p1cc.x1dPlot,
                                                    'setConfiguration')
        mockYSetConfiguration = mocker.patch.object(p1cc.y1dPlot,
                                                    'setConfiguration')
        mockScatterSetConfiguration = mocker.patch.object(
            p1cc.scatterPlot, 'setConfiguration')

        truthConfig = {
            'xCentroid': {
                'autoscale': False,
                'minimum': 10,
                'maximum': 1000
            },
            'yCentroid': {
                'autoscale': True,
                'minimum': None,
                'maximum': None
            },
            'scatterPlot': {
                'numHistogramBins': 50
            }
        }
        p1cc.setPlotConfiguration(truthConfig)
        assert mockXSetConfiguration.call_count == 1
        assert mockYSetConfiguration.call_count == 1
        assert mockScatterSetConfiguration.call_count == 1
 def test_getPlotConfiguration(self, qtbot):
     cxp = Centroid1dPlotWidget()
     cyp = Centroid1dPlotWidget()
     csp = CentroidScatterPlotWidget()
     qtbot.addWidget(cxp)
     qtbot.addWidget(cyp)
     qtbot.addWidget(csp)
     p1cc = PlotCentroidController(cxp, cyp, csp)
     currentConfig = p1cc.getPlotConfiguration()
     assert currentConfig == self.truthConfig
    def test_parametersAfterConstruction(self, qtbot):
        cxp = Centroid1dPlotWidget()
        cyp = Centroid1dPlotWidget()
        csp = CentroidScatterPlotWidget()
        qtbot.addWidget(cxp)
        qtbot.addWidget(cyp)
        qtbot.addWidget(csp)

        p1cc = PlotCentroidController(cxp, cyp, csp)
        assert p1cc.x1dPlot is not None
        assert p1cc.y1dPlot is not None
        assert p1cc.scatterPlot is not None
        assert p1cc.config is not None
 def test_updateRoiFps(self, qtbot, mocker):
     cxp = Centroid1dPlotWidget()
     cyp = Centroid1dPlotWidget()
     csp = CentroidScatterPlotWidget()
     qtbot.addWidget(cxp)
     qtbot.addWidget(cyp)
     qtbot.addWidget(csp)
     p1cc = PlotCentroidController(cxp, cyp, csp)
     mockXSetRoiFps = mocker.patch.object(p1cc.x1dPlot, 'setRoiFps')
     mockYSetRoiFps = mocker.patch.object(p1cc.y1dPlot, 'setRoiFps')
     p1cc.setup(self.bufferSize, self.roiFps)
     p1cc.updateRoiFps(20)
     assert mockXSetRoiFps.call_count == 1
     assert mockYSetRoiFps.call_count == 1
    def test_parametersAfterSetup(self, qtbot):
        cxp = Centroid1dPlotWidget()
        cyp = Centroid1dPlotWidget()
        csp = CentroidScatterPlotWidget()
        qtbot.addWidget(cxp)
        qtbot.addWidget(cyp)
        qtbot.addWidget(csp)

        p1cc = PlotCentroidController(cxp, cyp, csp)
        p1cc.setup(self.bufferSize, self.roiFps)

        assert p1cc.x1dPlot.dataSize == self.bufferSize
        assert p1cc.y1dPlot.dataSize == self.bufferSize
        assert p1cc.scatterPlot.dataSize == self.bufferSize
 def test_updatePlot(self, qtbot, mocker):
     c1dpw = Centroid1dPlotWidget()
     c1dpw.show()
     qtbot.addWidget(c1dpw)
     arraySize = 3
     currentFps = 2
     c1dpw.numAccumFrames = 2
     c1dpw.setup(arraySize, 'X', currentFps)
     timeRange = [0.0, 0.5, 1.0]
     assert c1dpw.timeRange.tolist() == timeRange
     mockSetData = mocker.patch.object(c1dpw.curve, 'setData')
     values = [254.43, 254.86, 253.91, 254.21]
     c1dpw.updatePlot(values[0])
     assert c1dpw.data.tolist() == [values[0]] + 2 * [0.0]
     assert c1dpw.dataCounter == 1
     assert c1dpw.yRange is None
     c1dpw.updatePlot(values[1])
     assert c1dpw.data.tolist() == [values[0], values[1], 0.0]
     assert c1dpw.yRange == [244, 264]
     c1dpw.updatePlot(values[2])
     assert c1dpw.data.tolist() == values[:-1]
     assert c1dpw.dataCounter == arraySize
     assert c1dpw.rollArray is True
     c1dpw.updatePlot(values[3])
     assert c1dpw.data.tolist() == values[1:]
     assert c1dpw.dataCounter == arraySize
     assert c1dpw.rollArray is True
     assert mockSetData.call_count == len(values)
 def test_handleAcquireRoiStateChange(self, qtbot, mocker):
     cxp = Centroid1dPlotWidget()
     cyp = Centroid1dPlotWidget()
     csp = CentroidScatterPlotWidget()
     qtbot.addWidget(cxp)
     qtbot.addWidget(cyp)
     qtbot.addWidget(csp)
     p1cc = PlotCentroidController(cxp, cyp, csp)
     p1cc.setup(self.bufferSize, self.roiFps)
     mockXClearPlot = mocker.patch.object(p1cc.x1dPlot, 'clearPlot')
     mockYClearPlot = mocker.patch.object(p1cc.y1dPlot, 'clearPlot')
     mockScatterClearPlot = mocker.patch.object(p1cc.scatterPlot,
                                                'clearPlot')
     p1cc.handleAcquireRoiStateChange(Qt.Unchecked)
     assert mockXClearPlot.call_count == 1
     assert mockYClearPlot.call_count == 1
     assert mockScatterClearPlot.call_count == 1
    def test_update(self, qtbot):
        cxp = Centroid1dPlotWidget()
        cyp = Centroid1dPlotWidget()
        csp = CentroidScatterPlotWidget()
        qtbot.addWidget(cxp)
        qtbot.addWidget(cyp)
        qtbot.addWidget(csp)

        p1cc = PlotCentroidController(cxp, cyp, csp)
        p1cc.setup(self.bufferSize, self.roiFps)
        centroidX = 253.543
        centroidY = 313.683
        p1cc.update(centroidX, centroidY)

        assert p1cc.x1dPlot.data[0] == centroidX
        assert p1cc.y1dPlot.data[0] == centroidY
        assert p1cc.scatterPlot.xData[0] == centroidX
        assert p1cc.scatterPlot.yData[0] == centroidY
 def test_showScatterPlots(self, qtbot, mocker):
     cxp = Centroid1dPlotWidget()
     cyp = Centroid1dPlotWidget()
     csp = CentroidScatterPlotWidget()
     qtbot.addWidget(cxp)
     qtbot.addWidget(cyp)
     qtbot.addWidget(csp)
     mocker.patch('spot_motion_monitor.views.centroid_scatter_plot_widget.'
                  'CentroidScatterPlotWidget.showPlot')
     p1cc = PlotCentroidController(cxp, cyp, csp)
     p1cc.setup(self.bufferSize, self.roiFps)
     centroidX = 253.543
     centroidY = 313.683
     p1cc.update(centroidX, centroidY)
     p1cc.showScatterPlots(False)
     assert p1cc.scatterPlot.showPlot.call_count == 0
     p1cc.showScatterPlots(True)
     assert p1cc.scatterPlot.showPlot.call_count == 1
 def test_updateRoiFps(self, qtbot):
     c1dpw = Centroid1dPlotWidget()
     c1dpw.show()
     qtbot.addWidget(c1dpw)
     arraySize = 1024
     c1dpw.setup(arraySize, 'X', 40)
     newRoiFps = 90
     c1dpw.setRoiFps(newRoiFps)
     assert c1dpw.timeRange.shape[0] == arraySize
     assert c1dpw.timeRange[-1] == (arraySize - 1) / newRoiFps
    def test_badCentroidsUpdate(self, qtbot, mocker):
        cxp = Centroid1dPlotWidget()
        cyp = Centroid1dPlotWidget()
        csp = CentroidScatterPlotWidget()
        qtbot.addWidget(cxp)
        qtbot.addWidget(cyp)
        qtbot.addWidget(csp)
        mocker.patch(
            'spot_motion_monitor.views.centroid_1d_plot_widget.Centroid1dPlotWidget.updatePlot'
        )
        mocker.patch('spot_motion_monitor.views.centroid_scatter_plot_widget.'
                     'CentroidScatterPlotWidget.updateData')

        p1cc = PlotCentroidController(cxp, cyp, csp)
        p1cc.setup(self.bufferSize, self.roiFps)
        p1cc.update(None, None)
        assert p1cc.x1dPlot.updatePlot.call_count == 0
        assert p1cc.y1dPlot.updatePlot.call_count == 0
        assert p1cc.scatterPlot.updateData.call_count == 0
 def test_getConfiguration(self, qtbot):
     c1dpw = Centroid1dPlotWidget()
     c1dpw.show()
     qtbot.addWidget(c1dpw)
     truthAutoscale = AutoscaleState.PARTIAL
     truthPixelAddition = 10
     truthMinimum = None
     truthMaximum = None
     autoscale, irange, pixelAddition = c1dpw.getConfiguration()
     assert autoscale == truthAutoscale
     assert irange[0] == truthMinimum
     assert irange[1] == truthMaximum
     assert pixelAddition == truthPixelAddition
 def test_parametersAfterSetup(self, qtbot):
     c1dpw = Centroid1dPlotWidget()
     qtbot.addWidget(c1dpw)
     arraySize = 1000
     roiFps = 40
     c1dpw.setup(arraySize, 'X', roiFps)
     assert c1dpw.plot is not None
     assert c1dpw.curve is not None
     assert c1dpw.dataSize == arraySize
     assert c1dpw.data.size == arraySize
     assert c1dpw.timeRange.size == arraySize
     assert c1dpw.rollArray is False
     assert c1dpw.roiFps == roiFps
     assert c1dpw.axis == 'X'
 def test_updateArraySize(self, qtbot):
     c1dpw = Centroid1dPlotWidget()
     c1dpw.show()
     qtbot.addWidget(c1dpw)
     arraySize = 1024
     roiFps = 40
     c1dpw.setup(arraySize, 'X', roiFps)
     c1dpw.rollArray = True
     newArraySize = 2048
     c1dpw.setArraySize(newArraySize)
     assert c1dpw.dataSize == newArraySize
     assert c1dpw.data.shape[0] == newArraySize
     assert c1dpw.timeRange.shape[0] == newArraySize
     assert c1dpw.timeRange[-1] == (newArraySize - 1) / roiFps
     assert c1dpw.rollArray is False
 def test_parametersAfterConstruction(self, qtbot):
     c1dpw = Centroid1dPlotWidget()
     qtbot.addWidget(c1dpw)
     assert c1dpw.plot is None
     assert c1dpw.curve is None
     assert c1dpw.dataSize is None
     assert c1dpw.data is None
     assert c1dpw.timeRange is None
     assert c1dpw.dataCounter == 0
     assert c1dpw.rollArray is False
     assert c1dpw.roiFps is None
     assert c1dpw.autoscale == AutoscaleState.PARTIAL
     assert c1dpw.yRange is None
     assert c1dpw.pixelRangeAddition == 10
     assert c1dpw.numAccumFrames == 15
     assert c1dpw.axis is None
 def test_clearPlot(self, qtbot, mocker):
     c1dpw = Centroid1dPlotWidget()
     c1dpw.show()
     qtbot.addWidget(c1dpw)
     arraySize = 3
     currentFps = 2
     c1dpw.numAccumFrames = 2
     c1dpw.setup(arraySize, 'X', currentFps)
     values = [254.43, 254.86, 253.91, 254.21]
     c1dpw.updatePlot(values[0])
     c1dpw.updatePlot(values[1])
     c1dpw.updatePlot(values[2])
     c1dpw.updatePlot(values[3])
     c1dpw.clearPlot()
     assert c1dpw.rollArray is False
     assert c1dpw.dataCounter == 0
     assert np.all(c1dpw.data == 0)
     assert c1dpw.yRange is None
 def test_setConfiguration(self, qtbot):
     c1dpw = Centroid1dPlotWidget()
     c1dpw.show()
     qtbot.addWidget(c1dpw)
     arraySize = 1024
     roiFps = 40
     c1dpw.setup(arraySize, 'X', roiFps)
     truthConfig = CentroidPlotConfig()
     truthConfig.autoscaleX = AutoscaleState.OFF
     truthConfig.minimumX = 10
     truthConfig.maximumX = 100
     c1dpw.setConfiguration(truthConfig)
     c1dpw.autoscale == AutoscaleState.OFF
     c1dpw.yRange = [truthConfig.minimumX, truthConfig.maximumX]
     truthConfig.autoscaleX = AutoscaleState.ON
     c1dpw.setConfiguration(truthConfig)
     c1dpw.autoscale == AutoscaleState.ON
     c1dpw.yRange is None
     truthConfig.autoscaleX = AutoscaleState.PARTIAL
     truthConfig.pixelRangeAdditionX = 25
     c1dpw.setConfiguration(truthConfig)
     c1dpw.autoscale == AutoscaleState.PARTIAL
     c1dpw.pixelRangeAddition == truthConfig.pixelRangeAdditionX
     c1dpw.yRange is None