def test_containment(self): """Checks the __contains/getitem/setitem__ methods.""" with tempfile.TemporaryDirectory() as tmpdirname: with mock.patch("pitivi.timeline.previewers.xdg_cache_home" ) as xdg_cache_home: xdg_cache_home.return_value = tmpdirname sample_uri = common.get_sample_uri("1sec_simpsons_trailer.mp4") thumb_cache = ThumbnailCache(sample_uri) self.assertFalse(Gst.SECOND in thumb_cache) with self.assertRaises(KeyError): # pylint: disable=pointless-statement thumb_cache[Gst.SECOND] pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, False, 8, int(THUMB_HEIGHT * 1280 / 544), THUMB_HEIGHT) thumb_cache[Gst.SECOND] = pixbuf self.assertTrue(Gst.SECOND in thumb_cache) self.assertIsNotNone(thumb_cache[Gst.SECOND]) thumb_cache.commit() thumb_cache = ThumbnailCache(sample_uri) self.assertTrue(Gst.SECOND in thumb_cache) self.assertIsNotNone(thumb_cache[Gst.SECOND])
def test_image_size(self): """Checks the `image_size` property.""" with tempfile.TemporaryDirectory() as tmpdirname: with mock.patch("pitivi.timeline.previewers.xdg_cache_home" ) as xdg_cache_home: xdg_cache_home.return_value = tmpdirname sample_uri = common.get_sample_uri("1sec_simpsons_trailer.mp4") thumb_cache = ThumbnailCache(sample_uri) self.assertEqual(thumb_cache.image_size, (None, None)) pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, False, 8, 20, 10) thumb_cache[0] = pixbuf self.assertEqual(thumb_cache.image_size, (20, 10))
def testCache(self): c = ThumbnailCache(self.uri, size=32) for i in xrange(0, 64): c[i] = cairo.ImageSurface(cairo.FORMAT_RGB24, 10, 10) assert len(c.cache) == 32 # 31 should be in the Database, but not in the memory direct cache assert not 31 in c.cache assert 31 in c # 32 is in both assert 32 in c.cache # touch the LRU item, and then add something to the queue # the item should still remain in the queue c[32] c[65] = cairo.ImageSurface(cairo.FORMAT_RGB24, 10, 10) assert 32 in c assert 33 not in c.cache