def quadem(): FakeQuadEM = make_fake_device(QuadEM) em = FakeQuadEM('quadem:', name='quadem') clear_fake_device(em) em.conf.port_name.put('NSLS_EM') for k in [ 'image', 'current1', 'current2', 'current3', 'current4', 'sum_all' ]: cc = getattr(em, k) if isinstance(cc, ImagePlugin): cc.plugin_type.sim_put(ImagePlugin._plugin_type) cc.nd_array_port.sim_put('NSLS_EM') elif isinstance(cc, StatsPlugin): cc.plugin_type.sim_put(StatsPlugin._plugin_type) cc.nd_array_port.sim_put('NSLS_EM') cc.enable.sim_set_enum_strs(['Disabled', 'Enabled']) cc.enable.put('Enabled') cc.port_name.sim_put(k.upper()) em.wait_for_connection() return em
def quadem(): FakeQuadEM = make_fake_device(QuadEM) em = FakeQuadEM('quadem:', name='quadem') clear_fake_device(em) em.conf.port_name.put('NSLS_EM') for k in ['image', 'current1', 'current2', 'current3', 'current4', 'sum_all']: cc = getattr(em, k) if isinstance(cc, ImagePlugin): cc.plugin_type.sim_put(ImagePlugin._plugin_type) cc.nd_array_port.sim_put('NSLS_EM') elif isinstance(cc, StatsPlugin): cc.plugin_type.sim_put(StatsPlugin._plugin_type) cc.nd_array_port.sim_put('NSLS_EM') else: cc.plugin_type.sim_put('unknown') cc.enable.sim_set_enum_strs(['Disabled', 'Enabled']) cc.enable.put('Enabled') cc.port_name.sim_put(k.upper()) em.wait_for_connection() return em
def test_clear_fake_device(): FakeSample = make_fake_device(Sample) my_fake = FakeSample('KITCHEN', name='kitchen') clear_fake_device(my_fake, default_value=49, default_string_value='string') assert my_fake.butter.value == 49 assert my_fake.flour.value == 49 assert my_fake.sink.value == 49 assert my_fake.egg.yolk.value == 'string' assert my_fake.egg.whites.value == 49
def create_devices(device_names, cfg=None, fake_devices=False): """Returns a list of devices to be included in the typhos suite.""" logger.debug("Accessing Happi Client ...") try: happi_client = _create_happi_client(cfg) except Exception: logger.debug("Unable to create a happi client.", exc_info=True) happi_client = None # Load and add each device devices = list() klass_regex = re.compile( r'([a-zA-Z][a-zA-Z0-9\.\_]*)\[(\{.+})*[\,]*\]' # noqa ) for device_name in device_names: logger.info("Loading %r ...", device_name) result = klass_regex.findall(device_name) if len(result) > 0: try: klass, args = result[0] klass = pcdsutils.utils.import_helper(klass) default_kwargs = {"name": klass.__name__} if args: kwargs = ast.literal_eval(args) default_kwargs.update(kwargs) if fake_devices: klass = make_fake_device(klass) # Give default value to missing positional args # This might fail, but is best effort for arg in inspect.getfullargspec(klass).args: if arg not in default_kwargs and arg != 'self': if arg == 'prefix': default_kwargs[arg] = 'FAKE_PREFIX:' else: default_kwargs[arg] = 'FAKE' device = klass(**default_kwargs) devices.append(device) except Exception: logger.exception("Unable to load class entry: %s with args %s", klass, args) continue else: if not happi_client: logger.error( "Happi not available. Unable to load entry: %r", device_name, ) continue if fake_devices: raise NotImplementedError("Fake devices from happi not " "supported yet") try: device = happi_client.load_device(name=device_name) devices.append(device) except Exception: logger.exception("Unable to load Happi entry: %r", device_name) if fake_devices: clear_fake_device(device) return devices