コード例 #1
0
    def test_make_current_with_single_category(self, mock_figure_class):
        mock_figures = [mock.Mock(), mock.Mock()]
        # These manager is used to compare the relative order of calls of two different functions
        mock_managers = [mock.Mock(), mock.Mock()]

        for i in range(len(mock_figures)):
            mock_managers[i].attach_mock(mock_figures[i].flag_as_kept, 'fig_kept')
            mock_managers[i].attach_mock(mock_figures[i].flag_as_current, 'fig_current')
        mock_figure_class.side_effect = mock_figures
        cat1 = '1d'
        cat1_get_active_figure = set_category(cat1)(GlobalFigureManager.get_active_figure)
        # test is an arbitrary method just to make sure the correct figures are returned

        cat1_get_active_figure().test(1)  # create a figure of category 1
        GlobalFigureManager.set_figure_as_kept(1)  # now there is no active figure
        cat1_get_active_figure().test(2)  # this command should go to a new figure

        self.assertTrue(mock_managers[0].mock_calls[-1] == call.fig_kept())     # assert fig1 now displays kept
        self.assertTrue(mock_managers[1].mock_calls[-1] == call.fig_current())  # assert fig2 now displays current

        GlobalFigureManager.set_figure_as_current(1)
        self.assertTrue(mock_managers[0].mock_calls[-1] == call.fig_current())     # assert fig1 now displays current
        self.assertTrue(mock_managers[1].mock_calls[-1] == call.fig_kept())        # assert fig2 now displays kept

        cat1_get_active_figure().test(3)                # This should go to fig1
        GlobalFigureManager.get_active_figure().test(4)       # This should go to fig1 as well

        mock_figures[0].test.assert_has_calls([call(1), call(3), call(4)])
        mock_figures[1].test.assert_has_calls([call(2)])

        self.assertTrue(GlobalFigureManager._active_figure == 1)
コード例 #2
0
    def test_categorizing_of_uncategorized_plot(self, mock_figure_class):
        mock_figures = [mock.Mock(), mock.Mock(), mock.Mock()]
        fig1_mock_manager = mock.Mock()
        # This manager is used to compare the relative order of calls of two differebc functions
        fig1_mock_manager.attach_mock(mock_figures[0].flag_as_kept, 'fig1_kept')
        fig1_mock_manager.attach_mock(mock_figures[0].flag_as_current, 'fig1_current')
        mock_figure_class.side_effect = mock_figures
        cat1 = '1d'
        cat2 = '2d'
        cat1_get_active_figure = set_category(cat1)(GlobalFigureManager.get_active_figure)
        cat2_get_active_figure = set_category(cat2)(GlobalFigureManager.get_active_figure)

        # test is an arbitrary method just to make sure the correct figures are returned

        cat1_get_active_figure().test(1)  # create a figure of category 1
        cat2_get_active_figure().test(2)  # create a figure of category 2
        GlobalFigureManager.set_figure_as_kept(2) # now there is no active figure

        GlobalFigureManager.get_active_figure().test(3) # create an uncategorized figure
        cat1_get_active_figure().test(4) # the previously uncategorized figure should now be categorized as cat1

        mock_figures[0].test.assert_has_calls([call(1)])
        mock_figures[1].test.assert_has_calls([call(2)])
        mock_figures[2].test.assert_has_calls([call(3), call(4)])

        self.assertTrue(fig1_mock_manager.mock_calls[-1] == call.fig1_kept())  # assert final status of fig1 is kept
        self.assertTrue(GlobalFigureManager._active_figure == 3)
コード例 #3
0
    def test_make_current_with_single_category(self, mock_figure_class):
        mock_figures = [mock.Mock(), mock.Mock()]
        # These manager is used to compare the relative order of calls of two different functions
        mock_managers = [mock.Mock(), mock.Mock()]

        for i in range(len(mock_figures)):
            mock_managers[i].attach_mock(mock_figures[i].flag_as_kept,
                                         'fig_kept')
            mock_managers[i].attach_mock(mock_figures[i].flag_as_current,
                                         'fig_current')
        mock_figure_class.side_effect = mock_figures
        cat1 = '1d'
        cat1_get_active_figure = set_category(cat1)(
            GlobalFigureManager.get_active_figure)
        # test is an arbitrary method just to make sure the correct figures are returned

        cat1_get_active_figure().test(1)  # create a figure of category 1
        GlobalFigureManager.set_figure_as_kept(
            1)  # now there is no active figure
        cat1_get_active_figure().test(
            2)  # this command should go to a new figure

        self.assertTrue(mock_managers[0].mock_calls[-1] ==
                        call.fig_kept())  # assert fig1 now displays kept
        self.assertTrue(mock_managers[1].mock_calls[-1] ==
                        call.fig_current())  # assert fig2 now displays current

        GlobalFigureManager.set_figure_as_current(1)
        self.assertTrue(mock_managers[0].mock_calls[-1] ==
                        call.fig_current())  # assert fig1 now displays current
        self.assertTrue(mock_managers[1].mock_calls[-1] ==
                        call.fig_kept())  # assert fig2 now displays kept

        cat1_get_active_figure().test(3)  # This should go to fig1
        GlobalFigureManager.get_active_figure().test(
            4)  # This should go to fig1 as well

        mock_figures[0].test.assert_has_calls([call(1), call(3), call(4)])
        mock_figures[1].test.assert_has_calls([call(2)])

        self.assertTrue(GlobalFigureManager._active_figure == 1)
コード例 #4
0
    def test_categorizing_of_uncategorized_plot(self, mock_figure_class):
        mock_figures = [mock.Mock(), mock.Mock(), mock.Mock()]
        fig1_mock_manager = mock.Mock()
        # This manager is used to compare the relative order of calls of two differebc functions
        fig1_mock_manager.attach_mock(mock_figures[0].flag_as_kept,
                                      'fig1_kept')
        fig1_mock_manager.attach_mock(mock_figures[0].flag_as_current,
                                      'fig1_current')
        mock_figure_class.side_effect = mock_figures
        cat1 = '1d'
        cat2 = '2d'
        cat1_get_active_figure = set_category(cat1)(
            GlobalFigureManager.get_active_figure)
        cat2_get_active_figure = set_category(cat2)(
            GlobalFigureManager.get_active_figure)

        # test is an arbitrary method just to make sure the correct figures are returned

        cat1_get_active_figure().test(1)  # create a figure of category 1
        cat2_get_active_figure().test(2)  # create a figure of category 2
        GlobalFigureManager.set_figure_as_kept(
            2)  # now there is no active figure

        GlobalFigureManager.get_active_figure().test(
            3)  # create an uncategorized figure
        cat1_get_active_figure().test(
            4
        )  # the previously uncategorized figure should now be categorized as cat1

        mock_figures[0].test.assert_has_calls([call(1)])
        mock_figures[1].test.assert_has_calls([call(2)])
        mock_figures[2].test.assert_has_calls([call(3), call(4)])

        self.assertTrue(
            fig1_mock_manager.mock_calls[-1] ==
            call.fig1_kept())  # assert final status of fig1 is kept
        self.assertTrue(GlobalFigureManager._active_figure == 3)
コード例 #5
0
def KeepFigure(figure_number=None):
    GlobalFigureManager.set_figure_as_kept(figure_number)
コード例 #6
0
def KeepFigure(figure_number=None):
    GlobalFigureManager.set_figure_as_kept(figure_number)