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
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)
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)
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")
def test_subscribe_no_default(): o = OphydObject(name='name', parent=None) with pytest.raises(ValueError): o.subscribe(lambda *a, **k: None)