Пример #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_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)
Пример #3
0
def MakeCurrent(figure_number=None):
    GlobalFigureManager.set_figure_as_current(figure_number)
Пример #4
0
def MakeCurrent(figure_number=None):
    GlobalFigureManager.set_figure_as_current(figure_number)