aboutsummaryrefslogtreecommitdiffstats
path: root/test/reader/image/test_image.py
blob: c60ca75a7be439c78bb3a885a4d19a9ff5232081 (plain)
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
"""

Part of the bsie test suite.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# standard imports
import importlib
import os
import unittest

# bsie imports
from bsie.utils import errors

# objects to test
from bsie.reader.image import Image


## code ##

class TestImage(unittest.TestCase):
    def setUp(self):
        importlib.import_module(__package__ + '.load_nef').get()

    def test_construct(self):
        image = Image({})
        self.assertIsInstance(image, Image)
        self.assertEqual(len(image._children), 2)

    def test_call(self):
        image = Image({})
        # call returns raw image
        img = image(os.path.join(os.path.dirname(__file__), 'testimage.nef'))
        self.assertEqual(img.size, (6016, 4016)) # FIXME: change when image was replaced
        img.close()
        # call returns jpeg image
        img = image(os.path.join(os.path.dirname(__file__), 'testimage.jpg'))
        self.assertEqual(img.size, (1, 1))
        img.close()
        # call raises error if file cannot be read
        self.assertRaises(errors.ReaderError, image,
            os.path.join(os.path.dirname(__file__), 'invalid.nef'))
        self.assertRaises(errors.ReaderError, image,
            os.path.join(os.path.dirname(__file__), 'invalid.jpg'))

## main ##

if __name__ == '__main__':
    unittest.main()

## EOF ##