Beispiel #1
0
def test_table(fresh_RE):
    RE = fresh_RE

    with _print_redirect() as fout:
        det.precision = 2
        motor.precision = 2

        table = LiveTable(['det', 'motor'], min_width=16, extra_pad=2)
        ad_scan = AdaptiveAbsScanPlan([det], 'det', motor, -15, 5, .01, 1, .05,
                                      True)
        # use lossless sub here because rows can get dropped
        token = RE.subscribe_lossless('all', table)
        RE(ad_scan)
        RE.unsubscribe_lossless(token)

    fout.seek(0)

    for ln, kn in zip(fout, KNOWN_TABLE.split('\n')):
        # this is to strip the `\n` from the print output
        ln = ln.rstrip()

        if ln[0] == '+':
            # test the full line on the divider lines
            assert ln == kn
        else:
            # skip the 'time' column on data rows
            # this is easier than faking up times in the scan!
            assert ln[:16] == kn[:16]
            assert ln[26:] == kn[26:]
Beispiel #2
0
def test_table(RE, hw):

    with _print_redirect() as fout:
        hw.det.precision = 2
        hw.motor.precision = 2
        hw.motor.setpoint.put(0.0)  # Make dtype 'number' not 'integer'.
        hw.det.trigger()
        assert hw.det.describe()['det']['precision'] == 2
        assert hw.motor.describe()['motor']['precision'] == 2
        assert hw.det.describe()['det']['dtype'] == 'number'
        assert hw.motor.describe()['motor']['dtype'] == 'number'

        table = LiveTable(['det', 'motor'],
                          min_width=16,
                          extra_pad=2,
                          separator_lines=False)
        ad_scan = bp.adaptive_scan([hw.det], 'det', hw.motor, -15.0, 5., .01,
                                   1, .05, True)
        # use lossless sub here because rows can get dropped
        token = RE.subscribe(table)
        RE(ad_scan)
        RE.unsubscribe_lossless(token)

    fout.seek(0)
    _compare_tables(fout, KNOWN_TABLE)
Beispiel #3
0
def test_table(RE, hw):

    with _print_redirect() as fout:
        hw.det.precision = 2
        hw.motor.precision = 2
        hw.motor.setpoint.put(0.0)  # Make dtype 'number' not 'integer'.
        hw.det.put(0.0)  # Make dtype 'number' not 'integer'.
        assert hw.det.describe()["det"]["precision"] == 2
        assert hw.motor.describe()["motor"]["precision"] == 2
        assert hw.det.describe()["det"]["dtype"] == "number"
        assert hw.motor.describe()["motor"]["dtype"] == "number"

        table = LiveTable(["det", "motor"], min_width=16, extra_pad=2)
        ad_scan = bp.adaptive_scan([hw.det], "det", hw.motor, -15.0, 5., .01,
                                   1, .05, True)
        # use lossless sub here because rows can get dropped
        token = RE.subscribe(table)
        RE(ad_scan)
        RE.unsubscribe_lossless(token)

    fout.seek(0)

    for ln, kn in zip(fout, KNOWN_TABLE.split("\n")):
        # this is to strip the `\n` from the print output
        ln = ln.rstrip()

        if ln[0] == "+":
            # test the full line on the divider lines
            assert ln == kn
        else:
            # skip the 'time' column on data rows
            # this is easier than faking up times in the scan!
            assert ln[:16] == kn[:16]
            assert ln[26:] == kn[26:]
Beispiel #4
0
def test_table(RE, hw):

    with _print_redirect() as fout:
        hw.det.precision = 2
        hw.motor.precision = 2
        hw.motor.setpoint.put(0.0)  # Make dtype 'number' not 'integer'.
        hw.det.put(0.0)  # Make dtype 'number' not 'integer'.
        assert hw.det.describe()['det']['precision'] == 2
        assert hw.motor.describe()['motor']['precision'] == 2
        assert hw.det.describe()['det']['dtype'] == 'number'
        assert hw.motor.describe()['motor']['dtype'] == 'number'

        table = LiveTable(['det', 'motor'], min_width=16, extra_pad=2)
        ad_scan = bp.adaptive_scan([hw.det], 'det', hw.motor,
                                   -15.0, 5., .01, 1, .05,
                                   True)
        # use lossless sub here because rows can get dropped
        token = RE.subscribe(table)
        RE(ad_scan)
        RE.unsubscribe_lossless(token)

    fout.seek(0)

    for ln, kn in zip(fout, KNOWN_TABLE.split('\n')):
        # this is to strip the `\n` from the print output
        ln = ln.rstrip()

        if ln[0] == '+':
            # test the full line on the divider lines
            assert ln == kn
        else:
            # skip the 'time' column on data rows
            # this is easier than faking up times in the scan!
            assert ln[:16] == kn[:16]
            assert ln[26:] == kn[26:]
Beispiel #5
0
def test_table():
    with _print_redirect() as fout:
        det.precision = 2
        motor.precision = 2

        table = LiveTable(['det', 'motor'], min_width=16, extra_pad=2)
        ad_scan = AdaptiveAbsScanPlan([det], 'det', motor, -15, 5, .01, 1, .05,
                                      True)
        # use lossless sub here because rows can get dropped
        token = RE.subscribe_lossless('all', table)
        RE(ad_scan)
        RE.unsubscribe_lossless(token)

    fout.seek(0)

    for ln, kn in zip(fout, KNOWN_TABLE.split('\n')):
        # this is to strip the `\n` from the print output
        ln = ln.rstrip()

        if ln[0] == '+':
            # test the full line on the divider lines
            assert ln == kn
        else:
            # skip the 'time' column on data rows
            # this is easier than faking up times in the scan!
            assert ln[:16] == kn[:16]
            assert ln[26:] == kn[26:]
def test_invalid_generator(fresh_RE, motor_det):

    RE = fresh_RE
    motor, det = motor_det

    # this is not a valid generator as it will try to yield if it
    # is throw a GeneratorExit
    def patho_finalize_wrapper(plan, post):
        try:
            yield from plan
        finally:
            yield from post

    def base_plan(motor):
        for j in range(5):
            yield Msg('set', motor, j * 2 + 1)
        yield Msg('pause')

    def post_plan(motor):
        yield Msg('set', motor, 5)

    def pre_suspend_plan():
        yield Msg('set', motor, 5)
        raise GeneratorExit()

    def make_plan():
        return patho_finalize_wrapper(base_plan(motor),
                                      post_plan(motor))

    with _print_redirect() as fout:
        RE(make_plan())
        RE.request_suspend(None, pre_plan=pre_suspend_plan())
        try:
            RE.resume()
        except GeneratorExit:
            pass

    fout.seek(0)
    actual_err = list(fout)[-1]
    expected_prefix = 'The plan '
    expected_postfix = (' tried to yield a value on close.  '
                        'Please fix your plan.\n')[::-1]
    assert actual_err[:len(expected_prefix)] == expected_prefix
    assert actual_err[::-1][:len(expected_postfix)] == expected_postfix
    def trigger(self):
        super().trigger()
        x = self._motor0.read()[self._field0]['value']
        y = self._motor1.read()[self._field1]['value']
        datum_id = new_uid()
        date = datetime.datetime.now()
        srw_file = Path('/tmp/data') / Path(date.strftime('%Y/%m/%d')) / \
            Path('{}.dat'.format(datum_id))
        with _print_redirect():
            srw_run(str(srw_file), slit_x_width=x, slit_y_width=y)
            ret = read_srw_file(srw_file)
        self.image.put(datum_id)
        self.shape.put(ret['shape'])
        self.mean.put(ret['mean'])
        self.photon_energy.put(ret['photon_energy'])
        self.horizontal_extent.put(ret['horizontal_extent'])
        self.vertical_extent.put(ret['vertical_extent'])

        self._resource_id = self.reg.insert_resource('srw', srw_file, {})
        self.reg.insert_datum(self._resource_id, datum_id, {})

        return NullStatus()
Beispiel #8
0
def test_evil_table_names(RE):
    from ophyd import Signal
    sigs = [
        Signal(value=0, name="a:b"),
        Signal(value=0, name="a,b"),
        Signal(value=0, name="a'b"),
        Signal(value=0, name="🐍"),
    ]
    table = LiveTable([s.name for s in sigs],
                      min_width=5,
                      extra_pad=2,
                      separator_lines=False)
    with _print_redirect() as fout:
        print()  # get a blank line in camptured output
        RE(bpp.subs_wrapper(bp.count(sigs, num=2), table))
    reference = """
+------------+--------------+--------+--------+--------+--------+
|   seq_num  |        time  |   a:b  |   a,b  |   a'b  |     🐍  |
+------------+--------------+--------+--------+--------+--------+
|         1  |  12:47:09.7  |     0  |     0  |     0  |     0  |
|         2  |  12:47:09.7  |     0  |     0  |     0  |     0  |
+------------+--------------+--------+--------+--------+--------+"""
    _compare_tables(fout, reference)