async def test_flush(rat_cache_fx: RatCache): rat_cache_fx.by_name = {"s": 12} rat_cache_fx.by_uuid = {uuid4(): 12} rat_cache_fx.flush() assert {} == rat_cache_fx.by_uuid assert {} == rat_cache_fx.by_name
def __init__(self, uuid: UUID, name: str = None, platform: Optional[Platforms] = None): """ Creates a new rat Args: uuid (UUID): name (str): rat's name platform (Platforms): rat's platform """ # set our properties self._platform = platform self._uuid = uuid self._name = name self._hash = None # and update the cache, should it exist if name and name not in RatCache().by_name: # don't register duplicates RatCache().by_name[name] = self if uuid not in RatCache().by_uuid: # don't register duplicates RatCache().by_uuid[uuid] = self
def reset_rat_cache_fx(rat_cache_fx: RatCache): """"cleans up the rat_cache's cache""" # ensure the cache is clean during setup rat_cache_fx.flush() yield # and clean up after ourselves rat_cache_fx.flush()
async def test_singleton(): """Verifies rat_cache acts as a singleton""" alpha = RatCache() beta = RatCache() assert alpha is beta
async def test_by_name_setter_garbage(rat_cache_fx: RatCache, garbage): with pytest.raises(TypeError): rat_cache_fx.by_name = garbage
async def test_by_uuid_setter_valid(rat_cache_fx: RatCache, rat_good_fx: Rat): fdict = {rat_good_fx.uuid: rat_good_fx} rat_cache_fx.by_uuid = fdict assert fdict == rat_cache_fx.by_uuid
def rat_cache_fx(): """provides a empty rat_cache""" return RatCache()