<commit_before>from bluesky.tests import requires_ophyd
from bluesky.tests.utils import MsgCollector
from bluesky.plans import (ramp_plan, trigger_and_read)
from bluesky import Msg
from bluesky.utils import RampFail
import numpy as np
import time
import pytest


@requires_ophyd
def test_ramp(RE, db):
    from ophyd.positioner import SoftPositioner
    from ophyd import StatusBase
    from bluesky.examples import SynGauss

    tt = SoftPositioner(name='mot')
    tt.set(0)
    dd = SynGauss('det', tt, 'mot', 0, 3)

    st = StatusBase()

    def kickoff():
        yield Msg('null')
        for j, v in enumerate(np.linspace(-5, 5, 25)):
            RE.loop.call_later(.05 * j, lambda v=v: tt.set(v))
        RE.loop.call_later(.05 * 30, st._finished)
        return st

    def inner_plan():
        yield from trigger_and_read([dd])

    g = ramp_plan(kickoff(), tt, inner_plan, period=0.04)
    RE.subscribe('all', db.mds.insert)
    RE.msg_hook = MsgCollector()
    rs_uid, = RE(g)
    hdr = db[-1]
    assert hdr.start.uid == rs_uid
    assert len(hdr.descriptors) == 2

    assert set([d['name'] for d in hdr.descriptors]) == \
        set(['primary', 'mot-monitor'])

    primary_events = list(db.get_events(hdr, stream_name='primary'))
    assert len(primary_events) > 27

    monitor_events = list(db.get_events(hdr, stream_name='mot-monitor'))
    assert len(monitor_events) == 25


@requires_ophyd
def test_timeout(RE):
    from ophyd.positioner import SoftPositioner
    from bluesky.examples import SynGauss
    from ophyd import StatusBase

    mot = SoftPositioner(name='mot')
    mot.set(0)
    det = SynGauss('det', mot, 'mot', 0, 3)

    def kickoff():
        yield Msg('null')
        for j in range(20):
            RE.loop.call_later(.05 * j, lambda j=j: mot.set(j))

        return StatusBase()

    def inner_plan():
        yield from trigger_and_read([det])

    g = ramp_plan(kickoff(), mot, inner_plan, period=.1, timeout=1)

    start = time.time()
    with pytest.raises(RampFail):
        RE(g)
    stop = time.time()
    elapsed = stop - start

    assert 1 < elapsed < 1.2<commit_msg>CI: tweak ramp plan test timings<commit_after>from bluesky.tests import requires_ophyd
from bluesky.tests.utils import MsgCollector
from bluesky.plans import (ramp_plan, trigger_and_read)
from bluesky import Msg
from bluesky.utils import RampFail
import numpy as np
import time
import pytest


@requires_ophyd
def test_ramp(RE, db):
    from ophyd.positioner import SoftPositioner
    from ophyd import StatusBase
    from bluesky.examples import SynGauss

    tt = SoftPositioner(name='mot')
    tt.set(0)
    dd = SynGauss('det', tt, 'mot', 0, 3)

    st = StatusBase()

    def kickoff():
        yield Msg('null')
        for j, v in enumerate(np.linspace(-5, 5, 10)):
            RE.loop.call_later(.1 * j, lambda v=v: tt.set(v))
        RE.loop.call_later(1.2, st._finished)
        return st

    def inner_plan():
        yield from trigger_and_read([dd])

    g = ramp_plan(kickoff(), tt, inner_plan, period=0.1)
    RE.subscribe('all', db.mds.insert)
    RE.msg_hook = MsgCollector()
    rs_uid, = RE(g)
    hdr = db[-1]
    assert hdr.start.uid == rs_uid
    assert len(hdr.descriptors) == 2

    assert set([d['name'] for d in hdr.descriptors]) == \
        set(['primary', 'mot-monitor'])

    primary_events = list(db.get_events(hdr, stream_name='primary'))
    assert len(primary_events) > 11

    monitor_events = list(db.get_events(hdr, stream_name='mot-monitor'))
    assert len(monitor_events) == 10


@requires_ophyd
def test_timeout(RE):
    from ophyd.positioner import SoftPositioner
    from bluesky.examples import SynGauss
    from ophyd import StatusBase

    mot = SoftPositioner(name='mot')
    mot.set(0)
    det = SynGauss('det', mot, 'mot', 0, 3)

    def kickoff():
        yield Msg('null')
        for j in range(5):
            RE.loop.call_later(.05 * j, lambda j=j: mot.set(j))

        return StatusBase()

    def inner_plan():
        yield from trigger_and_read([det])

    g = ramp_plan(kickoff(), mot, inner_plan, period=.01, timeout=.1)

    start = time.time()
    with pytest.raises(RampFail):
        RE(g)
    stop = time.time()
    elapsed = stop - start

    assert .1 < elapsed < .2
{'fraction_non_alphanumeric': 0.1236192714453584, 'fraction_numerical': 0.014806110458284371, 'mean_word_length': 3.007532956685499, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '754085', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1435, 'n_words': 373}