def __init__(self): self._happi_db_dirs = [happi_site_dir, happi_user_dir] self._device_view = HappiClientTreeView() self._client_model = HappiClientModel() self._device_view.setModel(self._client_model) for db_dir in self._happi_db_dirs: for db_file in Path(db_dir).glob('*.json'): client = Client(path=str(db_file)) self._client_model.add_client(client) try: mongo_client = Client( MongoBackend(host='127.0.0.1', db='happi', collection='labview_static', user=USER_MONGO, pw=PW_MONGO, timeout=None)) self._client_model.add_client(mongo_client) except Exception as e: #TODO catch exception properly msg.logError(e) widget = QWidget() layout = QVBoxLayout() layout.addWidget(self._device_view) widget.setLayout(layout) icon = QIcon(str(static.path('icons/calibrate.png'))) name = "Devices" super(HappiSettingsPlugin, self).__init__(icon, name, widget) self._device_view.expandAll() self.restore()
def mockjsonclient(): # Write underlying database with open('testing.json', 'w+') as handle: simplejson.dump({device_info()['prefix']: device_info()}, handle) # Return handle name db = JSONBackend('testing.json') return Client(database=db)
def test_beckoff_axis_device_class(mockqsbackend): c = Client(database=mockqsbackend) d = load_devices(*c.all_items).__dict__ vh_y = d.get('vh_y') sam_x = d.get('sam_x') assert vh_y.__class__.__name__ == 'BeckhoffAxis' assert sam_x.__class__.__name__ == 'IMS'
def test_qsbackend_with_acromag(mockqsbackend): c = Client(database=mockqsbackend) d = load_devices(*c.all_devices, pprint=False).__dict__ ai1 = d.get('ai_7') ao1 = d.get('ao_6') assert ai1.__class__.__name__ == 'EpicsSignalRO' assert ao1.__class__.__name__ == 'EpicsSignal'
def mockjsonclient(item_info: Dict[str, Any]): # Write underlying database with tempfile.NamedTemporaryFile(mode='w') as handle: simplejson.dump({item_info['name']: item_info}, handle) handle.flush() # flush buffer to write file # Return handle name db = JSONBackend(handle.name) yield Client(database=db)
def mockmongoclient(item_info: Dict[str, Any]): with patch('happi.backends.mongo_db.MongoClient') as mock_mongo: mc = MongoClient() mc['test_db'].create_collection('test_collect') mock_mongo.return_value = mc # Client backend = MongoBackend(db='test_db', collection='test_collect') client = Client(database=backend) # Insert a single device client.backend._collection.insert_one(item_info) return client
def test_qsbackend_with_client(mockqsbackend): c = Client(database=mockqsbackend) assert len(c.all_items) == 14 assert all( d.__class__.__name__ in {'Trigger', 'Motor', 'Acromag', 'LCLSItem'} for d in c.all_items) device_types = [device.__class__.__name__ for device in c.all_items] assert device_types.count('Motor') == 7 assert device_types.count('Trigger') == 2 # Acromag: six entries, but one erroneously has the same name assert device_types.count('Acromag') == 5
def test_qsbackend_with_client(mockqsbackend): from pcdsdevices.device_types import Motor, Trigger, Acromag c = Client(database=mockqsbackend) assert len(c.all_devices) == 14 assert all([ isinstance(d, Motor) or isinstance(d, Trigger) or isinstance(d, Acromag) for d in c.all_devices ]) device_types = [device.__class__ for device in c.all_devices] assert device_types.count(Motor) == 6 assert device_types.count(Trigger) == 2 assert device_types.count(Acromag) == 6
def make_tile_configs(tile, directory, dbpath): """ Write TILE IOC configs based on database entries. """ # Hack in our test device types registry._registry['pcdsdevices.Elliptec'] = Elliptec registry._reverse_registry[Elliptec] = 'pcdsdevices.Elliptec' registry._registry['pcdsdevices.Qmini'] = Qmini registry._reverse_registry[Qmini] = 'pcdsdevices.Qmini' registry._registry['pcdsdevices.SmarActMotor'] = SmarActMotor registry._reverse_registry[SmarActMotor] = 'pcdsdevices.SmarActMotor' registry._registry['pcdsdevices.SmarActTipTiltMotor'] = SmarActTipTiltMotor registry._reverse_registry[SmarActTipTiltMotor] = \ 'pcdsdevices.SmarActTipTiltMotor' registry._registry['pcdsdevices.LasBasler'] = LasBasler registry._reverse_registry[LasBasler] = 'pcdsdevices.LasBasler' registry._registry['pcdsdevices.ThorlabsWfs'] = ThorlabsWfs registry._reverse_registry[ThorlabsWfs] = 'pcdsdevices.ThorlabsWfs' registry._registry['pcdsdevices.ThorlabsPM101PowerMeter'] = \ ThorlabsPM101PowerMeter registry._reverse_registry[ThorlabsPM101PowerMeter] = \ 'pcdsdevices.ThorlabsPM101PowerMeter' registry._registry['pcdsdevices.EnvironmentalMontior'] = \ EnvironmentalMonitor registry._reverse_registry[EnvironmentalMonitor] = \ 'pcdsdevices.EnvironmentalMonitor' # Just use our test devices for now if tile not in ['lm1k4_com']: raise ValueError("Unrecognized TILE {}".format(tile)) client = Client(path=dbpath) results = client.search(location_group=tile) for dev in dev_map.keys(): # Aggregate devices based on container type devs = [result for result in results if result['type'] == dev] print("Found {} devices of type {}".format(len(devs), dev)) func = dev_map[devs[0]['type']] func(devs, directory)
def test_qsbackend_with_client(mockqsbackend): c = Client(database=mockqsbackend) assert len(c.all_devices) == 6 assert all([isinstance(d, Motor) for d in c.all_devices])
def client(): client = Client(path=os.path.join(os.path.dirname(__file__), 'happi.json')) register_client(client) return client
def test_qsbackend_with_client(mockqsbackend): c = Client(database=mockqsbackend) assert len(c.all_devices) == 6 assert all([ d.device_class == 'pcdsdevices.epics_motor.IMS' for d in c.all_devices ])