def _make_presenter(self): self.view = self._make_mock_view() parent_view = self._make_mock_parent_view() presenter = AddRunsPagePresenter(mock.Mock(), self.view, parent_view) presenter._get_filename_manager = mock.Mock( return_value=MockedOutAddRunsFilenameManager()) return presenter
def test_shows_error_when_empty_default_directory(self, _): view = self._make_mock_view() presenter = AddRunsPagePresenter(mock.MagicMock(), view, mock.Mock()) presenter.save_directory = "" view.sum.emit() view.no_save_directory.assert_any_call()
def _make_presenter(self): presenter = AddRunsPagePresenter(mock.Mock(), self._capture_on_change_callback(self.run_selector_presenter), self._just_use_summation_settings_presenter(), self._view, self._parent_view) presenter._get_filename_manager = mock.Mock(return_value=MockedOutAddRunsFilenameManager()) return presenter
def _make_presenter(self, run_summation, run_selection, summation_settings): presenter = AddRunsPagePresenter(run_summation, run_selection, summation_settings, self.view, self.parent_view) presenter._get_filename_manager = mock.Mock( return_value=MockedOutAddRunsFilenameManager()) return presenter
def _make_presenter(self): presenter = AddRunsPagePresenter( self._make_mock_run_summation(), self._capture_on_change_callback(self.run_selector_presenter), self._just_use_summation_settings_presenter(), self.view, self.parent_view) presenter._get_filename_manager = mock.Mock( return_value=MockedOutAddRunsFilenameManager()) return presenter
def _make_presenter(self, run_summation, run_selection, summation_settings): presenter = AddRunsPagePresenter(run_summation, run_selection, summation_settings, self.view, self.parent_view) presenter._get_filename_manager = mock.Mock(return_value=MockedOutAddRunsFilenameManager()) return presenter
def test_creates_run_selector_summation_model_with_child_view(self, patched_presenter, patched_model): view = self._make_mock_view() parent_view = self._make_mock_parent_view() AddRunsPagePresenter(sum_runs_model=mock.Mock(), view=view, parent_view=parent_view) patched_model.assert_called_once_with(mock.ANY) patched_presenter.assert_called_once_with(patched_model.return_value, mock.ANY, view)
class AddRunsDefaultSettingsTest(unittest.TestCase): def setUp(self): mock_parent_view = mock.Mock() mock_parent_view.instrument = SANSInstrument.LOQ self.presenter = AddRunsPagePresenter(parent_view=mock_parent_view, sum_runs_model=mock.Mock(), view=mock.Mock()) def test_that_presenter_calls_properties_handler_to_update_directory_on_directory_changed( self): new_dir_name = os.path.join("some", "dir", "path") self.presenter._view.display_save_directory_box = mock.Mock( return_value=new_dir_name) self.presenter.gui_properties_handler.set_setting = mock.Mock() self.presenter.set_output_directory = mock.Mock() self.presenter._handle_output_directory_changed() self.presenter.gui_properties_handler.set_setting.assert_called_once_with( "add_runs_output_directory", new_dir_name + os.sep) self.presenter.set_output_directory.assert_called_once_with( new_dir_name + os.sep) def test_that_if_output_directory_is_empty_default_save_directory_is_used_instead( self): default_dir = os.path.join("default", "save", "directory") ConfigService["defaultsave.directory"] = default_dir # ConfigService may do some conversion in the background. default_dir = ConfigService["defaultsave.directory"] output_dir = self.presenter.set_output_directory("") ConfigService["defaultsave.directory"] = "" self.assertEqual( output_dir, default_dir, "Because directory input was an empty string, we expected the output directory " "to use the default save directory {} instead. " "Directory actually used was {}".format(default_dir, output_dir)) self.assertEqual(self.presenter.save_directory, default_dir) def test_that_if_output_directory_is_not_empty_it_is_used(self): dir = os.path.join("a", "save", "directory") output_dir = self.presenter.set_output_directory(dir) self.assertEqual(output_dir, dir) self.assertEqual(self.presenter.save_directory, dir)
def test_passes_correct_config_when_summation_requested(self, patched_run_selector): # Ensure we know the type that was returned by the constructor run_selector_mock = mock.Mock() patched_run_selector.return_value = run_selector_mock ConfigService["defaultsave.directory"] = "someDir/" run_summation = mock.Mock() presenter = AddRunsPagePresenter(run_summation, self.view, self.parent_view) presenter._get_filename_manager = mock.Mock(return_value=MockedOutAddRunsFilenameManager()) mocked_run_selector = mock.MagicMock() mocked_run_selector.has_any_runs.return_value = True run_number_mock = mock.Mock() run_number_mock.display_name.return_value = 3 mocked_run_selector.__iter__.return_value = [run_number_mock] run_selector_mock.run_selection.return_value = mocked_run_selector self.view.sum.emit() run_summation.assert_called_with(mock.ANY, mock.ANY, 'LOQ00003-add')
class AddRunsDefaultSettingsTest(unittest.TestCase): def setUp(self): self.presenter = AddRunsPagePresenter(mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock()) def test_that_presenter_calls_properties_handler_to_update_directory_on_directory_changed(self): new_dir_name = os.path.join("some", "dir", "path") self.presenter._view.display_save_directory_box = mock.Mock(return_value=new_dir_name) self.presenter.gui_properties_handler.set_setting = mock.Mock() self.presenter.set_output_directory = mock.Mock() self.presenter._handle_output_directory_changed() self.presenter.gui_properties_handler.set_setting.assert_called_once_with("add_runs_output_directory", new_dir_name + os.sep) self.presenter.set_output_directory.assert_called_once_with(new_dir_name + os.sep) def test_that_if_output_directory_is_empty_default_save_directory_is_used_instead(self): default_dir = os.path.join("default", "save", "directory") ConfigService["defaultsave.directory"] = default_dir output_dir = self.presenter.set_output_directory("") ConfigService["defaultsave.directory"] = "" self.assertEqual(output_dir, default_dir, "Because directory input was an empty string, we expected the output directory " "to use the default save directory {} instead. " "Directory actually used was {}".format(default_dir, output_dir)) self.assertEqual(self.presenter.save_directory, default_dir) def test_that_if_output_directory_is_not_empty_it_is_used(self): dir = os.path.join("a", "save", "directory") output_dir = self.presenter.set_output_directory(dir) self.assertEqual(output_dir, dir) self.assertEqual(self.presenter.save_directory, dir)
def setUp(self): mock_parent_view = mock.Mock() mock_parent_view.instrument = SANSInstrument.LOQ self.presenter = AddRunsPagePresenter(parent_view=mock_parent_view, sum_runs_model=mock.Mock(), view=mock.Mock())
def _make_presenter(self, run_summation, run_selection, summation_settings): return AddRunsPagePresenter(run_summation, run_selection, summation_settings, self.view, self.parent_view)
def _make_presenter_with_child_presenters(self, run_selection, summation_settings): return AddRunsPagePresenter(self.run_summation, run_selection, summation_settings, self.view, None)
def setUp(self): self.presenter = AddRunsPagePresenter(mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock())
def _make_presenter(self, run_summation): return AddRunsPagePresenter( run_summation, self._capture_on_change_callback(self.run_selector_presenter), self._just_use_summation_settings_presenter(), self.view, self.parent_view)
def _make_presenter(self): return AddRunsPagePresenter( self._make_mock_run_summation(), self._capture_on_change_callback(self.run_selector_presenter), self._just_use_summation_settings_presenter(), self.view, None)
def setUp(self): self.presenter = AddRunsPagePresenter(mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock())
def _make_presenter(self): presenter = AddRunsPagePresenter(self._make_mock_run_summation(), self.view, self.parent_view) presenter._get_filename_manager = mock.Mock( return_value=MockedOutAddRunsFilenameManager()) return presenter