File: imageio_formats_test.py

package info (click to toggle)
python-sigima 1.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 24,956 kB
  • sloc: python: 33,326; makefile: 3
file content (41 lines) | stat: -rw-r--r-- 1,428 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
# Copyright (c) DataLab Platform Developers, BSD 3-Clause license, see LICENSE file.

"""
Testing image format handling based on the `imageio_formats` option.
"""

# Note about the modules imported outside top-level:
#
# We want to keep the import order under control, so we import the modules only when
# they are needed, especially for the dynamically defined image formats in the `formats`
# module. This way, we can ensure that the formats are defined just before we use them
# in the tests. This is particularly useful for testing the `imageio_formats` option
# that allows users to set custom image I/O formats.


def get_image_formats():
    """Get image formats"""
    # pylint: disable=import-outside-toplevel
    from sigima.io.image import formats

    return [clname for clname in dir(formats) if clname.endswith("ImageFormat")]


def test_imageio_formats_option():
    """Set other image I/O formats"""
    # pylint: disable=import-outside-toplevel
    from sigima.config import options
    from sigima.io.image import formats

    # Set custom image I/O formats
    options.imageio_formats.set((("*.rec", "PCO Camera REC"),))
    # Check if the formats are set correctly
    assert hasattr(formats, "RECImageFormat"), "RECImageFormat not found in formats"


if __name__ == "__main__":
    from pprint import pprint

    pprint(get_image_formats())
    test_imageio_formats_option()
    pprint(get_image_formats())