Source code for tests.test_formats_mat_zip

#!/usr/bin/env python3

"""Test zip archive
"""

import unittest
import os.path
import tempfile
import numpy as np
import argparse

from .context import imagedata
import imagedata.cmdline
import imagedata.readdata
import imagedata.formats
from imagedata.series import Series


[docs]class TestMatZipRead(unittest.TestCase):
[docs] def setUp(self): parser = argparse.ArgumentParser() imagedata.cmdline.add_argparse_options(parser) self.opts = parser.parse_args([]) if len(self.opts.output_format) < 1: self.opts.output_format = ['mat']
# @unittest.skip("skipping test_read_single_file")
[docs] def test_read_single_file(self): si1 = Series( os.path.join('data', 'mat', 'time.zip?time/Image_00000.mat'), 'none', self.opts) self.assertEqual(si1.dtype, np.uint16) self.assertEqual(si1.shape, (10, 40, 192, 152))
# @unittest.skip("skipping test_read_single_file_wildcard")
[docs] def test_read_single_file_wildcard(self): si1 = Series( os.path.join('data', 'mat', 'time.zip?*Image_00000.mat'), 'none', self.opts) self.assertEqual(si1.dtype, np.uint16) self.assertEqual(si1.shape, (10, 40, 192, 152))
# @unittest.skip("skipping test_read_single_file_relative")
[docs] def test_read_single_file_relative(self): si1 = Series( os.path.join('data', 'mat', 'time.zip?time/Image_00000.mat'), 'none', self.opts) self.assertEqual(si1.dtype, np.uint16) self.assertEqual(si1.shape, (10, 40, 192, 152))
[docs] @unittest.skip("skipping test_read_two_files") def test_read_two_files(self): si1 = Series( os.path.join('data', 'mat', 'time.zip?*Image_0000[01].mat'), imagedata.formats.INPUT_ORDER_TIME, self.opts) self.assertEqual(si1.dtype, np.uint16) self.assertEqual(si1.shape, (2, 40, 192, 152))
# @unittest.skip("skipping test_read_single_directory")
[docs] def test_read_single_directory(self): si1 = Series( os.path.join('data', 'mat', 'time.zip?time'), imagedata.formats.INPUT_ORDER_TIME, self.opts) self.assertEqual(si1.dtype, np.uint16) self.assertEqual(si1.shape, (10, 40, 192, 152))
# @unittest.skip("skipping test_read_all_files")
[docs] def test_read_all_files(self): si1 = Series( os.path.join('data', 'mat', 'time.zip'), imagedata.formats.INPUT_ORDER_TIME, self.opts) self.assertEqual(si1.dtype, np.uint16) self.assertEqual(si1.shape, (10, 40, 192, 152))
[docs]class TestMatZipWrite(unittest.TestCase):
[docs] def setUp(self): parser = argparse.ArgumentParser() imagedata.cmdline.add_argparse_options(parser) self.opts = parser.parse_args([]) if len(self.opts.output_format) < 1: self.opts.output_format = ['mat']
# @unittest.skip("skipping test_write_single_file")
[docs] def test_write_single_file(self): si1 = Series( os.path.join('data', 'mat', 'time.zip?time/Image_00000.mat')) with tempfile.TemporaryDirectory() as d: si1.write(os.path.join(d, 'mat.zip'), formats=['mat']) si2 = Series(os.path.join(d, 'mat.zip?Image_00000.mat')) self.assertEqual(si1.dtype, si2.dtype) self.assertEqual(si1.shape, si2.shape)
# @unittest.skip("skipping test_write_all_files")
[docs] def test_write_all_files(self): si1 = Series( os.path.join('data', 'mat', 'time.zip'), imagedata.formats.INPUT_ORDER_TIME, self.opts) with tempfile.TemporaryDirectory() as d: si1.write(os.path.join(d, 'mat.zip'), formats=['mat']) si2 = Series(os.path.join(d, 'mat.zip'), imagedata.formats.INPUT_ORDER_TIME, self.opts) self.assertEqual(si1.dtype, si2.dtype) self.assertEqual(si1.shape, si2.shape)
if __name__ == '__main__': unittest.main()