def test_remove_phasequad_button_selected_rows(self): phasequad_1 = MuonPhasequad("test_1", "table") phasequad_2 = MuonPhasequad("test_2", "table") phasequad_3 = MuonPhasequad("test_3", "table") self.view.num_rows = mock.Mock(return_value=3) self.view.get_table_item_text = mock.Mock(return_value="test") self.view.get_selected_phasequad_names_and_indexes = mock.Mock( return_value=[("test_1", 0), ("test_2", 1)]) self.view.remove_phasequad_by_index = mock.Mock() self.presenter.add_phasequad_to_analysis = mock.Mock() self.presenter.calculation_finished_notifier = mock.Mock() self.presenter.context.group_pair_context._phasequad = [ phasequad_1, phasequad_2, phasequad_3 ] self.presenter.handle_remove_phasequad_button_clicked() self.assertEqual( 1, len(self.presenter.context.group_pair_context.phasequads)) self.view.remove_phasequad_by_index.assert_any_call(0) self.view.remove_phasequad_by_index.assert_any_call(1) self.presenter.add_phasequad_to_analysis.assert_any_call( False, False, phasequad_1) self.presenter.add_phasequad_to_analysis.assert_any_call( False, False, phasequad_2) self.assertEqual( 2, self.presenter.calculation_finished_notifier.notify_subscribers. call_count)
def test_update_rebin(self): phasequad = MuonPhasequad("test", "table") Re = mock.Mock() Im = mock.Mock() phasequad._Re.update_asymmetry_workspace = mock.Mock() phasequad._Im.update_asymmetry_workspace = mock.Mock() phasequad.update_asymmetry_workspaces([Re, Im], 42, True) phasequad._Re.update_asymmetry_workspace.assert_called_once_with( Re, 42, rebin=True) phasequad._Im.update_asymmetry_workspace.assert_called_once_with( Im, 42, rebin=True)
def test_rm_phasequad(self): phasequad = MuonPhasequad("test", "table") phasequad2 = MuonPhasequad("test2", "table2") self.context.add_phasequad(phasequad) self.context.add_phasequad(phasequad2) self.assertEqual(len(self.context._phasequad), 2) self.assertEqual(len(self.context._pairs), 4) self.context.remove_phasequad(phasequad) self.assertEqual(len(self.context._phasequad), 1) self.assertEqual(len(self.context._pairs), 2) self.assertEqual(self.context._phasequad[0].name, "test2") self.assertEqual(self.context._pairs[0].name, "test2_Re_") self.assertEqual(self.context._pairs[1].name, "test2_Im_")
def test_calculate_phasequad_rebin_deadtime(self, crop_mock, split_mock, run_mock): table = "test_table" self.context._run_deadtime = mock.Mock(side_effect=run_side_effect) self.context.data_context._current_runs = [5234] phasequad = MuonPhasequad("test", table) run_mock.side_effect = run_side_effect self.context._run_rebin = mock.Mock(side_effect=rebin_side_effect) split_mock.side_effect = return_list crop_mock.side_effect = crop_side_effect self.set_up_phasequad_rebin_mock() result = self.context.calculate_phasequad(phasequad, 5234, True) # names are wrong due to split mock name = "EMU5234; PhaseQuad; test_Re__Im_; Rebin; MA" self.assertEqual(result, [name + "1", name + "2"]) self.context._run_rebin.assert_called_with(name, True) run_mock.assert_called_with( { "PhaseTable": table, 'InputWorkspace': name }, name) split_mock.assert_called_with(name) crop_mock.assert_called_with(name, 0.0, 0.0) self.context._get_bin_width.assert_called_once_with(name) self.context._average_by_bin_widths.assert_called_once_with(name, 0.1)
def test_add_phasequad(self): phasequad = MuonPhasequad("test", "table") self.assertEqual(len(self.context._phasequad), 0) self.assertEqual(len(self.context._pairs), 0) self.context.add_phasequad(phasequad) self.assertEqual(len(self.context._phasequad), 1) self.assertEqual(len(self.context._pairs), 2) self.assertEqual(self.context._phasequad[0].name, "test") self.assertEqual(self.context._pairs[0].name, "test_Re_") self.assertEqual(self.context._pairs[1].name, "test_Im_")
def test_update_phasequads(self): phasequad = MuonPhasequad("test", "test_table") self.context.group_pair_context.add_phasequad(phasequad) self.context._calculate_phasequads = mock.Mock() self.assertEqual(["long", "test_Re_", "test_Im_"], self.context.group_pair_context.pair_names) self.assertEqual("test", self.context.group_pair_context._phasequad[0].name) self.assertEqual(1, len(self.context.group_pair_context._phasequad)) self.context.update_phasequads() self.assertEqual(["long", "test_Re_", "test_Im_"], self.context.group_pair_context.pair_names) self.assertEqual("test", self.context.group_pair_context._phasequad[0].name) self.assertEqual(1, len(self.context.group_pair_context._phasequad)) self.assertEqual(1, self.context._calculate_phasequads.call_count)
def test_remove_phasequad_button_last_row(self): phasequad = MuonPhasequad("test", "table") self.view.num_rows = mock.Mock(return_value=1) self.view.get_table_item_text = mock.Mock(return_value="test") self.view.get_selected_phasequad_names_and_indexes = mock.Mock( return_value=None) self.view.get_table_contents = mock.Mock(return_value=["test"]) self.view.remove_last_row = mock.Mock() self.presenter.add_phasequad_to_analysis = mock.Mock() self.presenter.calculation_finished_notifier = mock.Mock() self.presenter.context.group_pair_context._phasequad = [phasequad] self.presenter.handle_remove_phasequad_button_clicked() self.assertEqual( 0, len(self.presenter.context.group_pair_context.phasequads)) self.presenter.add_phasequad_to_analysis.assert_called_once_with( False, False, phasequad) self.presenter.calculation_finished_notifier.notify_subscribers.assert_called_once_with( )
def test_calculate_phasequad(self): self.presenter.phasequad_calculation_complete_notifier = mock.Mock() self.presenter.phasequad_calculation_complete_notifier.notify_subscribers = mock.Mock( ) self.context.group_pair_context.add_phasequad = mock.Mock() self.context.calculate_phasequads = mock.Mock() phasequad = MuonPhasequad("test", "table") self.presenter._phasequad_obj = phasequad self.presenter.calculate_phasequad() self.context.group_pair_context.add_phasequad.assert_called_once_with( phasequad) self.context.calculate_phasequads.assert_called_once_with(phasequad) self.presenter.phasequad_calculation_complete_notifier.notify_subscribers.assert_any_call( phasequad.Re.name) self.presenter.phasequad_calculation_complete_notifier.notify_subscribers.assert_any_call( phasequad.Im.name) self.assertEqual( self.presenter.phasequad_calculation_complete_notifier. notify_subscribers.call_count, 2)
def handle_add_phasequad_button_clicked(self): """When the + button is pressed, calculate a new phasequad from the currently selected table""" if self.view.number_of_phase_tables < 1: self.view.warning_popup("Please generate a phase table first.") return self.update_model_from_view() name = self.view.enter_phasequad_name() if name is None: return elif self.validate_phasequad_name(name): table = self.context.phase_context.options_dict[ 'phase_table_for_phase_quad'] self._phasequad_obj = MuonPhasequad(str(name), table) self.phasequad_calculation_thread = self.create_phasequad_calculation_thread( ) self.phasequad_calculation_thread.threadWrapperSetUp( self.handle_phasequad_calculation_started, self.handle_phasequad_calculation_success, self.handle_phasequad_calculation_error) self.phasequad_calculation_thread.start()
def test_phasequad_success(self): self.context.group_pair_context.add_pair_to_selected_pairs = mock.Mock( ) self.presenter.selected_phasequad_changed_notifier = mock.Mock() self.presenter.calculation_finished_notifier = mock.Mock() self.presenter.handle_thread_calculation_success = mock.Mock() self.context.group_pair_context.add_pair_to_selected_pairs = mock.Mock( ) self.presenter.selected_phasequad_changed_notifier.notify_subscribers = mock.Mock( ) self.presenter._phasequad_obj = MuonPhasequad("test", "table") self.presenter.handle_phasequad_calculation_success() self.context.group_pair_context.add_pair_to_selected_pairs.assert_any_call( "test_Re_") self.context.group_pair_context.add_pair_to_selected_pairs.assert_any_call( "test_Im_") self.presenter.selected_phasequad_changed_notifier.notify_subscribers.assert_not_called( ) self.presenter.calculation_finished_notifier.notify_subscribers.assert_called_once_with( ) self.presenter.handle_thread_calculation_success.assert_called_once_with( )
def test_phase_table_swap(self): phasequad = MuonPhasequad("test", "table") self.assertEqual(phasequad.phase_table, "table") phasequad.phase_table = "new" self.assertEqual(phasequad.phase_table, "new")
def test_phase_table(self): phasequad = MuonPhasequad("test", "table") self.assertEqual(phasequad.phase_table, "table")
def test_create_base_pairs(self): phasequad = MuonPhasequad("test", "table") self.assertEqual(phasequad.Re.name, "test_Re_") self.assertEqual(phasequad.Im.name, "test_Im_")
def test_name(self): phasequad = MuonPhasequad("test", "table") self.assertEqual(phasequad.name, "test")