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.

36 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.parser import Parser
  6. import urllib.request
  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_get_image(self):
  22. stitched_path = "test_data/test_stitched.nd2"
  23. if not path.isfile(stitched_path):
  24. file_name, header = urllib.request.urlretrieve(
  25. "https://downloads.openmicroscopy.org/images/ND2/karl/sample_image.nd2",
  26. stitched_path,
  27. )
  28. with open(stitched_path, "rb") as fh:
  29. parser = Parser(fh)
  30. parser.get_image(0)