File: test_get.py

package info (click to toggle)
python-imagesize 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,692 kB
  • sloc: python: 599; sh: 6; makefile: 3
file content (147 lines) | stat: -rw-r--r-- 5,389 bytes parent folder | download
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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 GetTest(unittest.TestCase):
    def test_load_png(self):
        width, height = imagesize.get(os.path.join(imagedir, "test.png"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    def test_load_jpeg(self):
        width, height = imagesize.get(os.path.join(imagedir, "test.jpg"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    def test_load_jpeg2000(self):
        width, height = imagesize.get(os.path.join(imagedir, "test.jp2"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    def test_load_gif(self):
        width, height = imagesize.get(os.path.join(imagedir, "test.gif"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    def test_bigendian_tiff(self):
        width, height = imagesize.get(os.path.join(imagedir, "test.tiff"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    def test_load_svg(self):
        width, height = imagesize.get(os.path.join(imagedir, "test.svg"))
        self.assertEqual(width, 90)
        self.assertEqual(height, 60)

    def test_littleendian_tiff(self):
        width, height = imagesize.get(os.path.join(imagedir, "multipage_tiff_example.tif"))
        self.assertEqual(width, 800)
        self.assertEqual(height, 600)

    def test_load_png_filelike(self):
        """ test_load_png_filelike
        """
        from io import BytesIO

        _ = os.path.join(imagedir, "test.png")
        with open(_, "rb") as fhandle:
            filelike = BytesIO(fhandle.read())

        width, height = imagesize.get(filelike)
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    def test_netpbm(self):
        for test_type in ["test", "test-ascii"]:
            for test_ext in ["pbm", "pgm", "ppm"]:
                test_file = os.path.join(imagedir, "{}.{}".format(test_type, test_ext))
                width, height = imagesize.get(test_file)
                self.assertEqual(width, 65)
                self.assertEqual(height, 20)

    def test_load_png_bytes(self):
        width, height = imagesize.get(os.path.join(imagedir_bytes, b"test.png"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    def test_load_jpeg_bytes(self):
        width, height = imagesize.get(os.path.join(imagedir_bytes, b"test.jpg"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    def test_load_jpeg2000_bytes(self):
        width, height = imagesize.get(os.path.join(imagedir_bytes, b"test.jp2"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    def test_load_gif_bytes(self):
        width, height = imagesize.get(os.path.join(imagedir_bytes, b"test.gif"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    def test_bigendian_tiff_bytes(self):
        width, height = imagesize.get(os.path.join(imagedir_bytes, b"test.tiff"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    def test_load_svg_bytes(self):
        width, height = imagesize.get(os.path.join(imagedir_bytes, b"test.svg"))
        self.assertEqual(width, 90)
        self.assertEqual(height, 60)

    def test_littleendian_tiff_bytes(self):
        width, height = imagesize.get(os.path.join(imagedir_bytes, b"multipage_tiff_example.tif"))
        self.assertEqual(width, 800)
        self.assertEqual(height, 600)

    @unittest.skipIf(Path is None, "requires pathlib support")
    def test_load_png_path(self):
        width, height = imagesize.get(Path(imagedir, "test.png"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    @unittest.skipIf(Path is None, "requires pathlib support")
    def test_load_jpeg_path(self):
        width, height = imagesize.get(Path(imagedir, "test.jpg"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    @unittest.skipIf(Path is None, "requires pathlib support")
    def test_load_jpeg2000_path(self):
        width, height = imagesize.get(Path(imagedir, "test.jp2"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    @unittest.skipIf(Path is None, "requires pathlib support")
    def test_load_gif_path(self):
        width, height = imagesize.get(Path(imagedir, "test.gif"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    @unittest.skipIf(Path is None, "requires pathlib support")
    def test_bigendian_tiff_path(self):
        width, height = imagesize.get(Path(imagedir, "test.tiff"))
        self.assertEqual(width, 802)
        self.assertEqual(height, 670)

    @unittest.skipIf(Path is None, "requires pathlib support")
    def test_load_svg_path(self):
        width, height = imagesize.get(Path(imagedir, "test.svg"))
        self.assertEqual(width, 90)
        self.assertEqual(height, 60)

    @unittest.skipIf(Path is None, "requires pathlib support")
    def test_littleendian_tiff_path(self):
        width, height = imagesize.get(Path(imagedir, "multipage_tiff_example.tif"))
        self.assertEqual(width, 800)
        self.assertEqual(height, 600)