def test_cache_dir_already_exists(self): ident = 'id1' image_info = img_info.ImageInfo(None) image_info.width = 100 image_info.height = 100 image_request = img.ImageRequest(ident, 'full', 'full', '0', 'default', 'jpg') self.app.img_cache.create_dir_and_return_file_path(image_request, image_info) #call request again, so cache directory should already be there # throws an exception if we don't handle that existence properly self.app.img_cache.create_dir_and_return_file_path(image_request, image_info)
def test_precinct_jp2_tiles_from_image(self): fp = self.test_jp2_with_precincts_fp fmt = self.test_jp2_with_precincts_fmt ident = self.test_jp2_with_precincts_id uri = self.test_jp2_with_precincts_uri info = img_info.ImageInfo(self.app, uri, fp, fmt) self.assertEqual(info.tiles, self.test_jp2_with_precincts_tiles) self.assertEqual(info.sizes, self.test_jp2_with_precincts_sizes)
def test_is_canonical(self, args, is_canonical): info = img_info.ImageInfo(None) info.width = 100 info.height = 100 request = img.ImageRequest(*args) request.info = info # Called twice for caching behaviour assert request.is_canonical == is_canonical assert request.is_canonical == is_canonical
def test_extract_icc_profile_from_jp2(self): fp = self.test_jp2_with_embedded_profile_fp fmt = self.test_jp2_with_embedded_profile_fmt ident = self.test_jp2_with_embedded_profile_id uri = self.test_jp2_with_embedded_profile_uri profile_copy_fp = self.test_jp2_embedded_profile_copy_fp info = img_info.ImageInfo(self.app, uri, fp, fmt) with open(self.test_jp2_embedded_profile_copy_fp, 'rb') as fixture_bytes: self.assertEqual(info.color_profile_bytes, fixture_bytes.read())
def test_color_jp2_info_from_image(self): fp = self.test_jp2_color_fp fmt = self.test_jp2_color_fmt ident = self.test_jp2_color_id uri = self.test_jp2_color_uri profile = ["http://iiif.io/api/image/2/level2.json", { "formats": [ "jpg", "png", "gif", "webp", "tif" ], "qualities": [ "default", "bitonal", "gray", "color" ], "supports": [ "canonicalLinkHeader", "profileLinkHeader", "mirroring", "rotationArbitrary", "regionSquare" ] } ] #test that sizeAboveFull isn't in profile if max_size_above_full is > 0 and <= 100 self.app.max_size_above_full = 80 info = img_info.ImageInfo(self.app, uri, fp, fmt) self.assertEqual(info.width, self.test_jp2_color_dims[0]) self.assertEqual(info.height, self.test_jp2_color_dims[1]) self.assertEqual(info.profile.compliance_uri, profile[0]) self.assertEqual(info.profile.description, profile[1]) self.assertEqual(info.tiles, self.test_jp2_color_tiles) self.assertEqual(info.sizes, self.test_jp2_color_sizes) self.assertEqual(info.ident, uri) self.assertEqual(info.protocol, PROTOCOL) self.app.max_size_above_full = 0 info = img_info.ImageInfo(self.app, uri, fp, fmt) self.assertTrue('sizeAboveFull' in info.profile.description['supports']) self.app.max_size_above_full = 200
def test_missing_src_file_causes_cache_miss(self): with tempfile.TemporaryDirectory() as tmp: cache = img_info.InfoCache(root=tmp) jpeg_fp = os.path.join(tmp, 'will_be_removed.jpeg') shutil.copyfile(self.test_jpeg_fp, jpeg_fp) info = img_info.ImageInfo(app=self.app, src_img_fp=jpeg_fp, src_format=self.test_jpeg_fmt) cache[self.test_jpeg_id] = info os.remove(jpeg_fp) with pytest.raises(KeyError): cache[self.test_jpeg_id]
def test_creates_cache_dir(self): with tempfile.TemporaryDirectory() as tmp: root = os.path.join(tmp, "doesnotexist") assert not os.path.exists(root) cache = img_info.InfoCache(root=root) info = img_info.ImageInfo(app=self.app, src_img_fp=self.test_jpeg_fp, src_format=self.test_jpeg_fmt) cache[self.test_jpeg_id] = info assert cache[self.test_jpeg_id][0] == info
def _cache_with_ident(self): """ Returns a tuple: an ``InfoCache`` with a single entry, and the key. """ cache = img_info.InfoCache(root=self.SRC_IMAGE_CACHE) info = img_info.ImageInfo(app=self.app, src_img_fp=self.test_jp2_color_fp, src_format=self.test_jp2_color_fmt) cache[self.test_jp2_color_id] = info return (cache, self.test_jp2_color_id)
def _cache_with_request(self): """ Returns a tuple: an ``InfoCache`` with a single entry, and the key. """ cache = img_info.InfoCache(root=self.SRC_IMAGE_CACHE) path = self.test_jp2_color_fp req = webapp_t._get_werkzeug_request(path=path) info = img_info.ImageInfo(self.app, self.test_jp2_color_uri, self.test_jp2_color_fp, self.test_jp2_color_fmt) cache[req] = info return (cache, req)
def test_creates_cache_dir(self): root = os.path.join(tempfile.mkdtemp(), "doesnotexist") assert not os.path.exists(root) cache = img_info.InfoCache(root=root) path = self.test_jpeg_fp req = webapp_t._get_werkzeug_request(path=path) info = img_info.ImageInfo(app=self.app, ident=self.test_jpeg_uri, src_img_fp=self.test_jpeg_fp, src_format=self.test_jpeg_fmt) cache[req] = info assert cache[req][0] == info
def test_can_delete_items_from_infocache(self): ''' Test for InfoCache.__delitem__. ''' cache = img_info.InfoCache(root=self.SRC_IMAGE_CACHE) path = self.test_jp2_color_fp req = webapp_t._get_werkzeug_request(path=path) # app = MockApp() info = img_info.ImageInfo(self.app, self.test_jp2_color_uri, self.test_jp2_color_fp, self.test_jp2_color_fmt) cache[req] = info del cache[req]
def test_tiff_info_from_image(self): fp = self.test_tiff_fp fmt = self.test_tiff_fmt ident = self.test_tiff_id uri = self.test_tiff_uri info = img_info.ImageInfo(app=self.app, src_img_fp=fp, src_format=fmt) profile = [ "http://iiif.io/api/image/2/level2.json", { "formats": ["jpg", "png", "gif", "webp", "tif"], "qualities": ["default", "color", "gray", "bitonal"], "supports": [ "canonicalLinkHeader", "profileLinkHeader", "mirroring", "rotationArbitrary", "regionSquare", "sizeAboveFull" ] } ] self.assertEqual(info.width, self.test_tiff_dims[0]) self.assertEqual(info.height, self.test_tiff_dims[1]) self.assertEqual(info.sizes, self.test_tiff_sizes) self.assertEqual(info.profile.compliance_uri, profile[0]) self.assertEqual(info.profile.description, profile[1])
def build_image_info(width=100, height=100): """Produces an ``ImageInfo`` object of the given dimensions.""" info = img_info.ImageInfo() info.width = width info.height = height return info