def test_browing_dialog_profiles_add(prof_plugin, process_and_sleep): """Test the browsing dialog page dedicated to explore the profiles. """ d = BrowsingDialog(plugin=prof_plugin) nb = d.central_widget().widgets()[0] nb.selected_tab = 'profiles' d.show() process_and_sleep() btn = nb.pages()[0].page_widget().widgets()[-3] origin = prof_plugin.profiles[:] with handle_dialog('reject', cls=ProfileEditionDialog): btn.clicked = True assert prof_plugin.profiles == origin def handle(dial): assert dial.creation dial.profile_infos.id = 'test' dial.profile_infos.model = prof_plugin._profiles['fp1'].model with handle_dialog('accept', handle, cls=ProfileEditionDialog): btn.clicked = True # Wait for file notification to be treated sleep(1.0) process_app_events() assert 'test' in prof_plugin.profiles assert os.path.isfile( os.path.join(prof_plugin._profiles_folders[0], 'test.instr.ini'))
def test_create_context(workbench, root, windows): """Test creating a context for a sequence. """ core = workbench.get_plugin('enaml.workbench.core') def select_context(dial): """Select the sequence to build. """ obj_combo = dial.central_widget().widgets()[0] obj_combo.selected_item = 'ecpy_pulses.TestContext' with handle_dialog('accept', select_context): cmd = 'ecpy.pulses.create_context' core.invoke_command(cmd, dict(root=root)) assert root.context is not None del root.context with handle_dialog('reject'): cmd = 'ecpy.pulses.create_context' core.invoke_command(cmd, dict(root=root)) assert root.context is None
def test_create_context(workbench, root, windows): """Test creating a context for a sequence. """ core = workbench.get_plugin('enaml.workbench.core') def select_context(dial): """Select the sequence to build. """ obj_combo = dial.central_widget().widgets()[0] obj_combo.selected_item = 'Test' with handle_dialog('accept', select_context): cmd = 'ecpy.pulses.create_context' core.invoke_command(cmd, dict(root=root)) assert root.context is not None del root.context with handle_dialog('reject'): cmd = 'ecpy.pulses.create_context' core.invoke_command(cmd, dict(root=root)) assert root.context is None
def test_create_sequence(root, workbench, windows, monkeypatch): """Test creating a sequence. """ core = workbench.get_plugin('enaml.workbench.core') def select_sequence(dial): """Select the sequence to build. """ dial.selector.selected_sequence = 'ecpy_pulses.BaseSequence' with handle_dialog('accept', select_sequence): cmd = 'ecpy.pulses.create_sequence' seq = core.invoke_command(cmd, dict(root=root)) assert seq is not None with handle_dialog('reject'): cmd = 'ecpy.pulses.create_sequence' seq = core.invoke_command(cmd, dict(root=root)) assert seq is None def raise_on_build(*args, **kwargs): raise Exception() from ecpy_pulses.pulses.configs.base_config import SequenceConfig monkeypatch.setattr(SequenceConfig, 'build_sequence', raise_on_build) with handle_dialog('accept', cls=ErrorsDialog, time=500): with handle_dialog('accept', cls=BuilderView): cmd = 'ecpy.pulses.create_sequence' seq = core.invoke_command(cmd, dict(root=root))
def test_create_sequence(root, workbench, windows, monkeypatch): """Test creating a sequence. """ core = workbench.get_plugin('enaml.workbench.core') def select_sequence(dial): """Select the sequence to build. """ dial.selector.selected_sequence = 'ecpy_pulses.BaseSequence' with handle_dialog('accept', select_sequence): cmd = 'ecpy.pulses.create_sequence' seq = core.invoke_command(cmd, dict(root=root)) assert seq is not None with handle_dialog('reject'): cmd = 'ecpy.pulses.create_sequence' seq = core.invoke_command(cmd, dict(root=root)) assert seq is None def raise_on_build(*args, **kwargs): raise Exception from ecpy_pulses.pulses.configs.base_config import SequenceConfig monkeypatch.setattr(SequenceConfig, 'build_sequence', raise_on_build) with handle_dialog('accept', cls=BasicErrorsDisplay): with handle_dialog('reject', cls=BuilderView): cmd = 'ecpy.pulses.create_sequence' seq = core.invoke_command(cmd, dict(root=root))
def test_browing_dialog_profiles_add(prof_plugin, process_and_sleep): """Test the browsing dialog page dedicated to explore the profiles. """ d = BrowsingDialog(plugin=prof_plugin) nb = d.central_widget().widgets()[0] nb.selected_tab = "profiles" d.show() process_and_sleep() btn = nb.pages()[1].page_widget().widgets()[-2] origin = prof_plugin.profiles[:] with handle_dialog("reject", cls=ProfileEditionDialog): btn.clicked = True assert prof_plugin.profiles == origin def handle(dial): assert dial.creation dial.profile_infos.id = "test" dial.profile_infos.model = prof_plugin._profiles["fp1"].model with handle_dialog("accept", handle, cls=ProfileEditionDialog): btn.clicked = True # Wait for file notification to be treated sleep(1.0) process_app_events() assert "test" in prof_plugin.profiles assert os.path.isfile(os.path.join(prof_plugin._profiles_folders[0], "test.instr.ini"))
def test_browing_dialog_profiles_edit(prof_plugin, process_and_sleep): """Test the browsing dialog page dedicated to explore the profiles. """ d = BrowsingDialog(plugin=prof_plugin) nb = d.central_widget().widgets()[0] nb.selected_tab = "profiles" d.show() process_and_sleep() c = nb.pages()[1].page_widget() btn = c.widgets()[-1] c.p_id = "fp1" manu = prof_plugin._manufacturers._manufacturers["Dummy"] model = manu._series["dumb"]._models["002"] def handle(dial): dial.profile_infos.model = model with handle_dialog("reject", handle, cls=ProfileEditionDialog): btn.clicked = True assert prof_plugin._profiles["fp1"].model != model def handle(dial): assert not dial.creation dial.profile_infos.model = model dial.central_widget().widgets()[0].sync() with handle_dialog("accept", handle, cls=ProfileEditionDialog): btn.clicked = True assert prof_plugin._profiles["fp1"].model == model assert ConfigObj(prof_plugin._profiles["fp1"].path)["model_id"] == "Dummy.dumb.002"
def test_browing_dialog_profiles_delete(prof_plugin, process_and_sleep): """Test the browsing dialog page dedicated to explore the profiles. """ d = BrowsingDialog(plugin=prof_plugin) nb = d.central_widget().widgets()[0] nb.selected_tab = 'profiles' d.show() process_and_sleep() c = nb.pages()[0].page_widget() btn = c.widgets()[-1] c.p_id = 'fp1' print(prof_plugin._profiles) with handle_dialog('reject', cls=MessageBox): btn.clicked = True assert 'fp1' in prof_plugin._profiles def handle(dial): dial.buttons[0].was_clicked = True with handle_dialog('accept', handle, cls=MessageBox): btn.clicked = True sleep(1.0) process_app_events() assert 'fp1' not in prof_plugin._profiles
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_report_command(err_workbench, windows): """Test generating an application errors report. """ core = err_workbench.get_plugin('enaml.workbench.core') with handle_dialog(): core.invoke_command('ecpy.app.errors.report') with handle_dialog(): core.invoke_command('ecpy.app.errors.report', dict(kind='error')) with handle_dialog(): core.invoke_command('ecpy.app.errors.report', dict(kind='stupid'))
def test_report_command(workbench, windows): """Test generating an application errors report. """ core = workbench.get_plugin('enaml.workbench.core') with handle_dialog(): core.invoke_command('ecpy.app.errors.report') with handle_dialog(): core.invoke_command('ecpy.app.errors.report', dict(kind='error')) with handle_dialog(): core.invoke_command('ecpy.app.errors.report', dict(kind='stupid'))
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_handling_error_in_handlers(workbench, windows): """Test handling an error occuring in a specilaized handler. """ plugin = workbench.get_plugin(ERRORS_ID) def check_dialog(dial): assert 'error' in dial.errors assert 'registering' not in dial.errors with handle_dialog(custom=check_dialog): plugin.signal('registering') with handle_dialog(custom=check_dialog): plugin.signal('registering', msg=FailedFormat())
def test_handling_error_in_handlers(err_workbench, windows): """Test handling an error occuring in a specilaized handler. """ plugin = err_workbench.get_plugin(ERRORS_ID) def check_dialog(dial): assert 'error' in dial.errors assert 'registering' not in dial.errors with handle_dialog(custom=check_dialog): plugin.signal('registering') with handle_dialog(custom=check_dialog): plugin.signal('registering', msg=FailedFormat())
def test_view_validate_driver_context(windows, task_view): """Test the validation of a context/driver pair. """ task_view.task.selected_instrument = ("p", "ecpy_pulses.TestDriver", "c", "s") with handle_dialog("accept"): validate_context_driver_pair(task_view.root.core, task_view.task.sequence.context, task_view.task, task_view) assert task_view.task.selected_instrument[0] task_view.task.selected_instrument = ("p", "__dummy__", "c", "s") with handle_dialog("accept"): validate_context_driver_pair(task_view.root.core, task_view.task.sequence.context, task_view.task, task_view) assert not task_view.task.selected_instrument[0]
def test_signal_command_with_unknown(workbench, windows): """Test the signal command with a stupid kind of error. """ core = workbench.get_plugin('enaml.workbench.core') with handle_dialog(): core.invoke_command('ecpy.app.errors.signal', {'kind': 'stupid', 'msg': None}) with handle_dialog(): fail = FailedFormat() core.invoke_command('ecpy.app.errors.signal', {'kind': 'stupid', 'msg': fail}) assert getattr(fail, 'called', None)
def test_enqueuing_fail_reload(workspace, monkeypatch, tmpdir): """Test failing when reloading the measure after saving. """ m = workspace.plugin.edited_measures.measures[0] m.root_task.default_path = text(tmpdir) from ecpy.measure.measure import Measure witness = [] @classmethod def r(cls, measure_plugin, path, build_dep=None): witness.append(None) return None, {'r': 't'} monkeypatch.setattr(Measure, 'load', r) with handle_dialog(): workspace.enqueue_measure(m) # Check dependencies are cleaned up assert_dependencies_released(workspace, m) assert not workspace.plugin.enqueued_measures.measures assert witness
def test_enqueueing_abort_warning(workspace, monkeypatch, tmpdir): """Test aborting enqueueing because some checks raised warnings. """ m = workspace.plugin.edited_measures.measures[0] m.root_task.default_path = text(tmpdir) from ecpy.measure.measure import Measure witness = [] def check(*args, **kwargs): witness.append(None) return True, {'r': {'t': 's'}} monkeypatch.setattr(Measure, 'run_checks', check) with handle_dialog('reject'): workspace.enqueue_measure(m) # Check dependencies are cleaned up assert_dependencies_released(workspace, m) assert not workspace.plugin.enqueued_measures.measures assert witness
def test_unsatifiable_requirement(self, windows): """Test the case of a declarator always adding itself to _deflayed. """ self.workbench.register(DContributor5()) with handle_dialog(): self.workbench.get_plugin(PLUGIN_ID)
def test_declarator_failed_registration(self, windows): """Test handling of error when a declarator fail to register. """ self.workbench.register(DContributor4()) with handle_dialog(): self.workbench.get_plugin(PLUGIN_ID)
def test_save_action(workspace, measure, windows): """Test that save action calls the proper commands. """ act = SaveAction( workspace=workspace, action_context={'data': (None, None, measure.root_task, None)}) with handle_dialog('reject'): act.triggered = True class CmdException(Exception): def __init__(self, cmd, opts): self.cmd = cmd def invoke(self, cmd, opts, caller=None): raise CmdException(cmd, opts) from enaml.workbench.core.core_plugin import CorePlugin old = CorePlugin.invoke_command CorePlugin.invoke_command = invoke try: with pytest.raises(CmdException) as ex: act.triggered = True process_app_events() assert ex.value.cmd == 'ecpy.app.errors.signal' finally: CorePlugin.invoke_command = old
def test_saving_as_template(windows, tmpdir, task_workbench, task, monkeypatch): """Test saving a task as a template. """ from ecpy.tasks.utils import saving monkeypatch.setattr(saving.TemplateViewer, 'exec_', saving.TemplateViewer.show) plugin = task_workbench.get_plugin('ecpy.tasks') plugin.templates = {'test': ''} def answer_dialog(dialog): model = dialog._model model.folder = str(tmpdir) model.filename = 'test' model.doc = 'This is a test' dialog.show_result = True assert model.accept_template_info(dialog) core = task_workbench.get_plugin('enaml.workbench.core') with handle_dialog('accept', answer_dialog): core.invoke_command(CMD, dict(task=task, mode='template')) get_window(Dialog).accept() process_app_events() path = str(tmpdir.join('test.task.ini')) assert os.path.isfile(path) config = ConfigObj(path) assert config.initial_comment == ['# This is a test']
def test_app_startup4(self, tmpdir, windows): """Test app start-up when user request to reset app folder. """ manifest = PreferencesManifest() self.workbench.register(manifest) app_dir = str(tmpdir.join('ecpy')) # Add a app_directory.ini file. app_pref = os.path.join(ecpy_path(), APP_PREFERENCES, APP_DIR_CONFIG) if not os.path.isfile(app_pref): conf = ConfigObj() conf.filename = app_pref conf['app_path'] = app_dir conf.write() # Start the app and fake a user answer. app = self.workbench.get_plugin('ecpy.app') class DummyArgs(object): reset_app_folder = True with handle_dialog(custom=lambda x: setattr(x, 'path', app_dir)): app.run_app_startup(DummyArgs) assert os.path.isfile(app_pref) assert ConfigObj(app_pref)['app_path'] == app_dir assert os.path.isdir(app_dir)
def test_enqueueing_abort_warning(workspace, monkeypatch, tmpdir): """Test aborting enqueueing because some checks raised warnings. """ m = workspace.plugin.edited_measures.measures[0] m.root_task.default_path = text(tmpdir) from ecpy.measure.measure import Measure witness = [] def check(*args, **kwargs): witness.append(None) return True, {'r': {'t': 's'}} monkeypatch.setattr(Measure, 'run_checks', check) with handle_dialog('reject'): workspace.enqueue_measure(m) # Make sure runtimes are always released. m = workspace.plugin.workbench.get_manifest('test.measure') assert not m.find('runtime_dummy1').collected assert not m.find('runtime_dummy2').collected assert not workspace.plugin.enqueued_measures.measures assert witness
def test_save_action(workspace, measure, windows): """Test that save action calls the proper commands. """ act = SaveAction(workspace=workspace, action_context={'data': (None, None, measure.root_task, None)}) with handle_dialog('reject'): act.triggered = True class CmdException(Exception): def __init__(self, cmd, opts): self.cmd = cmd def invoke(self, cmd, opts, caller=None): raise CmdException(cmd, opts) from enaml.workbench.core.core_plugin import CorePlugin old = CorePlugin.invoke_command CorePlugin.invoke_command = invoke try: with pytest.raises(CmdException) as ex: act.triggered = True process_app_events() assert ex.value.cmd == 'ecpy.app.errors.signal' finally: CorePlugin.invoke_command = old
def test_enqueuing_fail_reload(workspace, monkeypatch, tmpdir): """Test failing when reloading the measure after saving. """ m = workspace.plugin.edited_measures.measures[0] m.root_task.default_path = text(tmpdir) from ecpy.measure.measure import Measure witness = [] @classmethod def r(cls, measure_plugin, path, build_dep=None): witness.append(None) return None, {'r': 't'} monkeypatch.setattr(Measure, 'load', r) with handle_dialog(): workspace.enqueue_measure(m) # Make sure runtimes are always released. m = workspace.plugin.workbench.get_manifest('test.measure') assert not m.find('runtime_dummy1').collected assert not m.find('runtime_dummy2').collected assert not workspace.plugin.enqueued_measures.measures assert witness
def test_enqueueing_after_warning(workspace, monkeypatch, tmpdir): """Test enqueueing after some checks raised warnings. """ m = workspace.plugin.edited_measures.measures[0] m.root_task.default_path = text(tmpdir) from ecpy.measure.measure import Measure witness = [] def check(*args, **kwargs): witness.append(None) return True, {'r': {'t': 's'}} monkeypatch.setattr(Measure, 'run_checks', check) with handle_dialog(): assert workspace.enqueue_measure(m) # Make sure runtimes are always released. m = workspace.plugin.workbench.get_manifest('test.measure') assert not m.find('runtime_dummy1').collected assert not m.find('runtime_dummy2').collected assert witness
def test_running_main_error_in_parser_modifying(windows, monkeypatch): """Test starting the main app but encountering an issue while adding arguments. """ import ecpy.__main__ as em def false_iter(arg): class FalseEntryPoint(EntryPoint): def load(self, *args, **kwargs): def false_modifier(parser): raise Exception('Failed to add stupid argument to parser') return (false_modifier, 1) return [FalseEntryPoint('dummy', 'dummy')] monkeypatch.setattr(em, 'iter_entry_points', false_iter) def check_dialog(dial): assert 'modifying' in dial.text with pytest.raises(SystemExit): with handle_dialog('reject', check_dialog): main([])
def test_driver_validation_error_handler(windows, instr_workbench): """Test the error handler dedicated to driver validation issues. """ core = instr_workbench.get_plugin('enaml.workbench.core') p = instr_workbench.get_plugin('ecpy.instruments') d = DriverInfos(starter='starter', connections={ 'c1': {}, 'c2': {} }, settings={ 's2': {}, 's3': {} }) cmd = 'ecpy.app.errors.signal' def check_dialog(dial): w = dial.errors['ecpy.driver-validation'] assert 'd' in w.errors for err in ('starter', 'connections', 'settings'): assert err in w.errors['d'] with handle_dialog('accept', check_dialog): core.invoke_command(cmd, { 'kind': 'ecpy.driver-validation', 'details': { 'd': d.validate(p)[1] } })
def test_rule_edition_dialog(text_monitor_workbench, dialog_sleep): """Test editing a rule using the dialog widget. """ p = text_monitor_workbench.get_plugin(PLUGIN_ID) m = p.create_monitor(False) m.handle_database_entries_change(('added', 'root/test_f', 0)) d = EditRulesView(monitor=m) d.show() process_app_events() sleep(dialog_sleep) # Create a new rule psh_btn = d.central_widget().widgets()[-4] def create(dial): dial.rule = RejectRule(id='__dummy', suffixes=['f']) with handle_dialog(custom=create, cls=CreateRuleDialog): psh_btn.clicked = True assert any([r.id == '__dummy' for r in m.rules]) assert not m.displayed_entries qlist = d.central_widget().widgets()[0] qlist.selected_item = [r for r in m.rules if r.id == '__dummy'][0] process_app_events() assert d.central_widget().widgets()[1].rule sleep(dialog_sleep) # Save rule and save and add to default try: psh_btn = d.central_widget().widgets()[-2] act = psh_btn.children[0].children[0] act.triggered = True process_app_events() assert '__dummy' in p.rules assert '__dummy' not in p.default_rules del p._user_rules['__dummy'] act = psh_btn.children[0].children[1] act.triggered = True process_app_events() assert '__dummy' in p.rules assert '__dummy' in p.default_rules finally: if '__dummy' in p._user_rules: del p._user_rules['__dummy'] # Delete rule psh_btn = d.central_widget().widgets()[-3] psh_btn.clicked = True process_app_events() assert '__dummy' not in m.rules assert m.displayed_entries d.central_widget().widgets()[-1].clicked = True process_app_events()
def test_rule_edition_dialog(text_monitor_workbench, dialog_sleep): """Test editing a rule using the dialog widget. """ p = text_monitor_workbench.get_plugin(PLUGIN_ID) m = p.create_monitor(False) m.handle_database_change(('added', 'root/test_f', 0)) d = EditRulesView(monitor=m) d.show() process_app_events() sleep(dialog_sleep) # Create a new rule psh_btn = d.central_widget().widgets()[-4] def create(dial): dial.rule = RejectRule(id='__dummy', suffixes=['f']) with handle_dialog(custom=create, cls=CreateRuleDialog): psh_btn.clicked = True assert any([r.id == '__dummy' for r in m.rules]) assert not m.displayed_entries qlist = d.central_widget().widgets()[0] qlist.selected_item = [r for r in m.rules if r.id == '__dummy'][0] process_app_events() assert d.central_widget().widgets()[1].rule sleep(dialog_sleep) # Save rule and save and add to default try: psh_btn = d.central_widget().widgets()[-2] act = psh_btn.children[0].children[0] act.triggered = True process_app_events() assert '__dummy' in p.rules assert '__dummy' not in p.default_rules del p._user_rules['__dummy'] act = psh_btn.children[0].children[1] act.triggered = True process_app_events() assert '__dummy' in p.rules assert '__dummy' in p.default_rules finally: if '__dummy' in p._user_rules: del p._user_rules['__dummy'] # Delete rule psh_btn = d.central_widget().widgets()[-3] psh_btn.clicked = True process_app_events() assert '__dummy' not in m.rules assert m.displayed_entries d.central_widget().widgets()[-1].clicked = True process_app_events()
def test_check_errors2(self, windows): """Test use of validate_ext. """ self.workbench.register(Contributor3()) with handle_dialog(): self.workbench.get_plugin(PLUGIN_ID)
def answer_dialog(dialog): model = dialog._model model.folder = str(tmpdir) model.filename = 'test' model.doc = 'This is a test' dialog.show_result = True with handle_dialog('accept', time=0): assert model.accept_template_info(dialog)
def test_select_instrument(instr_task_workbench, instr_view): """Test selecting an instrument from the view. """ tool_btn = instr_view.widgets()[-1] selec = ('fp1', 'tests.test.FalseDriver', 'false_connection', 'false_settings') instr_view.task.selected_instrument = selec with handle_dialog('reject'): tool_btn.clicked = True assert instr_view.task.selected_instrument == selec with handle_dialog('accept'): tool_btn.clicked = True assert instr_view.task.selected_instrument == selec
def test_select_instrument(instr_task_workbench, instr_view): """Test selecting an instrument from the view. """ tool_btn = instr_view.widgets()[-1].widgets()[-1] selec = ('fp1', 'tests.test.FalseDriver', 'false_connection', 'false_settings') instr_view.task.selected_instrument = selec with handle_dialog('reject'): tool_btn.clicked = True assert instr_view.task.selected_instrument == selec with handle_dialog('accept'): tool_btn.clicked = True assert instr_view.task.selected_instrument == selec
def test_check_errors1(self, windows): """Test enforcement of type when using factory. """ self.workbench.register(DContributor3()) with handle_dialog(): self.workbench.get_plugin(PLUGIN_ID)
def test_saving_as_template_cancelled(windows, task_workbench, task): """Test saving a task as a template : fail to save. """ core = task_workbench.get_plugin('enaml.workbench.core') with handle_dialog('reject'): val = core.invoke_command(CMD, dict(task=task, mode='template')) assert val is None
def test_errors1(self, windows): """Test uniqueness of contribution id. """ self.workbench.register(Contributor1()) self.workbench.register(Contributor1(id='bis')) self.workbench.register(Contributor1(id='ter')) with handle_dialog(): self.workbench.get_plugin(PLUGIN_ID)
def test_select_instrument_profile_command(prof_plugin): """Test selecting an instrument profile. """ core = prof_plugin.workbench.get_plugin('enaml.workbench.core') with handle_dialog('reject'): res = core.invoke_command('ecpy.instruments.select_instrument') assert res is None with handle_dialog('accept'): res = core.invoke_command('ecpy.instruments.select_instrument', dict(profile='fp1', driver='tests.test.FalseDriver', connection='false_connection3', settings='false_settings3')) assert res == ('fp1', 'tests.test.FalseDriver', 'false_connection3', 'false_settings3')
def test_open_browser_command(prof_plugin): """Test opening the browsing window. """ with enaml.imports(): from enaml.workbench.ui.ui_manifest import UIManifest prof_plugin.workbench.register(UIManifest()) core = prof_plugin.workbench.get_plugin('enaml.workbench.core') with handle_dialog(): core.invoke_command('ecpy.instruments.open_browser')
def test_signal_command_with_unknown(err_workbench, windows): """Test the signal command with a stupid kind of error. """ core = err_workbench.get_plugin('enaml.workbench.core') with handle_dialog(): core.invoke_command('ecpy.app.errors.signal', { 'kind': 'stupid', 'msg': None }) with handle_dialog(): fail = FailedFormat() core.invoke_command('ecpy.app.errors.signal', { 'kind': 'stupid', 'msg': fail }) assert getattr(fail, 'called', None)
def test_select_instrument_profile_command(prof_plugin): """Test selecting an instrument profile. """ core = prof_plugin.workbench.get_plugin('enaml.workbench.core') with handle_dialog('reject'): res = core.invoke_command('ecpy.instruments.select_instrument') assert res is None with handle_dialog('accept'): res = core.invoke_command( 'ecpy.instruments.select_instrument', dict(profile='fp1', driver='tests.test.FalseDriver', connection='false_connection3', settings='false_settings3')) assert res == ('fp1', 'tests.test.FalseDriver', 'false_connection3', 'false_settings3')
def test_running_main_error_in_parsing(windows): """Test starting the main app but encountering an issue while adding arguments. """ def check_dialog(dial): assert 'cmd' in dial.text with pytest.raises(SystemExit): with handle_dialog('reject', check_dialog): main(['dummy'])
def test_enqueueing_fail_checks(workspace): """Test enqueueing a measure not passing the checks. """ m = workspace.plugin.edited_measures.measures[0] with handle_dialog('reject'): workspace.enqueue_measure(m) assert not workspace.plugin.enqueued_measures.measures # Check dependencies are cleaned up assert_dependencies_released(workspace, m)
def test_gathering_mode(workbench, windows): """Test gathering multiple errors. """ core = workbench.get_plugin('enaml.workbench.core') core.invoke_command('ecpy.app.errors.enter_error_gathering') core.invoke_command('ecpy.app.errors.signal', {'kind': 'stupid', 'msg': None}) assert get_window() is None with handle_dialog(): core.invoke_command('ecpy.app.errors.exit_error_gathering')
def test_profile_edition_dialog_ok(prof_plugin, process_and_sleep, profile_infos): """Test the dialog used to edit a profile. """ profile_infos.connections.clear() profile_infos.settings.clear() ed = ProfileEditionDialog(plugin=prof_plugin, profile_infos=profile_infos) ed.show() process_and_sleep() ed_widgets = ed.central_widget().widgets() ed_widget = ed_widgets[0] nb = ed_widget.widgets()[5] c_page, s_page = nb.pages() # Add a connection with handle_dialog(cls=ConnectionCreationDialog): c_page.page_widget().widgets()[2].clicked = True process_and_sleep() # Add a settings with handle_dialog(cls=SettingsCreationDialog): s_page.page_widget().widgets()[2].clicked = True process_and_sleep() assert len(ed_widget.connections) == 1 assert len(ed_widget.settings) == 1 ed_widgets[-1].clicked = True process_app_events() assert len(profile_infos.connections) == 1 assert len(profile_infos.settings) == 1
def test_force_enqueueing(workspace): """Test enqueueing a measure not passing the checks. """ m = workspace.plugin.edited_measures.measures[0] with handle_dialog(): workspace.enqueue_measure(m) assert workspace.plugin.enqueued_measures.measures # Make sure runtimes are always released. m = workspace.plugin.workbench.get_manifest('test.measure') assert not m.find('runtime_dummy1').collected assert not m.find('runtime_dummy2').collected