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.

37 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. import urllib.request
  8. class TestParser(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. self.create_test_nd2()
  17. def test_can_open_test_file(self):
  18. self.create_test_nd2()
  19. with open(self.test_file, "rb") as fh:
  20. parser = Parser(fh)
  21. self.assertTrue(parser.supported)
  22. def test_get_image(self):
  23. stitched_path = "test_data/test_stitched.nd2"
  24. if not path.isfile(stitched_path):
  25. file_name, header = urllib.request.urlretrieve(
  26. "https://downloads.openmicroscopy.org/images/ND2/karl/sample_image.nd2",
  27. stitched_path,
  28. )
  29. with open(stitched_path, "rb") as fh:
  30. parser = Parser(fh)
  31. parser.get_image(0)