示例#1
0
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
示例#2
0
    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
示例#3
0
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()
示例#4
0
async def test_singleton():
    """Verifies rat_cache acts as a singleton"""
    alpha = RatCache()
    beta = RatCache()
    assert alpha is beta
示例#5
0
async def test_by_name_setter_garbage(rat_cache_fx: RatCache, garbage):
    with pytest.raises(TypeError):
        rat_cache_fx.by_name = garbage
示例#6
0
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
示例#7
0
def rat_cache_fx():
    """provides a empty rat_cache"""
    return RatCache()