42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
# Copyright 2023 (c) Anna Schumaker.
|
|
"""Tests our Gdk.Texture cache."""
|
|
import emmental.texture
|
|
import pathlib
|
|
import tests.util
|
|
import unittest
|
|
from gi.repository import Gdk
|
|
|
|
|
|
class TestTextureCache(unittest.TestCase):
|
|
"""Test our custom cache dictionary."""
|
|
|
|
def setUp(self):
|
|
"""Set up common variables."""
|
|
self.cache = emmental.texture._TextureCache()
|
|
|
|
def test_init(self):
|
|
"""Test that the cache dict is initialized properly."""
|
|
self.assertIsInstance(emmental.texture.CACHE,
|
|
emmental.texture._TextureCache)
|
|
self.assertDictEqual(emmental.texture.CACHE, {})
|
|
|
|
self.assertIsInstance(self.cache, dict)
|
|
self.assertDictEqual(self.cache, {})
|
|
|
|
def test_drop(self):
|
|
"""Test dropping items from the cache."""
|
|
self.cache[tests.util.COVER_JPG]
|
|
self.cache.drop(tests.util.COVER_JPG)
|
|
self.assertDictEqual(self.cache, {})
|
|
|
|
def test_getitem(self):
|
|
"""Test getting and creating items in the cache dict."""
|
|
self.assertIsNone(self.cache[None])
|
|
self.assertIsNone(self.cache[pathlib.Path("/no/such/path")])
|
|
self.assertDictEqual(self.cache, {})
|
|
|
|
texture = self.cache[tests.util.COVER_JPG]
|
|
self.assertIsInstance(texture, Gdk.Texture)
|
|
self.assertDictEqual(self.cache, {tests.util.COVER_JPG: texture})
|
|
self.assertEqual(self.cache[tests.util.COVER_JPG], texture)
|