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.

32 lines
1.2 KiB

  1. import unittest
  2. from os import path
  3. from nd2reader.artificial import ArtificialND2
  4. from nd2reader.common import check_or_make_dir
  5. from nd2reader.exceptions import InvalidVersionError
  6. from nd2reader.parser import Parser
  7. class TestParser(unittest.TestCase):
  8. def create_test_nd2(self):
  9. with ArtificialND2(self.test_file) as artificial:
  10. artificial.close()
  11. def setUp(self):
  12. dir_path = path.dirname(path.realpath(__file__))
  13. check_or_make_dir(path.join(dir_path, 'test_data/'))
  14. self.test_file = path.join(dir_path, 'test_data/test.nd2')
  15. self.create_test_nd2()
  16. def test_can_open_test_file(self):
  17. self.create_test_nd2()
  18. with open(self.test_file, 'rb') as fh:
  19. parser = Parser(fh)
  20. self.assertTrue(parser.supported)
  21. def test_cannot_open_wrong_version(self):
  22. with ArtificialND2(self.test_file, version=('0', '0')) as _:
  23. with open(self.test_file, 'rb') as fh:
  24. with self.assertRaises(InvalidVersionError) as exception:
  25. Parser(fh)
  26. self.assertEqual(str(exception.exception), "No parser is available for that version.")