def test_is_image_format(self): image_format_extensions = ( 'tif', 'tiff', 'jpg', 'jpeg', 'tif', 'tiff', 'png', 'jpg' ) for ext in image_format_extensions: mime_type = MimeType(MimeType.canonical_extension(ext)) self.assertTrue(MimeType.is_image_format(mime_type), msg="Expected MIME type {} to be an image format".format(mime_type.value))
def test_canonical_extension(self): extension_pairs = (('tiff', 'tiff'), ('tif', 'tiff'), ('jpg', 'jpg'), ('jpeg', 'jpg'), ('png', 'png'), ('jp2', 'jp2'), ('txt', 'txt'), ('h5', 'hdf'), ('hdf', 'hdf'), ('hdf5', 'hdf')) for ext, canon in extension_pairs: res = MimeType.canonical_extension(ext) self.assertEqual(canon, res, msg="Expected {}, got {}".format(canon, res))
def test_get_string(self): type_string_pairs = ( (MimeType.PNG, 'image/png'), (MimeType.JPG, 'image/jpeg'), (MimeType.TIFF, 'image/tiff'), (MimeType.TIFF_d32f, 'image/tiff;depth=32f'), (MimeType.JSON, 'application/json'), (MimeType.CSV, 'text/csv'), (MimeType.ZIP, 'application/zip'), (MimeType.HDF, 'application/x-hdf'), (MimeType.XML, 'application/xml'), (MimeType.TXT, 'text/plain') ) for img_type, img_str in type_string_pairs: res = MimeType.get_string(img_type) self.assertEqual(img_str, res, msg="Expected {}, got {}".format(img_str, res))