def test_changing_context_sequence(task_view, windows): """Test changing the context of a sequence. This should trigger a new validation of the driver. """ show_widget(task_view) task = task_view.task task.selected_instrument = ("p", "ecpy_pulses.TestDriver", "c", "s") task.sequence.context = None assert task.selected_instrument[0] task.selected_instrument = ("p", "__dummy__", "c", "s") with handle_question("yes"): task.sequence.context = TestContext() assert not task.selected_instrument[0] # Test changing the sequence. task.selected_instrument = ("p", "__dummy__", "c", "s") with handle_question("yes"): task.sequence = sequence() assert not task.selected_instrument[0] # Check the observer has been installed on the new sequence. task.selected_instrument = ("p", "ecpy_pulses.TestDriver", "c", "s") task.sequence.context = None assert task.selected_instrument[0] task.selected_instrument = ("p", "__dummy__", "c", "s") with handle_question("yes"): task.sequence.context = TestContext() assert not task.selected_instrument[0]
def test_pulse_view(windows, workbench, process_and_sleep): """Test the view of the Pulse class. """ from ecpy.testing.util import show_widget with enaml.imports(): from ecpy_pulses.pulses.sequences.views.base_sequences_views\ import RootSequenceView pulse = Pulse(root=RootSequence(context=TestContext())) 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(root_view) process_and_sleep() # Test selecting a slope shape shape_select = pulse_view.widgets()[-1].widgets()[-1] shape_select.selected = 'ecpy_pulses.SlopeShape' process_and_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 process_and_sleep() assert sv_widgets[2].text == mode.split('/')[0] assert sv_widgets[4].text == mode.split('/')[1]
def test_changing_context_sequence(task_view, windows): """Test changing the context of a sequence. This should trigger a new validation of the driver. """ show_widget(task_view) task = task_view.task task.selected_instrument = ('p', 'ecpy_pulses.TestDriver', 'c', 's') task.sequence.context = None assert task.selected_instrument[0] task.selected_instrument = ('p', '__dummy__', 'c', 's') with handle_question('yes'): task.sequence.context = TestContext() assert not task.selected_instrument[0] # Test changing the sequence. task.selected_instrument = ('p', '__dummy__', 'c', 's') with handle_question('yes'): task.sequence = sequence() assert not task.selected_instrument[0] # Check the observer has been installed on the new sequence. task.selected_instrument = ('p', 'ecpy_pulses.TestDriver', 'c', 's') task.sequence.context = None assert task.selected_instrument[0] task.selected_instrument = ('p', '__dummy__', 'c', 's') with handle_question('yes'): task.sequence.context = TestContext() assert not task.selected_instrument[0]
def test_visa_raw(windows): """Test the raw visa connection used for aliases or unsupported resources. """ c = VisaRaw() show_widget(c) c.widgets()[1].text = 'dummy' assert c.gather_infos() == {'resource_name': 'dummy'}
def test_sequence_config_view(windows): """Test the view of the base config. """ w = SequenceConfigView(model=SequenceConfig(sequence_doc='test',)) show_widget(w) w.widgets()[1].text = 'test' process_app_events() assert w.model.ready
def test_abstract_refresh(windows): """Test the refresh function of the abstract view. """ view = AbstractSequenceView(item=BaseSequence()) show_widget(view) view.hide() view.refresh() assert view.visible
def test_base_sequence_refresh(windows): """Test the refresh function of the base sequence view. """ view = BaseSequenceView(item=BaseSequence()) show_widget(view) view.hide() view.refresh() assert view.visible
def test_sequence_config_view(windows): """Test the view of the base config. """ w = SequenceConfigView(model=SequenceConfig(sequence_doc='test', )) show_widget(w) w.widgets()[1].text = 'test' process_app_events() assert w.model.ready
def test_view_changing_interface(self, windows, 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(view) selector = view.widgets()[2] selector.selected = selector.items[1] process_app_events() selector.selected = selector.items[0] process_app_events()
def test_visa_rs232(windows): """Test the rs232 visa connection. """ c = VisaRS232() show_widget(c) c.widgets()[-1].text = '1' process_app_events() assert c.gather_infos() == { 'interface_type': 'ASRL', 'resource_class': 'INSTR', 'board': '1' } assemble_canonical_name(**c.gather_infos())
def test_pulse_view(windows, workbench, pulse, process_and_sleep): """Test the view of the Pulse class. """ import enaml from ecpy.testing.util import show_widget with enaml.imports(): from ecpy_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(root_view) process_and_sleep() # Test swithcing between logical and analogical widgets_num = len(pulse_view.widgets()) pulse.kind = 'Logical' process_and_sleep() process_and_sleep() assert widgets_num - 1 == len(pulse_view.widgets()) pulse.kind = 'Analogical' process_and_sleep() assert widgets_num == len(pulse_view.widgets()) # Test selecting a shape shape_select = pulse_view.widgets()[-1].widgets()[-1] shape_select.selected = 'ecpy_pulses.SquareShape' process_and_sleep() assert widgets_num + 1 == len(pulse_view.widgets()) shape_select.selected = '' process_and_sleep() assert widgets_num == len(pulse_view.widgets()) # Test adding a modulation mod_check = pulse_view.widgets()[-1].widgets()[0] mod_check.checked = True process_and_sleep() assert widgets_num + 1 == len(pulse_view.widgets()) mod_check.checked = False process_and_sleep() assert widgets_num == len(pulse_view.widgets())
def test_root_sequence_view(windows, workbench): """Test the root sequence view. """ core = workbench.get_plugin('enaml.workbench.core') view = RootSequenceView(item=RootSequence(), core=core) show_widget(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('reject'): but.clicked = True
def test_loop_config_with_subtask(task_workbench, windows, dialog_sleep, monkeypatch): """Test the loop config. """ plugin = task_workbench.get_plugin('ecpy.tasks') config = LoopTaskConfig(manager=plugin, task_class=plugin.get_task('ecpy.LoopTask'), task_name='Test') show_widget(LoopConfigView(config=config)) assert config.ready sleep(dialog_sleep) config.use_subtask = True assert not config.ready process_app_events() sleep(dialog_sleep) config.subtask = 'ecpy.BreakTask' assert config.ready process_app_events() sleep(dialog_sleep) 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 process_app_events() sleep(dialog_sleep) config.use_subtask = False assert config.ready process_app_events() sleep(dialog_sleep) config.use_subtask = True config.subtask = 'ecpy.ContinueTask' task = config.build_task() assert task.name == 'Bis' assert type(task.task).__name__ == 'ContinueTask'
def test_visa_tcpip_instr(windows): """Test the visa tcpip connection. """ c = VisaTCPIP() show_widget(c) c.widgets()[-4].text = '192.168.0.10' process_app_events() c.widgets()[-1].checked = True process_app_events() assert c.gather_infos() == { 'interface_type': 'TCPIP', 'resource_class': 'INSTR', 'host_address': '192.168.0.10', 'lan_device_name': 'inst0', 'board': '0' } assemble_canonical_name(**c.gather_infos())
def test_visa_GPIB(windows): """Test the GPIB visa connection. """ c = VisaGPIB() show_widget(c) c.widgets()[-2].text = '1' process_app_events() c.widgets()[-1].checked = True process_app_events() assert c.gather_infos() == { 'interface_type': 'GPIB', 'resource_class': 'INSTR', 'board': '0', 'primary_address': '1', 'secondary_address': '0' } assemble_canonical_name(**c.gather_infos())
def test_creating_a_visa_connection(prof_plugin, windows, caplog): """Test creating a Visa connection through VisaConnection.new """ c = prof_plugin.create_connection('VisaTCPIP', {'__junk': ''}, True) w = show_widget(c) assert caplog.records assert c.read_only w.close
def test_root_view(windows, 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(view) sleep(dialog_sleep) assert editor.task is task assert editor.root is view TASK_NAME = 'Foo' def answer_dialog(dial): selector = dial.selector selector.selected_task = 'ecpy.ComplexTask' dial.config.task_name = TASK_NAME process_app_events() with handle_dialog('accept', answer_dialog, cls=BuilderView): editor._empty_button.clicked = True process_app_events() assert task.children assert type(task.children[0]) is ComplexTask assert len(editor._children_buttons) == 1 sleep(dialog_sleep) TASK_NAME = 'Bar' with handle_dialog('accept', answer_dialog, cls=BuilderView): editor.operations['add'](0, 'after') process_app_events() sleep(dialog_sleep) task.children[0].add_child_task(0, ComplexTask(name='Test')) get_window().maximize() process_app_events() sleep(dialog_sleep) editor.operations['move'](0, 1) process_app_events() sleep(dialog_sleep) task.remove_child_task(1) process_app_events() sleep(dialog_sleep) assert len(view._cache) == 2 editor.operations['remove'](0) process_app_events() sleep(dialog_sleep) assert len(view._cache) == 1 win.close()
def test_sequence_replacement(editor, task, windows, process_and_sleep): """Test replacing the sequence (a priori not possible). """ editor.selected_task = task show_widget(editor) root_view = editor.page_widget().widgets()[0].scroll_widget().widgets()[0] old = root_view.additional_pages[0] seq = task.sequence task.sequence = sequence() process_and_sleep() task.sequence = seq process_and_sleep() root_view = editor.page_widget().widgets()[0].scroll_widget().widgets()[0] new = root_view.additional_pages[0] assert old is not new
def test_load_refresh_save2(task_view, monkeypatch, process_and_sleep, windows): """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(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 ecpy_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('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_sequence_replacement(editor, task, windows, process_and_sleep): """Test replacing the sequence (a priori not possible). """ editor.selected_task = task show_widget(editor) root_view = editor.page_widget().widgets()[0].scroll_widget().widgets()[0] old = root_view.additional_pages[0] seq = task.sequence task.sequence = sequence() process_and_sleep() task.sequence = seq process_and_sleep() root_view = editor.page_widget().widgets()[0].scroll_widget().widgets()[0] process_and_sleep() new = root_view.additional_pages[0] assert old is not new
def test_visa_tcpip_socket(windows, process_and_sleep): """Test the visa tcpip connection. """ c = VisaTCPIP() show_widget(c) c.resource_class = 'SOCKET' process_and_sleep() c.widgets()[-4].text = '192.168.0.10' c.widgets()[-2].text = '10000' process_app_events() c.widgets()[-1].checked = True process_app_events() assert c.gather_infos() == { 'interface_type': 'TCPIP', 'resource_class': 'SOCKET', 'host_address': '192.168.0.10', 'port': '10000', 'board': '0' } assemble_canonical_name(**c.gather_infos())
def test_visa_usb(windows): """ Test the visa usb connection. """ c = VisaUSB() show_widget(c) c.widgets()[-6].text = '0x00' c.widgets()[-4].text = '0x01' c.widgets()[-2].text = '0x02' process_app_events() c.widgets()[-1].checked = True process_app_events() 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' } assemble_canonical_name(**c.gather_infos())
def test_loop_config_with_subtask(task_workbench, windows, dialog_sleep): """Test the loop config. """ plugin = task_workbench.get_plugin('ecpy.tasks') config = LoopTaskConfig(manager=plugin, task_class=plugin.get_task('ecpy.LoopTask'), task_name='Test') show_widget(LoopConfigView(config=config)) assert config.ready sleep(dialog_sleep) config.use_subtask = True assert not config.ready process_app_events() sleep(dialog_sleep) config.subtask = 'ecpy.BreakTask' assert config.ready process_app_events() sleep(dialog_sleep) config.subconfig.task_name = '' assert not config.ready process_app_events() sleep(dialog_sleep) config.use_subtask = False assert config.ready process_app_events() sleep(dialog_sleep) config.use_subtask = True config.subtask = 'ecpy.ContinueTask' task = config.build_task() assert task.name == 'Test' assert type(task.task).__name__ == 'ContinueTask'
def test_root_view(windows, 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[0] win = show_widget(view) sleep(dialog_sleep) assert editor.task is task assert editor.root is view TASK_NAME = 'Foo' def answer_dialog(dial): selector = dial.selector selector.selected_task = 'ecpy.ComplexTask' dial.config.task_name = TASK_NAME process_app_events() with handle_dialog('accept', answer_dialog, cls=BuilderView): editor._empty_button.clicked = True process_app_events() assert task.children assert type(task.children[0]) is ComplexTask assert len(editor._children_buttons) == 1 sleep(dialog_sleep) TASK_NAME = 'Bar' with handle_dialog('accept', answer_dialog, cls=BuilderView): editor.operations['add'](0, 'after') process_app_events() sleep(dialog_sleep) task.children[0].add_child_task(0, ComplexTask(name='Test')) get_window().maximize() process_app_events() sleep(dialog_sleep) editor.operations['move'](0, 1) task.children[1].remove_child_task(0) assert len(view._cache) == 3 editor.operations['remove'](0) assert len(view._cache) == 2 win.close()
def test_loop_config_with_subtask(task_workbench, windows, dialog_sleep): """Test the loop config. """ plugin = task_workbench.get_plugin("ecpy.tasks") config = LoopTaskConfig(manager=plugin, task_class=plugin.get_task("ecpy.LoopTask"), task_name="Test") show_widget(LoopConfigView(config=config)) assert config.ready sleep(dialog_sleep) config.use_subtask = True assert not config.ready process_app_events() sleep(dialog_sleep) config.subtask = "ecpy.BreakTask" assert config.ready process_app_events() sleep(dialog_sleep) config.subconfig.task_name = "" assert not config.ready process_app_events() sleep(dialog_sleep) config.use_subtask = False assert config.ready process_app_events() sleep(dialog_sleep) config.use_subtask = True config.subtask = "ecpy.ContinueTask" task = config.build_task() assert task.name == "Test" assert type(task.task).__name__ == "ContinueTask"
def test_swapping(windows, 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(cont) view.set_parent(cont) view.refresh() process_app_events() assert cont.children == [view] sleep(dialog_sleep) view.set_parent(None) subview.set_parent(cont) subview.refresh() process_app_events() assert cont.children == [subview] sleep(dialog_sleep) subview.set_parent(None) view.set_parent(cont) view.refresh() process_app_events() assert cont.children == [view] assert subview.visible sleep(dialog_sleep)
def test_save_view(windows, process_and_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(view) process_and_sleep() d_editor = view.widgets()[-1] d_editor._model.add_pair(0) process_and_sleep() win.close()
def test_sequence_vars_update(measure_workbench, editor, task, process_and_sleep, windows): """Test that when unselecting the editor we properly synchronize the vars. """ task.sequence_vars = {'a': '1.5', 'b': '2'} win = show_widget(editor) editor.selected_task = task process_and_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(measure_workbench) assert task.sequence_vars == {'a': '1.5', 'c': ''}
def test_view(self, windows, root_view, task_workbench, process_and_sleep): """Intantiate a view with no selected interface and select one after """ view = LoadArrayView(task=self.task, root=root_view) win = show_widget(view) process_and_sleep() assert self.task.interface is None assert "CSV" in view.file_formats self.task.selected_format = "CSV" process_and_sleep() assert isinstance(self.task.interface, CSVLoadInterface) win.close()
def test_view2(self, windows, root_view, task_workbench, process_and_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(view) process_and_sleep() assert self.task.interface is interface win.close()
def test_sequence_vars_update(measure_workbench, editor, task, process_and_sleep, windows): """Test that when unselecting the editor we properly synchronize the vars. """ task.sequence_vars = OrderedDict({'a': '1.5', 'b': '2'}) win = show_widget(editor) editor.selected_task = task process_and_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(measure_workbench) assert task.sequence_vars == OrderedDict([('a', '1.5'), ('c', '')]) win.close()
def test_load_refresh_save(task_view, monkeypatch, process_and_sleep, windows): """Test loading a sequence, refreshing, modifying and saving. """ from enaml.widgets.api import FileDialogEx @classmethod def get_filename(cls, parent, 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(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 = {"a": "1*23", "c": "1"} # Load task_view.widgets()[2].clicked = True process_and_sleep() assert task_view.task.sequence is not old_seq assert task_view.task.sequence_vars == {"a": "1*23"} assert not task_view.widgets()[4].style_class old_seq = task_view.task.sequence task_view.task.sequence_vars = {} # Refresh with handle_question("no"): task_view.widgets()[4].clicked = True assert task_view.task.sequence is old_seq with handle_question("yes"): task_view.widgets()[4].clicked = True assert task_view.task.sequence is not old_seq assert task_view.task.sequence_vars == {"a": ""} old_timestamp = task_view.task.sequence_timestamp # Save btn = task_view.widgets()[5] actions = btn.menu().items() with handle_question("no"): btn.clicked = True actions[0].triggered = True assert task_view.task.sequence_timestamp == old_timestamp with handle_question("yes"): btn.clicked = True actions[0].triggered = True assert task_view.task.sequence_timestamp != old_timestamp @classmethod def get_save_filename1(cls, parent, path, name_filters): return "" new_path = task_view.task.sequence_path.rstrip(".pulse.ini") new_path += "2" @classmethod def get_save_filename2(cls, parent, 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_load_refresh_save(task_view, monkeypatch, process_and_sleep, windows): """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(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 process_and_sleep() 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 old_seq = task_view.task.sequence task_view.task.sequence_vars = OrderedDict() # Refresh with handle_question('no'): task_view.widgets()[4].clicked = True assert task_view.task.sequence is old_seq with handle_question('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('no'): btn.clicked = True actions[0].triggered = True assert task_view.task.sequence_timestamp == old_timestamp with handle_question('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'