File: test_fabio.py

package info (click to toggle)
python-fabio 0.14.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,068 kB
  • sloc: python: 20,053; ansic: 1,085; makefile: 217; sh: 215
file content (108 lines) | stat: -rw-r--r-- 3,541 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#    Project: Fable Input Output
#             https://github.com/silx-kit/fabio
#
#    Copyright (C) European Synchrotron Radiation Facility, Grenoble, France
#
#    Principal author:       Jérôme Kieffer (Jerome.Kieffer@ESRF.eu)
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

"""
Test the main fabio API.

Basically everything supposed to be provided by `import fabio`
"""

import unittest
import logging
import io

logger = logging.getLogger(__name__)

from .utilstest import UtilsTest
import fabio


class TestFabio(unittest.TestCase):

    def test_open(self):
        filename = UtilsTest.getimage("multiframes.edf.bz2")
        filename = filename.replace(".bz2", "")
        image = fabio.open(filename)
        image.data
        image.close()

    def test_open_bytesio(self):
        filename = UtilsTest.getimage("multiframes.edf.bz2")
        filename = filename.replace(".bz2", "")
        with io.open(filename, "rb") as f:
            data = f.read()
            mem = io.BytesIO(data)
            with fabio.open(mem) as image:
                self.assertIsNotNone(image)
                self.assertEqual(image.nframes, 8)

    def test_open_fabio_bytesio(self):
        filename = UtilsTest.getimage("multiframes.edf.bz2")
        filename = filename.replace(".bz2", "")
        with io.open(filename, "rb") as f:
            data = f.read()
            mem = fabio.fabioutils.BytesIO(data)
            with fabio.open(mem) as image:
                self.assertIsNotNone(image)
                self.assertEqual(image.nframes, 8)

    def test_open_with(self):
        filename = UtilsTest.getimage("multiframes.edf.bz2")
        filename = filename.replace(".bz2", "")
        with fabio.open(filename) as image:
            image.data

    def test_open_series(self):
        filename = UtilsTest.getimage("multiframes.edf.bz2")
        filename = filename.replace(".bz2", "")
        series = fabio.open_series(filenames=[filename])
        for _frame in series.frames():
            pass
        series.close()

    def test_open_series_with(self):
        filename = UtilsTest.getimage("multiframes.edf.bz2")
        filename = filename.replace(".bz2", "")
        with fabio.open_series(filenames=[filename]) as series:
            for _frame in series.frames():
                pass

    def test_open_series_first_filename(self):
        filename = UtilsTest.getimage("multiframes.edf.bz2")
        filename = filename.replace(".bz2", "")
        with fabio.open_series(first_filename=filename) as series:
            for _frame in series.frames():
                pass


def suite():
    loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
    testsuite = unittest.TestSuite()
    testsuite.addTest(loadTests(TestFabio))
    return testsuite


if __name__ == '__main__':
    runner = unittest.TextTestRunner()
    runner.run(suite())