def test_export(happi_client: Client, valve: OphydItem): # Setup client with both items happi_client.add_item(valve) fd, temp_path = tempfile.mkstemp() happi_client.export(open(temp_path, 'w+'), sep=',', attrs=['name', 'prefix']) exp = open(temp_path, 'r').read() assert "alias,BASE:PV" in exp assert "name,BASE:VGC:PV" in exp # Cleanup os.remove(temp_path) os.close(fd)
def test_search_range(happi_client: Client, valve: OphydItem): happi_client.add_item(valve) # Search between two points res = happi_client.search_range('z', start=0, end=500) assert len(res) == 2 # Search between two points, nothing found res = happi_client.search_range('z', start=10000, end=500000) assert not res # Search without an endpoint res = happi_client.search_range('z', start=0) assert len(res) == 2 # Search invalid range with pytest.raises(ValueError): happi_client.search_range('z', start=1000, end=5)
def test_search(happi_client: Client, valve: OphydItem, item_info: Dict[str, Any]): happi_client.add_item(valve) res = happi_client.search(name=item_info['name']) # Single search return assert len(res) == 1 loaded_item = res[0].item assert loaded_item.prefix == item_info['prefix'] assert loaded_item.name == item_info['name'] # No results assert not happi_client.search(name='not') # Returned as dict res = happi_client.search(**item_info) loaded_item = res[0].item assert loaded_item['prefix'] == item_info['prefix'] assert loaded_item['name'] == item_info['name'] # Search off keyword res = happi_client.search(beamline='LCLS') assert len(res) == 2
def test_add_item(happi_client: Client, valve: OphydItem): happi_client.add_item(valve) # No duplicates with pytest.raises(DuplicateError): happi_client.add_item(valve) # No incompletes d = OphydItem() with pytest.raises(EntryError): happi_client.add_item(d)
def test_get_by_id(happi_client: Client, valve: OphydItem, valve_info: Dict[str, Any]): happi_client.add_item(valve) name = valve_info['name'] for k, v in valve_info.items(): assert happi_client[name][k] == valve_info[k]
def test_add_and_find_item(happi_client: Client, valve: OphydItem, valve_info: Dict[str, Any]): happi_client.add_item(valve) loaded_item = happi_client.find_item(**valve_info) assert loaded_item.prefix == valve.prefix assert loaded_item.name == valve.name