def process_engine(measurement_workbench): measurement_workbench.register(LogManifest()) measurement_workbench.register(TasksManagerManifest()) plugin = measurement_workbench.get_plugin('exopy.measurement') yield plugin.create('engine', 'exopy.process_engine') plugin.processor.engine = None gc.collect()
def test_task_saving_building(workbench, task): """Test saving and rebuilbing the sequence. """ workbench.register(PulsesTasksManifest()) workbench.register(TasksManagerManifest()) core = workbench.get_plugin('enaml.workbench.core') deps = core.invoke_command('exopy.app.dependencies.analyse', dict(obj=task, dependencies=['build'])) deps = core.invoke_command( 'exopy.app.dependencies.collect', dict(dependencies=deps.dependencies, kind='build')) task.update_preferences_from_members() prefs = task.preferences task2 = TransferPulseSequenceTask.build_from_config( prefs, deps.dependencies) assert task2.sequence assert task2.sequence.context assert task2.sequence.items # Try to build a task missing a sequence. del task.sequence task.update_preferences_from_members() prefs = task.preferences del deps.dependencies['exopy.pulses.item'] task3 = TransferPulseSequenceTask.build_from_config( prefs, deps.dependencies) assert not task3.sequence
def task_workbench(workbench, monkeypatch, app_dir): """Setup the workbench in such a way that the task manager can be tested. """ monkeypatch.setattr(ErrorsPlugin, 'exit_error_gathering', exit_on_err) workbench.register(CoreManifest()) workbench.register(AppManifest()) workbench.register(PreferencesManifest()) workbench.register(IconManagerManifest()) workbench.register(ErrorsManifest()) workbench.register(StateManifest()) workbench.register(DependenciesManifest()) workbench.register(TasksManagerManifest()) yield workbench for m_id in ('exopy.tasks', 'exopy.app.dependencies', 'exopy.app.errors', 'exopy.app.icons', 'exopy.app.preferences', 'exopy.app'): try: workbench.unregister(m_id) except Exception: pass # Give some time to the os to release resources linked to file # monitoring. sleep(0.1)
def test_converting_a_measurement(measurement_workbench, meas_file, tmpdir, monkeypatch): """Test converting a measurement created using HQCMeas to make it run on Exopy. """ import enaml from exopy.measurement.monitors.text_monitor import monitor monkeypatch.setattr(monitor, 'information', lambda *args, **kwargs: 1) measurement_workbench.register(TasksManagerManifest()) measurement_workbench.register(HqcLegacyManifest()) try: with enaml.imports(): from exopy_pulses.pulses.manifest import PulsesManagerManifest measurement_workbench.register(PulsesManagerManifest()) from exopy_pulses.tasks.manifest import PulsesTasksManifest measurement_workbench.register(PulsesTasksManifest()) from exopy_hqc_legacy.pulses.manifest\ import HqcLegacyPulsesManifest measurement_workbench.register(HqcLegacyPulsesManifest()) except ImportError: print('Exopy pulses is not installed') print_exc() plugin = measurement_workbench.get_plugin('exopy.measurement') path = convert_measure(os.path.join(MEASURE_DIRECTORY, meas_file), dest_folder=str(tmpdir)) res, errors = Measurement.load(plugin, path) with open(path) as f: print(errors.get('main task'), f.read()) assert res
def test_running_checks(measurement_workbench, measurement): """Test running the checks attached to a measurement. """ # Add dummy hooks measurement.add_tool('pre-hook', 'dummy') measurement.add_tool('post-hook', 'dummy') # This is necessary for the internal checks. measurement_workbench.register(TasksManagerManifest()) # Collect run time dependencies. res, msg, errors = measurement.dependencies.collect_runtimes() assert res # Fake the presence of run time dependencies to check that they are well # passed to the root task. measurement.dependencies._runtime_map['main'] = {'dummy': (1, 2, 3)} measurement.dependencies._runtime_dependencies['dummy'] =\ {1: None, 2: None, 3: None} # Check that the internal hook does run the root_task tests. res, errors = measurement.run_checks() assert not res assert 'exopy.internal_checks' in errors # Check an ideal case measurement.root_task.default_path = os.path.dirname(__file__) res, errors = measurement.run_checks() assert res assert not errors # Check handling error in pre_hook measurement.pre_hooks['dummy'].fail_check = True res, errors = measurement.run_checks() assert not res assert 'dummy' in errors and errors['dummy'] == 'pre' # Check handling error in post_hook measurement.pre_hooks['dummy'].fail_check = False measurement.post_hooks['dummy'].fail_check = True res, errors = measurement.run_checks() assert not res assert 'dummy' in errors and errors['dummy'] == 'post' # Check kwargs passing to pre-hooks measurement.post_hooks['dummy'].fail_check = False res, errors = measurement.run_checks(fail=True) assert not res assert 'dummy' in errors and errors['dummy'] == 'pre' # Check kwargs passing to post-hooks res, errors = measurement.run_checks(fail_post=True) assert not res assert 'dummy' in errors and errors['dummy'] == 'post'
def test_measurement_persistence(measurement_workbench, measurement, tmpdir, monkeypatch): """Test saving and reloading a measurement. """ measurement_workbench.register(TasksManagerManifest()) plugin = measurement_workbench.get_plugin('exopy.measurement') for m_e in ('meas_name', 'meas_id', 'meas_date', 'meas_time'): assert m_e in measurement.root_task.database_entries measurement.add_tool('pre-hook', 'dummy') measurement.root_task.default_path = 'test' measurement.pre_hooks['dummy'].fail_check = True path = str(tmpdir.join('test.meas.ini')) measurement.save(path) assert measurement.path == path loaded, errors = Measurement.load(plugin, path) assert loaded.root_task.default_path == 'test' assert loaded.pre_hooks['dummy'].fail_check assert loaded.path == path assert not errors # Test handling errors : root_task rebuilding and tool rebuilding. class CommandError(Exception): pass def generate_err(self, cmd, infos, u=None): raise CommandError() from enaml.workbench.core.core_plugin import CorePlugin old = CorePlugin.invoke_command monkeypatch.setattr(CorePlugin, 'invoke_command', generate_err) loaded, errors = Measurement.load(plugin, path) assert loaded is None assert 'main task' in errors and 'CommandError' in errors['main task'] CorePlugin.invoke_command = old class CreationError(Exception): pass class Fail(object): def new(self, workbench, default=True): raise CreationError() plugin._pre_hooks.contributions['dummy'] = Fail() loaded, errors = Measurement.load(plugin, path) assert loaded is None assert 'pre-hook' in errors and 'dummy' in errors['pre-hook'] assert 'CreationError' in errors['pre-hook']['dummy']
def content_workbench(measurement_workbench, measurement, exopy_qtbot): """Create a measurement workspace. """ measurement_workbench.register(UIManifest()) measurement_workbench.register(LogManifest()) measurement_workbench.register(TasksManagerManifest()) measurement_plugin = measurement_workbench.get_plugin('exopy.measurement') measurement_plugin.selected_engine = 'dummy' measurement_plugin.default_monitors = ['dummy'] return measurement_workbench
def processor(exopy_qtbot, measurement_workbench, measurement): """Fixture starting the measurement plugin and returning the processor. Use app because we need run the event loop """ # measurement ensures that contributions are there measurement_workbench.register(UIManifest()) measurement_workbench.register(TasksManagerManifest()) plugin = measurement_workbench.get_plugin('exopy.measurement') plugin.selected_engine = 'dummy' return plugin.processor
def task_view(task, workbench): """Transfer sequence task view for testing. """ workbench.register(TasksManagerManifest()) core = workbench.get_plugin('enaml.workbench.core') cmd = 'exopy.pulses.get_context_infos' c_infos = core.invoke_command(cmd, dict(context_id='exopy_pulses.DummyContext')) c_infos.instruments = set(['exopy_pulses.TestDriver']) task.selected_instrument = ('p', 'exopy_pulses.TestDriver', 'c', 's') root_view = RootTaskView(task=task.root, core=core) view = TransferPulseSequenceView(task=task, root=root_view) return view
def test_dependencies_analysis(workbench, task): """Test analysing dependencies. We must ensure that instruments are there as this task does not rely on the common mechanism. """ workbench.register(PulsesTasksManifest()) workbench.register(TasksManagerManifest()) workbench.register(InstrumentManagerManifest()) core = workbench.get_plugin('enaml.workbench.core') build, runtime = core.invoke_command( 'exopy.app.dependencies.analyse', dict(obj=task, dependencies=['build', 'runtime'])) print(runtime.errors) assert not build.errors and not runtime.errors assert len(runtime.dependencies) == 2
def workspace(exopy_qtbot, measurement_workbench, measurement): """Create a measurement workspace. """ measurement_workbench.register(UIManifest()) measurement_workbench.register(LogManifest()) measurement_workbench.register(TasksManagerManifest()) measurement_plugin = measurement_workbench.get_plugin('exopy.measurement') measurement_plugin.selected_engine = 'dummy' measurement_plugin.default_monitors = ['dummy'] core = measurement_workbench.get_plugin('enaml.workbench.core') cmd = 'enaml.workbench.ui.select_workspace' core.invoke_command(cmd, {'workspace': 'exopy.measurement.workspace'}) yield measurement_plugin.workspace cmd = 'enaml.workbench.ui.close_workspace' core.invoke_command(cmd, {'workspace': 'exopy.measurement.workspace'})
def instr_task_workbench(instr_workbench): """Workbench with instrument and task support and patched task. """ w = instr_workbench w.register(InstrContributor()) c = ConfigObj(PROFILE_PATH, encoding='utf-8') add_profile(instr_workbench, c, ['fp1', 'fp2', 'fp3', 'fp4']) w.register(TasksManagerManifest()) p = w.get_plugin('exopy.tasks') infos = TaskInfos(cls=InterInstrTask, instruments=['tasks.test.FalseDriver']) infos.interfaces = \ {'test.I': InterfaceInfos(cls=TaskInterface, parent=infos, instruments=['tasks.test.FalseDriver4', 'tasks.test.FalseDriver2'] ) } p._tasks.contributions['exopy.InstrumentTask'] = infos return w
def process_engine(measurement_workbench): measurement_workbench.register(LogManifest()) measurement_workbench.register(TasksManagerManifest()) plugin = measurement_workbench.get_plugin('exopy.measurement') return plugin.create('engine', 'exopy.process_engine')
def main(cmd_line_args=None): """Main entry point of the Exopy application. """ # Build parser from ArgParser and parse arguemnts parser = ArgParser() parser.add_choice('workspaces', 'exopy.measurement.workspace', 'measurement') parser.add_argument("-s", "--nocapture", help="Don't capture stdout/stderr", action='store_true') parser.add_argument("-w", "--workspace", help='Select start-up workspace', default='measurement', choices='workspaces') parser.add_argument("-r", "--reset-app-folder", help='Reset the application startup folder.', action='store_true') modifiers = [] for i, ep in enumerate(iter_entry_points('exopy_cmdline_args')): try: modifier, priority = ep.load(require=False) modifiers.append((ep, modifier, priority, i)) except Exception as e: text = 'Error loading extension %s' % ep.name content = ('The following error occurred when trying to load the ' 'entry point {} :\n {}'.format(ep.name, e)) details = format_exc() display_startup_error_dialog(text, content, details) modifiers.sort(key=itemgetter(1, 2)) try: for m in modifiers: m[1](parser) except Exception as e: text = 'Error modifying cmd line arguments' content = ('The following error occurred when the entry point {} ' 'tried to add cmd line options :\n {}'.format(ep.name, e)) details = format_exc() display_startup_error_dialog(text, content, details) try: args = parser.parse_args(cmd_line_args) except BaseException as e: if e.args == (0, ): sys.exit(0) text = 'Failed to parse cmd line arguments' content = ('The following error occurred when trying to parse the ' 'command line arguments :\n {}'.format(e)) details = format_exc() display_startup_error_dialog(text, content, details) # Patch Thread to use sys.excepthook setup_thread_excepthook() workbench = Workbench() workbench.register(CoreManifest()) workbench.register(UIManifest()) workbench.register(AppManifest()) workbench.register(StateManifest()) workbench.register(ErrorsManifest()) workbench.register(PreferencesManifest()) workbench.register(IconManagerManifest()) workbench.register(LogManifest()) workbench.register(PackagesManifest()) workbench.register(DependenciesManifest()) workbench.register(InstrumentManagerManifest()) workbench.register(TasksManagerManifest()) workbench.register(MeasureManifest()) workbench.register(TextMonitorManifest()) ui = workbench.get_plugin(u'enaml.workbench.ui') # Create the application try: app = workbench.get_plugin('exopy.app') app.run_app_startup(args) except Exception as e: text = 'Error starting plugins' content = ('The following error occurred when executing plugins ' 'application start ups :\n {}'.format(e)) details = format_exc() display_startup_error_dialog(text, content, details) core = workbench.get_plugin('enaml.workbench.core') # Install global except hook. if not args.nocapture: core.invoke_command('exopy.app.errors.install_excepthook', {}) # Select workspace core.invoke_command('enaml.workbench.ui.select_workspace', {'workspace': args.workspace}, workbench) ui = workbench.get_plugin(u'enaml.workbench.ui') ui.show_window() ui.window.maximize() ui.start_application() core.invoke_command('enaml.workbench.ui.close_workspace', {}, workbench) # Unregister all contributed packages workbench.unregister('exopy.app.packages') workbench.unregister('exopy.measurement.monitors.text_monitor') workbench.unregister('exopy.measurement') workbench.unregister('exopy.tasks') workbench.unregister('exopy.instruments') workbench.unregister('exopy.app.icons') workbench.unregister('exopy.app.preferences') workbench.unregister('exopy.app.states') workbench.unregister('exopy.app.dependencies') workbench.unregister('exopy.app.errors') workbench.unregister('exopy.app.logging') workbench.unregister('exopy.app') workbench.unregister(u'enaml.workbench.ui') workbench.unregister(u'enaml.workbench.core')