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