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
|
"""
Part of the bsie test suite.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# standard imports
import os
import unittest
# external imports
import PIL.Image
# objects to test
from bsie.reader.preview.utils import resize
## code ##
class TestUtils(unittest.TestCase):
def test_resize(self):
img = PIL.Image.open(os.path.join(os.path.dirname(__file__), 'testimage.jpg'))
landscape = img.resize((100, 80))
portrait = img.resize((80, 100))
self.assertEqual(img.size, (100, 100))
self.assertEqual(landscape.size, (100, 80))
self.assertEqual(portrait.size, (80, 100))
# resize can downscale
self.assertEqual(resize(img, 10).size, (10, 10))
self.assertEqual(resize(img, 20).size, (20, 20))
# resize can upscale
self.assertEqual(resize(img, 200).size, (200, 200))
# aspect ratio is preserved
self.assertEqual(resize(landscape, 10).size, (10, 8))
self.assertEqual(resize(portrait, 10).size, (8, 10))
## main ##
if __name__ == '__main__':
unittest.main()
## EOF ##
|