Пример #1
0
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']
Пример #2
0
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']
Пример #3
0
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