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.

30 lines
972 B

  1. import unittest
  2. from os import path
  3. from nd2reader.artificial import ArtificialND2
  4. from nd2reader.exceptions import InvalidVersionError
  5. from nd2reader.parser import Parser
  6. class TestParser(unittest.TestCase):
  7. def create_test_nd2(self):
  8. with ArtificialND2(self.test_file) as artificial:
  9. artificial.close()
  10. def setUp(self):
  11. dir_path = path.dirname(path.realpath(__file__))
  12. self.test_file = path.join(dir_path, 'test_data/test.nd2')
  13. self.create_test_nd2()
  14. def test_can_open_test_file(self):
  15. self.create_test_nd2()
  16. with open(self.test_file, 'rb') as fh:
  17. parser = Parser(fh)
  18. self.assertTrue(parser.supported)
  19. def test_cannot_open_wrong_version(self):
  20. with ArtificialND2(self.test_file, version=('a', 'b')) as artificial:
  21. artificial.close()
  22. with open(self.test_file, 'rb') as fh:
  23. self.assertRaises(InvalidVersionError, Parser, fh)