You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.9 KiB

8 years ago
  1. import unittest
  2. import numpy as np
  3. from nd2reader.artificial import ArtificialND2
  4. from nd2reader.exceptions import EmptyFileError
  5. from nd2reader.reader import ND2Reader
  6. from nd2reader.parser import Parser
  7. class TestReader(unittest.TestCase):
  8. def test_extension(self):
  9. self.assertTrue('nd2' in ND2Reader.class_exts())
  10. def test_init_and_init_axes(self):
  11. with ArtificialND2('test_data/test_nd2_reader.nd2') as artificial:
  12. with ND2Reader('test_data/test_nd2_reader.nd2') as reader:
  13. attributes = artificial.data['image_attributes']['SLxImageAttributes']
  14. self.assertEqual(reader.metadata['width'], attributes['uiWidth'])
  15. self.assertEqual(reader.metadata['height'], attributes['uiHeight'])
  16. self.assertEqual(reader.metadata['width'], reader.sizes['x'])
  17. self.assertEqual(reader.metadata['height'], reader.sizes['y'])
  18. self.assertEqual(reader.pixel_type, np.float64)
  19. self.assertEqual(reader.iter_axes, ['t'])
  20. def test_init_empty_file(self):
  21. with ArtificialND2('test_data/empty.nd2', skip_blocks=['label_map_marker']):
  22. with self.assertRaises(EmptyFileError) as exception:
  23. with ND2Reader('test_data/empty.nd2'):
  24. pass
  25. self.assertEqual(str(exception.exception), "No axes were found for this .nd2 file.")
  26. def test_get_parser(self):
  27. with ArtificialND2('test_data/test_nd2_reader.nd2') as _:
  28. with ND2Reader('test_data/test_nd2_reader.nd2') as reader:
  29. self.assertIsInstance(reader.parser, Parser)
  30. def test_get_timesteps(self):
  31. with ArtificialND2('test_data/test_nd2_reader.nd2') as _:
  32. with ND2Reader('test_data/test_nd2_reader.nd2') as reader:
  33. timesteps = reader.timesteps
  34. self.assertEquals(len(timesteps), 0)