Пример #1
0
def test_device_handling():
    sub_d = Device(name='sub_device')
    main_d = Device(name='main_device')
    sub = HXDGroup(sub_d, name='sub')
    main = HXDGroup(main_d, sub, name='main')
    assert main.children == (main_d, sub)
    assert main.devices == [main_d, sub_d]
    assert main.subgroups == [sub]
    assert sub.subgroups == []
Пример #2
0
def test_device_recursion():
    bot_d = Device(name='bot_device')
    low_d = Device(name='low_device')
    sub_d = Device(name='sub_device')
    main_d = Device(name='main_device')
    bot = HXDGroup(bot_d, name='bottom')
    low = HXDGroup(low_d, bot, name='low')
    sub = HXDGroup(sub_d, low, name='sub')
    main = HXDGroup(main_d, sub, name='main')
    assert bot_d in main.devices
    assert low_d in main.devices
    assert sub_d in main.devices
Пример #3
0
def test_add_md():
    d = Device(name='Test', prefix='Tst:This:3',
               beamline="TST", args=list(),
               device_class="happi.Device")
    obj = from_container(d, attach_md=True)
    assert obj.md.beamline == 'TST'
    assert obj.md.name == 'Test'
Пример #4
0
def test_add_device(happi_client, valve, device, valve_info):
    happi_client.add_device(valve)
    doc = happi_client.backend.find(multiples=False, **valve_info)
    assert valve.prefix == doc['prefix']
    assert valve.name == doc['name']
    assert valve.z == doc['z']
    assert valve.beamline == doc['beamline']
    # No duplicates
    with pytest.raises(DuplicateError):
        happi_client.add_device(device)
    # No incompletes
    d = Device()
    with pytest.raises(EntryError):
        happi_client.add_device(d)
Пример #5
0
def happiDB(simul_hutch):
    test_dir = os.path.dirname(os.path.abspath(__file__))
    client = happi.tests.MockClient()
    #Fill database
    for device in simul_hutch.devices:
        client.add_device(device)
    #Add a parent device to be added to group
    client.add_device(
        Device(name='Child',
               prefix='Tst:MMS',
               parent='DG4 Device Three',
               stand='DG4',
               beamline='TST',
               embedded_screen=os.path.join(test_dir, 'small.edl')))
    return client
Пример #6
0
def test_load_devices():
    # Create a bunch of devices to load
    devs = [
        TimeDevice(name='Test 1',
                   prefix='Tst1:This',
                   beamline='TST',
                   device_class='datetime.timedelta',
                   args=list(),
                   days=10,
                   kwargs={
                       'days': '{{days}}',
                       'seconds': 30
                   }),
        TimeDevice(name='Test 2',
                   prefix='Tst2:This',
                   beamline='TST',
                   device_class='datetime.timedelta',
                   args=list(),
                   days=10,
                   kwargs={
                       'days': '{{days}}',
                       'seconds': 30
                   }),
        TimeDevice(name='Test 3',
                   prefix='Tst3:This',
                   beamline='TST',
                   device_class='datetime.timedelta',
                   args=list(),
                   days=10,
                   kwargs={
                       'days': '{{days}}',
                       'seconds': 30
                   }),
        Device(name='Bad',
               prefix='Not:Here',
               beamline='BAD',
               device_class='non.existant')
    ]
    # Load our devices
    space = load_devices(*devs, pprint=True)
    # Check all our devices are there
    assert all([create_alias(dev.name) in space.__dict__ for dev in devs])
    # Devices were loading properly or exceptions were stored
    import datetime
    assert space.test_1 == datetime.timedelta(days=10, seconds=30)
    assert isinstance(space.bad, ImportError)
Пример #7
0
def test_device_equivalance():
    a = Device(name='a', prefix='b')
    b = Device(name='a', prefix='b')
    c = Device(name='c', prefix='b')
    assert a == b
    assert not c == a
Пример #8
0
def test_device_deepcopy():
    a = Device(name='abcd', prefix='abc', kwargs={'abc': 'def'})

    c = copy.deepcopy(a)
    assert a.kwargs == c.kwargs
    assert id(a.kwargs) != id(c.kwargs)
Пример #9
0
def test_device_copy():
    a = Device(name='abcd', prefix='b')
    b = copy.copy(a)
    assert dict(a) == dict(b)
Пример #10
0
def test_dictify():
    a = Device(name='abcd', prefix='b')
    assert dict(a) == a.post()
Пример #11
0
def valve():
    t = Device(**valve_info())
    return t
Пример #12
0
def device():
    t = Device(**device_info())
    return t
Пример #13
0
def simul_device():
    test_dir = os.path.dirname(os.path.abspath(__file__))
    group = HXDGroup(
        Device(name='a',
               prefix='MMS:a',
               embedded_screen=os.path.join(test_dir, 'tiny.edl'),
               beamline='TST',
               system='vacuum'),
        Device(name='b',
               prefix='MMS:b',
               embedded_screen=os.path.join(test_dir, 'tiny.edl'),
               beamline='TST',
               system='vacuum'),
        Device(name='c',
               prefix='MMS:c',
               embedded_screen=os.path.join(test_dir, 'tiny.edl'),
               beamline='TST',
               system='vacuum'),
        Device(name='d',
               prefix='MMS:d',
               embedded_screen=os.path.join(test_dir, 'tiny.edl'),
               beamline='TST',
               system='vacuum'),
        Device(name='e',
               prefix='MMS:e',
               embedded_screen=os.path.join(test_dir, 'tiny.edl'),
               beamline='TST',
               system='vacuum'),
        Device(name='f',
               prefix='MMS:f',
               embedded_screen=os.path.join(test_dir, 'tiny.edl'),
               beamline='TST',
               system='vacuum'),
        Device(name='g',
               prefix='MMS:g',
               embedded_screen=os.path.join(test_dir, 'small.edl'),
               beamline='TST',
               system='timing'),
        Device(name='h',
               prefix='MMS:h',
               embedded_screen=os.path.join(test_dir, 'small.edl'),
               beamline='TST',
               system='timing'),
        Device(name='i',
               prefix='MMS:i',
               embedded_screen=os.path.join(test_dir, 'small.edl'),
               beamline='TST',
               system='timing'),
        Device(name='j',
               prefix='MMS:j',
               embedded_screen=os.path.join(test_dir, 'small.edl'),
               beamline='TST',
               system='timing'),
        Device(name='k',
               prefix='MMS:k',
               embedded_screen=os.path.join(test_dir, 'large.edl'),
               beamline='TST',
               system='diagnostics'),
        name='Device Group')

    return group
Пример #14
0
def valve(valve_info):
    t = Device(**valve_info)
    return t
Пример #15
0
def device(device_info):
    t = Device(**device_info)
    return t