1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
import unittest
import os
import imagesize
try:
from pathlib import Path
except ImportError:
# Python 2
Path = None
imagedir = os.path.join(os.path.dirname(__file__), "images")
imagedir_bytes = imagedir.encode("utf-8")
class GetDPITest(unittest.TestCase):
def test_png(self):
xdpi, ydpi = imagesize.getDPI(os.path.join(imagedir, "test.png"))
self.assertEqual(xdpi, 72)
self.assertEqual(ydpi, 72)
def test_jpeg(self):
xdpi, ydpi = imagesize.getDPI(os.path.join(imagedir, "test.jpg"))
self.assertEqual(xdpi, 72)
self.assertEqual(ydpi, 72)
def test_jpeg2000(self):
xdpi, ydpi = imagesize.getDPI(os.path.join(imagedir, "test.jp2"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
def test_gif(self):
xdpi, ydpi = imagesize.getDPI(os.path.join(imagedir, "test.gif"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
def test_bigendian_tiff(self):
xdpi, ydpi = imagesize.getDPI(os.path.join(imagedir, "test.tiff"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
def test_svg(self):
xdpi, ydpi = imagesize.getDPI(os.path.join(imagedir, "test.svg"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
def test_littleendian_tiff(self):
xdpi, ydpi = imagesize.getDPI(os.path.join(imagedir, "multipage_tiff_example.tif"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
def test_png_bytes(self):
xdpi, ydpi = imagesize.getDPI(os.path.join(imagedir_bytes, b"test.png"))
self.assertEqual(xdpi, 72)
self.assertEqual(ydpi, 72)
def test_jpeg_bytes(self):
xdpi, ydpi = imagesize.getDPI(os.path.join(imagedir_bytes, b"test.jpg"))
self.assertEqual(xdpi, 72)
self.assertEqual(ydpi, 72)
def test_jpeg2000_bytes(self):
xdpi, ydpi = imagesize.getDPI(os.path.join(imagedir_bytes, b"test.jp2"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
def test_gif_bytes(self):
xdpi, ydpi = imagesize.getDPI(os.path.join(imagedir_bytes, b"test.gif"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
def test_bigendian_tiff_bytes(self):
xdpi, ydpi = imagesize.getDPI(os.path.join(imagedir_bytes, b"test.tiff"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
def test_svg_bytes(self):
xdpi, ydpi = imagesize.getDPI(os.path.join(imagedir_bytes, b"test.svg"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
def test_littleendian_tiff_bytes(self):
xdpi, ydpi = imagesize.getDPI(os.path.join(imagedir_bytes, b"multipage_tiff_example.tif"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
@unittest.skipIf(Path is None, "requires pathlib support")
def test_png_path(self):
xdpi, ydpi = imagesize.getDPI(Path(imagedir, "test.png"))
self.assertEqual(xdpi, 72)
self.assertEqual(ydpi, 72)
@unittest.skipIf(Path is None, "requires pathlib support")
def test_jpeg_path(self):
xdpi, ydpi = imagesize.getDPI(Path(imagedir, "test.jpg"))
self.assertEqual(xdpi, 72)
self.assertEqual(ydpi, 72)
@unittest.skipIf(Path is None, "requires pathlib support")
def test_jpeg2000_path(self):
xdpi, ydpi = imagesize.getDPI(Path(imagedir, "test.jp2"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
@unittest.skipIf(Path is None, "requires pathlib support")
def test_gif_path(self):
xdpi, ydpi = imagesize.getDPI(Path(imagedir, "test.gif"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
@unittest.skipIf(Path is None, "requires pathlib support")
def test_bigendian_tiff_path(self):
xdpi, ydpi = imagesize.getDPI(Path(imagedir, "test.tiff"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
@unittest.skipIf(Path is None, "requires pathlib support")
def test_svg_path(self):
xdpi, ydpi = imagesize.getDPI(Path(imagedir, "test.svg"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
@unittest.skipIf(Path is None, "requires pathlib support")
def test_littleendian_tiff_path(self):
xdpi, ydpi = imagesize.getDPI(Path(imagedir, "multipage_tiff_example.tif"))
self.assertEqual(xdpi, -1)
self.assertEqual(ydpi, -1)
|