def test_that_updates_rows_when_triggered(self): parent_presenter = create_run_tab_presenter_mock() view = create_mock_settings_diagnostic_tab() presenter = SettingsDiagnosticPresenter(parent_presenter) presenter.set_view(view) self.assertTrue(view.update_rows.call_count == 1) presenter.on_update_rows() self.assertTrue(view.update_rows.call_count == 2)
def test_that_updates_tree_view_when_row_selection_changes(self): parent_presenter = create_run_tab_presenter_mock() view = create_mock_settings_diagnostic_tab() presenter = SettingsDiagnosticPresenter(parent_presenter) presenter.set_view(view) self.assertTrue(view.set_tree.call_count == 1) presenter.on_row_changed() self.assertTrue(view.set_tree.call_count == 2)
def setUp(self): self.parent_presenter = create_run_tab_presenter_mock(use_fake_state = False) self.parent_presenter._file_information = mock.MagicMock() self.parent_presenter._file_information.get_instrument = mock.MagicMock(return_value = SANSInstrument.LARMOR) self.view = create_mock_beam_centre_tab() self.WorkHandler = mock.MagicMock() self.BeamCentreModel = mock.MagicMock() self.SANSCentreFinder = mock.MagicMock() self.presenter = BeamCentrePresenter(self.parent_presenter, self.WorkHandler, self.BeamCentreModel, self.SANSCentreFinder)
def setUp(self): self.parent_presenter = create_run_tab_presenter_mock(use_fake_state = False) self.view = create_mock_diagnostics_tab() self.state = mock.MagicMock() self.create_state = mock.MagicMock(return_value = self.state) self.WorkHandler = mock.MagicMock() self.run_integral = mock.MagicMock() self.presenter = DiagnosticsPagePresenter(self.parent_presenter, self.WorkHandler, self.run_integral, self.create_state, SANSFacility.ISIS) self.presenter.set_view(self.view, SANSInstrument.LARMOR)
def test_catches_exception_when_cant_find_file(self): parent_presenter = create_run_tab_presenter_mock() presenter = SettingsDiagnosticPresenter(parent_presenter) view = mock.MagicMock() view.get_current_row.result = 1 presenter.set_view(view) parent_presenter.get_state_for_row = mock.MagicMock() parent_presenter.get_state_for_row.side_effect = RuntimeError('Test Error') presenter.on_row_changed() parent_presenter.display_warning_box.assert_called_once_with('Warning', 'Unable to find files.', 'Test Error')
def test_that_sets_table_when_row_changes(self): # Arrange parent_presenter = create_run_tab_presenter_mock(use_fake_state=False) view = create_mock_masking_table() presenter = MaskingTablePresenter(parent_presenter) # Act + Assert presenter.set_view(view) self.assertTrue(view.set_table.call_count == 1) presenter.on_row_changed() self.assertTrue(view.set_table.call_count == 2) first_call = mock.call([]) second_call = mock.call([masking_information(first='Beam stop', second='', third='infinite-cylinder, r = 10.0'), masking_information(first='Corners', second='', third='infinite-cylinder, r = 20.0')]) # noqa view.set_table.assert_has_calls([first_call, second_call])
def test_that_checks_display_mask_is_reenabled_after_error(self): # Arrange parent_presenter = create_run_tab_presenter_mock(use_fake_state=False) presenter = MaskingTablePresenter(parent_presenter) presenter.on_processing_error_masking_display = mock.MagicMock() presenter._view = mock.MagicMock() presenter._view.set_display_mask_button_to_processing = mock.MagicMock() presenter._view.get_current_row.side_effect = RuntimeError("Mock get_current_row failure") try: presenter.on_display() except Exception as e: self.assertEqual(str(e), "Mock get_current_row failure") else: self.assertFalse(True) # As we expect an error to be raised # Confirm that on_processing_error_masking_display was called self.assertEqual( presenter.on_processing_error_masking_display.call_count, 1, "Expected on_processing_error_masking_display to have been called. Called {} times.".format( presenter.on_processing_error_masking_display.call_count))
def test_that_can_save_out_state(self): # Arrange parent_presenter = create_run_tab_presenter_mock() view = create_mock_settings_diagnostic_tab() dummy_file_path = os.path.join(tempfile.gettempdir(), "sans_settings_diag_test.json") print(dummy_file_path) view.get_save_location = mock.MagicMock(return_value=dummy_file_path) presenter = SettingsDiagnosticPresenter(parent_presenter) presenter.set_view(view) # Act presenter.on_save_state() # Assert self.assertTrue(os.path.exists(dummy_file_path)) with open(dummy_file_path) as f: data = json.load(f) self.assertTrue(data == "dummy_state") if os.path.exists(dummy_file_path): os.remove(dummy_file_path)
def test_that_can_get_state_for_index(self): parent_presenter = create_run_tab_presenter_mock() presenter = MaskingTablePresenter(parent_presenter) state = presenter.get_state(3) self.assertTrue(isinstance(state, FakeState))