Example #1
0
def test_ophydobj():
    parent = OphydObject(name='name', parent=None)
    child = OphydObject(name='name', parent=parent)
    assert child.parent is parent

    with pytest.raises(ValueError):
        child.subscribe(None, event_type=None)

    with pytest.raises(KeyError):
        child.subscribe(lambda *args: None, event_type='unknown_event_type')

    assert parent.connected
Example #2
0
    def test_ophydobj(self):
        parent = OphydObject(name='name', parent=None)
        child = OphydObject(name='name', parent=parent)
        self.assertIs(child.parent, parent)

        child._run_sub('not_a_callable', sub_type='sub')

        self.assertRaises(ValueError, child.subscribe, None,
                          event_type=None)
        self.assertRaises(KeyError, child.subscribe, None,
                          event_type='unknown_event_type')

        self.assertIs(parent.connected, True)
Example #3
0
    def test_ophydobj(self):
        parent = OphydObject(name='name', parent=None)
        child = OphydObject(name='name', parent=parent)
        self.assertIs(child.parent, parent)

        child._run_sub('not_a_callable', sub_type='sub')

        self.assertRaises(ValueError, child.subscribe, None, event_type=None)
        self.assertRaises(KeyError,
                          child.subscribe,
                          None,
                          event_type='unknown_event_type')

        self.assertIs(parent.connected, True)
Example #4
0
def test_register_instance():
    weakset = register_instances_in_weakset()
    test1 = OphydObject(name='test1')
    assert test1 in weakset
    test2 = OphydObject(name='test1')
    assert test2 in weakset

    weakdict = register_instances_keyed_on_name()
    test1 = OphydObject(name='test1')
    assert weakdict['test1'] == test1
    test2 = OphydObject(name='test2')
    assert weakdict['test2'] == test2

    assert OphydObject._OphydObject__any_instantiated is True
    with pytest.raises(RuntimeError):
        register_instances_in_weakset(fail_if_late=True)
    with pytest.raises(RuntimeError):
        register_instances_keyed_on_name(fail_if_late=True)
Example #5
0
def test_logger_adapter_ophyd_object():
    log_buffer = io.StringIO()
    log_stream = logging.StreamHandler(stream=log_buffer)
    log_stream.setFormatter(log.LogFormatter())

    log.logger.addHandler(log_stream)

    ophyd_object = OphydObject(name="testing OphydObject.log")
    ophyd_object.log.info("here is some info")
    assert log_buffer.getvalue().endswith(
        "[testing OphydObject.log] here is some info\n")
Example #6
0
def test_ophydobj():
    parent = OphydObject(name='name', parent=None)
    child = OphydObject(name='name', parent=parent)
    assert child.parent is parent

    with pytest.raises(ValueError):
        child.subscribe(None, event_type=None)

    with pytest.raises(KeyError):
        child.subscribe(lambda *args: None, event_type='unknown_event_type')

    assert parent.connected
Example #7
0
def test_subscribe_no_default():
    o = OphydObject(name='name', parent=None)

    with pytest.raises(ValueError):
        o.subscribe(lambda *a, **k: None)
Example #8
0
def test_subscribe_no_default():
    o = OphydObject(name='name', parent=None)

    with pytest.raises(ValueError):
        o.subscribe(lambda *a, **k: None)