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.

45 lines
1.6 KiB

8 years ago
  1. import unittest
  2. from os import path
  3. import numpy as np
  4. from nd2reader.artificial import ArtificialND2
  5. from nd2reader.common import check_or_make_dir
  6. from nd2reader.parser import Parser
  7. from nd2reader.reader import ND2Reader
  8. class TestReader(unittest.TestCase):
  9. def create_test_nd2(self):
  10. with ArtificialND2(self.test_file) as artificial:
  11. artificial.close()
  12. def setUp(self):
  13. dir_path = path.dirname(path.realpath(__file__))
  14. check_or_make_dir(path.join(dir_path, 'test_data/'))
  15. self.test_file = path.join(dir_path, 'test_data/test.nd2')
  16. def test_can_open_test_file(self):
  17. self.create_test_nd2()
  18. with ND2Reader(self.test_file) as reader:
  19. self.assertEqual(reader.filename, self.test_file)
  20. self.assertEqual(reader.pixel_type, np.float64)
  21. self.assertEqual(reader.sizes['x'], 0)
  22. self.assertEqual(reader.sizes['y'], 0)
  23. self.assertEqual(reader.sizes['z'], 1)
  24. self.assertEqual(reader.sizes['c'], 0)
  25. self.assertEqual(reader.sizes['t'], 1)
  26. def test_extension(self):
  27. self.assertTrue('nd2' in ND2Reader.class_exts())
  28. def test_get_metadata_property(self):
  29. self.create_test_nd2()
  30. with ND2Reader(self.test_file) as reader:
  31. self.assertIsNone(reader._get_metadata_property('kljdf'))
  32. self.assertEqual(reader._get_metadata_property('kljdf', 'default'), 'default')
  33. def test_get_parser(self):
  34. self.create_test_nd2()
  35. with ND2Reader(self.test_file) as reader:
  36. self.assertTrue(type(reader.parser) is Parser)