コード例 #1
0
    def test_setitem_value_type_error(self):
        cache = char_image_cache.CharImageCache(self.BASE_PATH)
        char = entity.Char()

        with pytest.raises(TypeError,
                           match=r"Invalid value type <class 'int'>"):
            cache[char] = 1
コード例 #2
0
    def test_getitem_empty(self):
        cache = char_image_cache.CharImageCache(self.BASE_PATH)
        char = entity.Char()

        with pytest.raises(
                KeyError,
                match=r"Character with char_id None is not in the cache"):
            cache[char]
コード例 #3
0
    def test_entry_timeout(self):
        cache = char_image_cache.CharImageCache(self.BASE_PATH,
                                                entry_timeout=0.5)
        char = entity.Char()

        cache[char] = "blah"
        assert char in cache
        time.sleep(0.55)
        assert char not in cache
コード例 #4
0
    def test_setitem(self):
        cache = char_image_cache.CharImageCache(self.BASE_PATH)
        char = entity.Char()

        cache[char] = "blah"

        assert cache.cache[char.char_id].char == char
        assert cache.cache[char.char_id].timestamp is not None
        assert cache.cache[char.char_id].image_path == "blah"
コード例 #5
0
    def test_online(self):
        cache = char_image_cache.CharImageCache(self.BASE_PATH)
        char = entity.Char()
        char.online = False

        cache[char] = "blah"
        assert char in cache

        char.online = True
        assert char not in cache
コード例 #6
0
    def test_getitem(self):
        cache = char_image_cache.CharImageCache(self.BASE_PATH)
        char = entity.Char()
        cache[char] = "blah"

        assert cache[char] == "blah"
コード例 #7
0
    def test_getitem_key_type_error(self):
        cache = char_image_cache.CharImageCache(self.BASE_PATH)

        with pytest.raises(TypeError, match=r"Invalid key type <class 'int'>"):
            cache[1]
コード例 #8
0
    def test_contains_empty(self):
        cache = char_image_cache.CharImageCache(self.BASE_PATH)
        char = entity.Char()

        assert char not in cache
        str
コード例 #9
0
    def test_constructor_with_entry_timeout(self):
        cache = char_image_cache.CharImageCache(self.BASE_PATH,
                                                entry_timeout=20)

        assert cache.base_path == self.BASE_PATH
        assert cache.entry_timeout == 20
コード例 #10
0
    def test_constructor_no_entry_timeout(self):
        cache = char_image_cache.CharImageCache(self.BASE_PATH)

        assert cache.base_path == self.BASE_PATH
        assert cache.entry_timeout == char_image_cache.CharImageCache.DEFAULT_ENTRY_TIMEOUT