def test_pulse_view(workbench, exopy_qtbot, dialog_sleep): """Test the view of the Pulse class. """ from exopy.testing.util import show_widget with enaml.imports(): from exopy_pulses.pulses.sequences.views.base_sequences_views\ import RootSequenceView pulse = Pulse(root=RootSequence(context=DummyContext())) pulse.kind = 'Analogical' root = pulse.root root.add_child_item(0, pulse) core = workbench.get_plugin('enaml.workbench.core') root_view = RootSequenceView(item=root, core=core) pulse_view = root_view.view_for(pulse) show_widget(exopy_qtbot, root_view) exopy_qtbot.wait(dialog_sleep) # Test selecting a slope shape shape_select = pulse_view.widgets()[-1].widgets()[-1] shape_select.selected = 'exopy_pulses.SlopeShape' exopy_qtbot.wait(10 + dialog_sleep) shape_view = pulse_view.widgets()[-1] sv_widgets = shape_view.split_items()[0].split_widget().widgets() for mode in ('Start/Stop', 'Start/Slope', 'Slope/Stop'): sv_widgets[1].selected = mode def assert_mode(): assert sv_widgets[2].text == mode.split('/')[0] assert sv_widgets[4].text == mode.split('/')[1] exopy_qtbot.wait_until(assert_mode)
def test_changing_context_sequence(task_view, exopy_qtbot): """Test changing the context of a sequence. This should trigger a new validation of the driver. """ show_widget(exopy_qtbot, task_view) task = task_view.task task.selected_instrument = ('p', 'exopy_pulses.TestDriver', 'c', 's') task.sequence.context = None assert task.selected_instrument[0] task.selected_instrument = ('p', '__dummy__', 'c', 's') with handle_question(exopy_qtbot, 'yes'): task.sequence.context = DummyContext() assert not task.selected_instrument[0] # Test changing the sequence. task.selected_instrument = ('p', '__dummy__', 'c', 's') with handle_question(exopy_qtbot, 'yes'): task.sequence = sequence() assert not task.selected_instrument[0] # Check the observer has been installed on the new sequence. task.selected_instrument = ('p', 'exopy_pulses.TestDriver', 'c', 's') task.sequence.context = None assert task.selected_instrument[0] task.selected_instrument = ('p', '__dummy__', 'c', 's') with handle_question(exopy_qtbot, 'yes'): task.sequence.context = DummyContext() assert not task.selected_instrument[0]
def test_visa_usb(exopy_qtbot): """ Test the visa usb connection. """ c = VisaUSB() show_widget(exopy_qtbot, c) c.widgets()[-6].text = '0x00' c.widgets()[-4].text = '0x01' c.widgets()[-2].text = '0x02' exopy_qtbot.wait(10) c.widgets()[-1].checked = True def assert_infos(): assert c.gather_infos() == { 'interface_type': 'USB', 'resource_class': 'INSTR', 'manufacturer_id': '0x00', 'model_code': '0x01', 'serial_number': '0x02', 'usb_interface_number': '0', 'board': '0' } exopy_qtbot.wait_until(assert_infos) assemble_canonical_name(**c.gather_infos())
def test_visa_raw(exopy_qtbot): """Test the raw visa connection used for aliases or unsupported resources. """ c = VisaRaw() show_widget(exopy_qtbot, c) c.widgets()[1].text = 'dummy' assert c.gather_infos() == {'resource_name': 'dummy'}
def test_base_sequence_refresh(exopy_qtbot): """Test the refresh function of the base sequence view. """ view = BaseSequenceView(item=BaseSequence()) show_widget(exopy_qtbot, view) view.hide() view.refresh() assert view.visible
def test_abstract_refresh(exopy_qtbot): """Test the refresh function of the abstract view. """ view = AbstractSequenceView(item=BaseSequence()) show_widget(exopy_qtbot, view) view.hide() view.refresh() assert view.visible
def test_sequence_config_view(exopy_qtbot): """Test the view of the base config. """ w = SequenceConfigView(model=SequenceConfig(sequence_doc='test', )) show_widget(exopy_qtbot, w) w.widgets()[1].text = 'test' def assert_ready(): assert w.model.ready exopy_qtbot.wait_until(assert_ready)
def test_visa_rs232(exopy_qtbot): """Test the rs232 visa connection. """ c = VisaRS232() show_widget(exopy_qtbot, c) c.widgets()[-1].text = '1' def assert_infos(): assert c.gather_infos() == {'interface_type': 'ASRL', 'resource_class': 'INSTR', 'board': '1'} exopy_qtbot.wait_until(assert_infos) assemble_canonical_name(**c.gather_infos())
def test_root_sequence_view(exopy_qtbot, workbench): """Test the root sequence view. """ core = workbench.get_plugin('enaml.workbench.core') view = RootSequenceView(item=RootSequence(), core=core) show_widget(exopy_qtbot, view) seq = BaseSequence() view.item.add_child_item(0, seq) assert seq in view._cache view.item.remove_child_item(0) assert seq not in view._cache but = view.widgets()[-1].pages()[1].page_widget().widgets()[0] with handle_dialog(exopy_qtbot, 'reject'): but.clicked = True
def test_swapping(exopy_qtbot, task_workbench, dialog_sleep): """Test moving a view between containers. """ task = RootTask() view = RootTaskView(task=task, core=task_workbench.get_plugin('enaml.workbench.core')) subtask = ComplexTask(name='Test') subview = view.view_for(subtask) task.add_child_task(0, subtask) cont = Container() show_widget(exopy_qtbot, cont) view.set_parent(cont) view.refresh() def assert_children(): assert cont.children == [view] exopy_qtbot.wait_until(assert_children) exopy_qtbot.wait(dialog_sleep) view.set_parent(None) subview.set_parent(cont) subview.refresh() def assert_children(): assert cont.children == [subview] exopy_qtbot.wait_until(assert_children) exopy_qtbot.wait(dialog_sleep) subview.set_parent(None) view.set_parent(cont) view.refresh() def assert_children(): assert cont.children == [view] exopy_qtbot.wait_until(assert_children) assert subview.visible exopy_qtbot.wait(dialog_sleep)
def test_visa_tcpip_instr(exopy_qtbot): """Test the visa tcpip connection. """ c = VisaTCPIP() show_widget(exopy_qtbot, c) c.widgets()[-4].text = '192.168.0.10' exopy_qtbot.wait(10) c.widgets()[-1].checked = True def assert_infos(): assert c.gather_infos() == {'interface_type': 'TCPIP', 'resource_class': 'INSTR', 'host_address': '192.168.0.10', 'lan_device_name': 'inst0', 'board': '0'} exopy_qtbot.wait_until(assert_infos) assemble_canonical_name(**c.gather_infos())
def test_visa_GPIB(exopy_qtbot): """Test the GPIB visa connection. """ c = VisaGPIB() show_widget(exopy_qtbot, c) c.widgets()[-2].text = '1' exopy_qtbot.wait(10) c.widgets()[-1].checked = True def assert_infos(): assert c.gather_infos() == {'interface_type': 'GPIB', 'resource_class': 'INSTR', 'board': '0', 'primary_address': '1', 'secondary_address': '0'} exopy_qtbot.wait_until(assert_infos) assemble_canonical_name(**c.gather_infos())
def test_creating_a_visa_connection(prof_plugin, exopy_qtbot, caplog): """Test creating a Visa connection through VisaConnection.new """ c = prof_plugin.create_connection('VisaTCPIP', {'__junk': ''}, True) w = show_widget(exopy_qtbot, c) assert caplog.records assert c.read_only w.close() wait_for_destruction(exopy_qtbot, w)
def test_loop_config_with_subtask(task_workbench, exopy_qtbot, dialog_sleep, monkeypatch): """Test the loop config. """ plugin = task_workbench.get_plugin('exopy.tasks') config = LoopTaskConfig(manager=plugin, task_class=plugin.get_task('exopy.LoopTask'), future_parent=RootTask(), task_name='Test') show_widget(exopy_qtbot, LoopConfigView(config=config)) assert config.ready exopy_qtbot.wait(dialog_sleep) config.use_subtask = True assert not config.ready exopy_qtbot.wait(dialog_sleep + 100) config.subtask = 'exopy.BreakTask' assert config.ready exopy_qtbot.wait(dialog_sleep + 100) def dummy(self): self.ready = False monkeypatch.setattr(type(config.subconfig), 'check_parameters', dummy) config.task_name = 'Bis' assert config.subconfig.task_name == 'Bis' # Check sync assert not config.ready # Result from the monkeypatch exopy_qtbot.wait(dialog_sleep + 100) config.use_subtask = False assert config.ready exopy_qtbot.wait(dialog_sleep + 100) config.use_subtask = True config.subtask = 'exopy.ContinueTask' task = config.build_task() assert task.name == 'Bis' assert type(task.task).__name__ == 'ContinueTask'
def test_load_refresh_save2(task_view, monkeypatch, exopy_qtbot): """Test loading a sequence, refreshing, modifying and saving. Test handling the case of an empty sequence_path """ from enaml.widgets.api import FileDialogEx @classmethod def get_filename(cls, parent, current_path, name_filters): return task_view.task.sequence_path monkeypatch.setattr(FileDialogEx, 'get_open_file_name', get_filename) task_view.task.sequence_path = '' show_widget(exopy_qtbot, task_view) task_view.task.sequence_vars = OrderedDict() # Refresh button = task_view.widgets()[4] assert not button.enabled def false_load(*args, **kwargs): raise Exception() with enaml.imports(): from exopy_pulses.tasks.tasks.instrs.views\ import transfer_sequence_task_view old = transfer_sequence_task_view.load_sequence monkeypatch.setattr(transfer_sequence_task_view, 'load_sequence', false_load) with handle_question(exopy_qtbot, 'OK'): button.clicked = True monkeypatch.setattr(transfer_sequence_task_view, 'load_sequence', old) # Save btn = task_view.widgets()[5] actions = btn.menu().items() assert not actions[0].enabled
def test_visa_tcpip_socket(exopy_qtbot, dialog_sleep): """Test the visa tcpip connection. """ c = VisaTCPIP() show_widget(exopy_qtbot, c) c.resource_class = 'SOCKET' exopy_qtbot.wait(10 + dialog_sleep) c.widgets()[-4].text = '192.168.0.10' c.widgets()[-2].text = '10000' exopy_qtbot.wait(10) c.widgets()[-1].checked = True def assert_infos(): assert c.gather_infos() == {'interface_type': 'TCPIP', 'resource_class': 'SOCKET', 'host_address': '192.168.0.10', 'port': '10000', 'board': '0'} exopy_qtbot.wait_until(assert_infos) assemble_canonical_name(**c.gather_infos())
def test_sequence_replacement(editor, task, exopy_qtbot, dialog_sleep): """Test replacing the sequence (a priori not possible). """ editor.selected_task = task show_widget(exopy_qtbot, editor) root_view = editor.page_widget().widgets()[0].scroll_widget().widgets()[0] old = root_view.additional_pages[0] seq = task.sequence task.sequence = sequence() exopy_qtbot.wait(10 + dialog_sleep) task.sequence = seq exopy_qtbot.wait(10 + dialog_sleep) root_view = editor.page_widget().widgets()[0].scroll_widget().widgets()[0] exopy_qtbot.wait(10 + dialog_sleep) new = root_view.additional_pages[0] assert old is not new
def test_view_changing_interface(self, exopy_qtbot, task_workbench): """Test the LoopTask view. """ core = task_workbench.get_plugin('enaml.workbench.core') root = RootTaskView(core=core) view = LoopView(task=self.task, root=root) show_widget(exopy_qtbot, view) selector = view.widgets()[2] current_interface = view.task.interface selector.selected = selector.items[1] def assert_interface_changed(): assert view.task.interface is not current_interface exopy_qtbot.wait_until(assert_interface_changed) current_interface = view.task.interface selector.selected = selector.items[0] def assert_interface_changed(): assert view.task.interface is not current_interface exopy_qtbot.wait_until(assert_interface_changed)
def test_save_view(exopy_qtbot, dialog_sleep, root_view): """Test SaveView widget. """ task = SaveTask(name='Test') root_view.task.add_child_task(0, task) view = SaveView(task=task, root=root_view) win = show_widget(exopy_qtbot, view) exopy_qtbot.wait(dialog_sleep) d_editor = view.widgets()[-1] d_editor._model.add_pair(0) exopy_qtbot.wait(dialog_sleep) win.close()
def test_validating_connection_default(id, defaults, should_log, exopy_qtbot, caplog, prof_plugin): """Test that keyword filtering works as expected. """ caplog.set_level(logging.INFO) c = prof_plugin.create_connection(id, defaults, False) w = show_widget(exopy_qtbot, c) if should_log: assert caplog.records else: assert not caplog.records assert not c.read_only w.close() wait_for_destruction(exopy_qtbot, w)
def test_view(self, exopy_qtbot, root_view, task_workbench, dialog_sleep): """Intantiate a view with no selected interface and select one after """ view = LoadArrayView(task=self.task, root=root_view) win = show_widget(exopy_qtbot, view) exopy_qtbot.wait(dialog_sleep) assert self.task.interface is None assert 'CSV' in view.file_formats self.task.selected_format = 'CSV' exopy_qtbot.wait(dialog_sleep) assert isinstance(self.task.interface, CSVLoadInterface) win.close()
def test_view2(self, exopy_qtbot, root_view, task_workbench, dialog_sleep): """Intantiate a view with a selected interface. """ interface = CSVLoadInterface() self.task.interface = interface self.task.selected_format = 'CSV' interface = self.task.interface view = LoadArrayView(task=self.task, root=root_view) win = show_widget(exopy_qtbot, view) exopy_qtbot.wait(dialog_sleep) assert self.task.interface is interface win.close()
def test_sequence_vars_update(measurement_workbench, editor, task, exopy_qtbot, dialog_sleep): """Test that when unselecting the editor we properly synchronize the vars. """ task.sequence_vars = OrderedDict({'a': '1.5', 'b': '2'}) win = show_widget(exopy_qtbot, editor) editor.selected_task = task exopy_qtbot.wait(10 + dialog_sleep) root_view = editor.page_widget().widgets()[0].scroll_widget().widgets()[0] vars_editor = root_view.additional_pages[0] vars_editor.page_widget().widgets()[0].text = 'a, c' editor.react_to_unselection(measurement_workbench) assert task.sequence_vars == OrderedDict([('a', '1.5'), ('c', '')]) win.close()
def test_root_view(exopy_qtbot, task_workbench, dialog_sleep): """Test the behavior of the root task view. """ task = RootTask() view = RootTaskView(task=task, core=task_workbench.get_plugin('enaml.workbench.core')) editor = view.children[-1] win = show_widget(exopy_qtbot, view) exopy_qtbot.wait(dialog_sleep) assert editor.task is task assert editor.root is view TASK_NAME = 'Foo' def answer_dialog(bot, dial): selector = dial.selector selector.selected_task = 'exopy.ComplexTask' dial.config.task_name = TASK_NAME with handle_dialog(exopy_qtbot, 'accept', answer_dialog, cls=BuilderView): editor._empty_button.clicked = True def assert_task_children(): assert task.children exopy_qtbot.wait_until(assert_task_children) assert type(task.children[0]) is ComplexTask assert len(editor._children_buttons) == 1 exopy_qtbot.wait(dialog_sleep) TASK_NAME = 'Bar' with handle_dialog(exopy_qtbot, 'accept', answer_dialog, cls=BuilderView): editor.operations['add'](0, 'after') exopy_qtbot.wait(10) exopy_qtbot.wait(dialog_sleep) task.children[0].add_child_task(0, ComplexTask(name='Test')) get_window(exopy_qtbot).maximize() exopy_qtbot.wait(10) exopy_qtbot.wait(dialog_sleep) editor.operations['move'](0, 1) exopy_qtbot.wait(10) exopy_qtbot.wait(dialog_sleep) task.remove_child_task(1) exopy_qtbot.wait(10) exopy_qtbot.wait(dialog_sleep) assert len(view._cache) == 2 # Test removing the last child and removing a view for an already removed # task child_task = task.children[0] editor.operations['remove'](0) exopy_qtbot.wait(10) exopy_qtbot.wait(dialog_sleep) assert len(view._cache) == 1 view.discard_view(child_task) win.close()
def test_load_refresh_save(task_view, monkeypatch, exopy_qtbot, dialog_sleep): """Test loading a sequence, refreshing, modifying and saving. """ from enaml.widgets.api import FileDialogEx @classmethod def get_filename(cls, parent, current_path, name_filters): return task_view.task.sequence_path monkeypatch.setattr(FileDialogEx, 'get_open_file_name', get_filename) task_view.task.sequence_timestamp = -1 show_widget(exopy_qtbot, task_view) # Check detection of outdated sequence assert task_view.widgets()[4].style_class old_seq = task_view.task.sequence task_view.task.sequence_vars = OrderedDict([('a', '1*23'), ('c', '1')]) # Load task_view.widgets()[2].clicked = True def assert_exec(): assert task_view.task.sequence is not old_seq assert task_view.task.sequence_vars == OrderedDict({'a': '1*23'}) assert not task_view.widgets()[4].style_class exopy_qtbot.wait_until(assert_exec) old_seq = task_view.task.sequence task_view.task.sequence_vars = OrderedDict() # Refresh with handle_question(exopy_qtbot, 'no'): task_view.widgets()[4].clicked = True assert task_view.task.sequence is old_seq with handle_question(exopy_qtbot, 'yes'): task_view.widgets()[4].clicked = True assert task_view.task.sequence is not old_seq assert task_view.task.sequence_vars == OrderedDict({'a': ''}) old_timestamp = task_view.task.sequence_timestamp # Save btn = task_view.widgets()[5] actions = btn.menu().items() with handle_question(exopy_qtbot, 'no'): btn.clicked = True actions[0].triggered = True assert task_view.task.sequence_timestamp == old_timestamp with handle_question(exopy_qtbot, 'yes'): btn.clicked = True actions[0].triggered = True sleep(0.1) assert task_view.task.sequence_timestamp != old_timestamp @classmethod def get_save_filename1(cls, parent, current_path, name_filters): return '' new_path = task_view.task.sequence_path.rstrip('.pulse.ini') new_path += '2' @classmethod def get_save_filename2(cls, parent, current_path, name_filters): return new_path old_timestamp = task_view.task.sequence_timestamp # Save as monkeypatch.setattr(FileDialogEx, 'get_save_file_name', get_save_filename1) btn.clicked = True actions[1].triggered = True assert task_view.task.sequence_timestamp == old_timestamp monkeypatch.setattr(FileDialogEx, 'get_save_file_name', get_save_filename2) btn.clicked = True actions[1].triggered = True assert task_view.task.sequence_timestamp != old_timestamp assert task_view.task.sequence_path == new_path + '.pulse.ini'
def test_pulse_view(exopy_qtbot, workbench, pulse, dialog_sleep): """Test the view of the Pulse class. """ import enaml from exopy.testing.util import show_widget with enaml.imports(): from exopy_pulses.pulses.sequences.views.base_sequences_views\ import RootSequenceView pulse.kind = 'Analogical' root = pulse.root root.add_child_item(0, pulse) core = workbench.get_plugin('enaml.workbench.core') root_view = RootSequenceView(item=root, core=core) pulse_view = root_view.view_for(pulse) show_widget(exopy_qtbot, root_view) exopy_qtbot.wait(dialog_sleep) # Test swithcing between logical and analogical widgets_num = len(pulse_view.widgets()) pulse.kind = 'Logical' def assert_widgets(): assert widgets_num - 1 == len(pulse_view.widgets()) exopy_qtbot.wait_until(assert_widgets) exopy_qtbot.wait(dialog_sleep) pulse.kind = 'Analogical' def assert_widgets(): assert widgets_num == len(pulse_view.widgets()) exopy_qtbot.wait_until(assert_widgets) exopy_qtbot.wait(dialog_sleep) # Test selecting a shape shape_select = pulse_view.widgets()[-1].widgets()[-1] shape_select.selected = 'exopy_pulses.SquareShape' def assert_widgets(): assert widgets_num + 1 == len(pulse_view.widgets()) exopy_qtbot.wait_until(assert_widgets) exopy_qtbot.wait(dialog_sleep) shape_select.selected = '' def assert_widgets(): assert widgets_num == len(pulse_view.widgets()) exopy_qtbot.wait_until(assert_widgets) exopy_qtbot.wait(dialog_sleep) # Test adding a modulation mod_check = pulse_view.widgets()[-1].widgets()[0] mod_check.checked = True def assert_widgets(): assert widgets_num + 1 == len(pulse_view.widgets()) exopy_qtbot.wait_until(assert_widgets) exopy_qtbot.wait(dialog_sleep) mod_check.checked = False def assert_widgets(): assert widgets_num == len(pulse_view.widgets()) exopy_qtbot.wait_until(assert_widgets) exopy_qtbot.wait(dialog_sleep)