예제 #1
0
class MultiPlottingContextTest(unittest.TestCase):
    def setUp(self):
        self.context = PlottingContext()

    def test_add_line_1(self):
        specNum = 4
        ws = mock.MagicMock()
        # add mock subplot
        subplot = mock.MagicMock()
        self.subplot = mock.create_autospec(subplotContext)
        with mock.patch(
                "MultiPlotting.subplot.subplot_context.subplotContext.addLine"
        ) as patch:
            self.context.addSubplot("one", subplot)
            self.context.addLine("one", ws, specNum)
            self.assertEquals(patch.call_count, 1)
            patch.assert_called_with(ws, specNum)

    def test_add_line_2(self):
        specNum = 4
        mockWS = mock.MagicMock()
        ws = gen_ws(mockWS)
        # add mock subplot
        subplot = mock.MagicMock()
        self.subplot = mock.create_autospec(subplotContext)
        with mock.patch(
                "MultiPlotting.subplot.subplot_context.subplotContext.addLine"
        ) as patch:
            self.context.addSubplot("one", subplot)
            self.context.addLine("one", ws, specNum)
            self.assertEquals(patch.call_count, 1)
            patch.assert_called_with(mockWS, specNum)
예제 #2
0
 def setUp(self):
     context = PlottingContext()
     self.subplot = subplot(context)
     self.subplot.canvas.draw = mock.MagicMock()
예제 #3
0
 def setUp(self):
     context = PlottingContext()
     self.widget = MultiPlotWidget(context)
예제 #4
0
 def setUp(self):
     self._qapp = mock_widget.mockQapp()
     context = PlottingContext()
     self.subplot = subplot(context)
     self.subplot.canvas.draw = mock.MagicMock()
예제 #5
0
 def setUp(self):
     self.context = PlottingContext()
예제 #6
0
class MultiPlottingContextTest(unittest.TestCase):
    def setUp(self):
        self.context = PlottingContext()

    def test_add_line_1(self):
        spec_num = 4
        ws = mock.MagicMock()
        # add mock subplot
        subplot = mock.MagicMock()
        self.subplot = mock.create_autospec(subplotContext)
        with mock.patch(
                "MultiPlotting.subplot.subplot_context.subplotContext.addLine"
        ) as patch:
            self.context.addSubplot("one", subplot)
            self.context.addLine("one", ws, spec_num, 'C0')
            self.assertEqual(patch.call_count, 1)
            patch.assert_called_with(ws, spec_num, color='C0')

    def test_add_line_2(self):
        spec_num = 4
        mock_ws = mock.MagicMock()
        ws = gen_ws(mock_ws)
        # add mock subplot
        subplot = mock.MagicMock()
        self.subplot = mock.create_autospec(subplotContext)
        with mock.patch(
                "MultiPlotting.subplot.subplot_context.subplotContext.addLine"
        ) as patch:
            self.context.addSubplot("one", subplot)
            self.context.addLine("one", ws, spec_num, 'C0')
            self.assertEqual(patch.call_count, 1)
            patch.assert_called_with(mock_ws, spec_num, color='C0')

    def test_update_layout(self):
        # add mocks
        figure = mock.Mock()
        self.subplot = mock.create_autospec(subplotContext)
        names = ["one", "two", "three"]
        for name in names:
            self.context.addSubplot(name, mock.Mock())

        gridspec = mock.Mock()
        self.context._gridspec = gridspec
        with mock.patch(
                "MultiPlotting.subplot.subplot_context.subplotContext.update_gridspec"
        ) as patch:
            self.context.update_layout(figure)
            self.assertEqual(patch.call_count, 3)
            # only last iteration survives
            patch.assert_called_with(gridspec, figure, 2)

    def test_subplot_empty_true(self):
        names = ["one", "two", "three"]
        for name in names:
            self.context.addSubplot(name, mock.Mock())

        for name in names:
            self.assertEqual(self.context.is_subplot_empty(name), True)

    def test_subplot_empty_false(self):
        names = ["one", "two", "three"]

        no_lines = 1

        ws = mock.MagicMock()
        with mock.patch("mantid.plots.axesfunctions.plot") as patch:
            patch.return_value = tuple([line()])

            for name in names:
                self.context.addSubplot(name, mock.Mock())
                for k in range(0, no_lines):
                    self.context.addLine(name, ws, 1, 'C0')
                no_lines += 1

        for name in names:
            self.assertEqual(self.context.is_subplot_empty(name), False)

    def test_that_remove_line_does_nothing_if_given_bad_subplot_name(self):
        self.context.subplots = {"plot": mock.Mock()}

        self.context.remove_line("plot that does not exist", "one")

        self.assertEqual(self.context.subplots["plot"].remove_line.call_count,
                         0)
        self.assertEqual(
            self.context.subplots["plot"].redraw_annotations.call_count, 0)

    def test_that_remove_line_calls_the_correct_functions(self):
        self.context.subplots = {"plot": mock.Mock()}

        self.context.remove_line("plot", "line name")

        self.assertEqual(1,
                         self.context.subplots["plot"].removeLine.call_count)
        self.assertEqual(
            0, self.context.subplots["plot"].redraw_annotations.call_count)
        self.context.subplots["plot"].removeLine.assert_called_with(
            "line name")

    def test_that_get_lines_returns_empty_list_if_given_bad_name(self):
        self.context.subplots = {"plot": mock.Mock()}

        lines = self.context.get_lines("not a valid plot")

        self.assertEqual(lines, [])

    def test_that_get_lines_returns_correct_lines(self):
        self.context.subplots = {"plot": mock.Mock()}
        self.context.subplots["plot"].lines = ["one", "two", "three"]

        lines = self.context.get_lines("plot")

        self.assertEqual(["one", "two", "three"], lines)
예제 #7
0
 def setUp(self):
     self._qapp = mock_widget.mockQapp()
     context = PlottingContext()
     self.widget = MultiPlotWidget(context)
 def setUp(self):
     self.context = PlottingContext()
class MultiPlottingContextTest(unittest.TestCase):
    def setUp(self):
        self.context = PlottingContext()
 
    def test_add_line_1(self):
        specNum = 4
        ws = mock.MagicMock()
        # add mock subplot
        subplot = mock.MagicMock()
        self.subplot = mock.create_autospec(subplotContext)
        with mock.patch("MultiPlotting.subplot.subplot_context.subplotContext.addLine") as patch:
            self.context.addSubplot("one",subplot) 
            self.context.addLine("one",ws,specNum)
            self.assertEquals(patch.call_count,1)
            patch.assert_called_with(ws,specNum)

    def test_add_line_2(self):
        specNum = 4
        mockWS = mock.MagicMock()
        ws = gen_ws(mockWS)
        # add mock subplot
        subplot = mock.MagicMock()
        self.subplot = mock.create_autospec(subplotContext)
        with mock.patch("MultiPlotting.subplot.subplot_context.subplotContext.addLine") as patch:
            self.context.addSubplot("one",subplot) 
            self.context.addLine("one",ws,specNum)
            self.assertEquals(patch.call_count,1)
            patch.assert_called_with(mockWS,specNum)

    def test_updateLayout(self):
        # add mocks
        figure = mock.Mock()
        self.subplot = mock.create_autospec(subplotContext)
        names = ["one","two","three"]
        for name in names:
            self.context.addSubplot(name, mock.Mock())

        gridspec = mock.Mock()
        self.context._gridspec = gridspec
        with mock.patch("MultiPlotting.subplot.subplot_context.subplotContext.update_gridspec") as patch:
            self.context.update_layout(figure)
            self.assertEquals(patch.call_count,3)
            # only last iteration survives
            patch.assert_called_with(gridspec,figure,2)
예제 #10
0
class MultiPlottingContextTest(unittest.TestCase):
    def setUp(self):
        self.context = PlottingContext()

    def test_add_line_1(self):
        specNum = 4
        ws = mock.MagicMock()
        # add mock subplot
        subplot = mock.MagicMock()
        self.subplot = mock.create_autospec(subplotContext)
        with mock.patch(
                "MultiPlotting.subplot.subplot_context.subplotContext.addLine"
        ) as patch:
            self.context.addSubplot("one", subplot)
            self.context.addLine("one", ws, specNum)
            self.assertEqual(patch.call_count, 1)
            patch.assert_called_with(ws, specNum)

    def test_add_line_2(self):
        specNum = 4
        mockWS = mock.MagicMock()
        ws = gen_ws(mockWS)
        # add mock subplot
        subplot = mock.MagicMock()
        self.subplot = mock.create_autospec(subplotContext)
        with mock.patch(
                "MultiPlotting.subplot.subplot_context.subplotContext.addLine"
        ) as patch:
            self.context.addSubplot("one", subplot)
            self.context.addLine("one", ws, specNum)
            self.assertEqual(patch.call_count, 1)
            patch.assert_called_with(mockWS, specNum)

    def test_updateLayout(self):
        # add mocks
        figure = mock.Mock()
        self.subplot = mock.create_autospec(subplotContext)
        names = ["one", "two", "three"]
        for name in names:
            self.context.addSubplot(name, mock.Mock())

        gridspec = mock.Mock()
        self.context._gridspec = gridspec
        with mock.patch(
                "MultiPlotting.subplot.subplot_context.subplotContext.update_gridspec"
        ) as patch:
            self.context.update_layout(figure)
            self.assertEqual(patch.call_count, 3)
            # only last iteration survives
            patch.assert_called_with(gridspec, figure, 2)

    def test_subplotEmptyTrue(self):
        names = ["one", "two", "three"]
        for name in names:
            self.context.addSubplot(name, mock.Mock())

        for name in names:
            self.assertEqual(self.context.is_subplot_empty(name), True)

    def test_subplotEmptyFalse(self):
        names = ["one", "two", "three"]

        no_lines = 1

        ws = mock.MagicMock()
        with mock.patch("mantid.plots.plotfunctions.plot") as patch:
            patch.return_value = tuple([line()])

            for name in names:
                self.context.addSubplot(name, mock.Mock())
                for k in range(0, no_lines):
                    self.context.addLine(name, ws, 1)
                no_lines += 1

        for name in names:
            self.assertEqual(self.context.is_subplot_empty(name), False)