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.

38 lines
1.9 KiB

  1. import unittest
  2. import warnings
  3. from nd2reader2.legacy import Nd2
  4. from nd2reader2.reader import ND2Reader
  5. from nd2reader2.artificial import ArtificialND2
  6. class TestLegacy(unittest.TestCase):
  7. def test_init(self):
  8. with ArtificialND2('test_data/legacy.nd2'):
  9. with warnings.catch_warnings(record=True) as w:
  10. # Cause all warnings to always be triggered.
  11. warnings.simplefilter("always")
  12. with Nd2('test_data/legacy.nd2') as reader:
  13. self.assertIsInstance(reader.reader, ND2Reader)
  14. self.assertTrue(issubclass(w[0].category, DeprecationWarning))
  15. self.assertEquals(str(w[0].message), "The 'Nd2' class is deprecated, please consider using the new" +
  16. " ND2Reader interface which uses pims.")
  17. def test_misc(self):
  18. with ArtificialND2('test_data/legacy.nd2'):
  19. with Nd2('test_data/legacy.nd2') as reader:
  20. representation = "\n".join(["<Deprecated ND2 %s>" % reader.reader.filename,
  21. "Created: Unknown",
  22. "Image size: %sx%s (HxW)" % (reader.height, reader.width),
  23. "Frames: %s" % len(reader.frames),
  24. "Channels: %s" % ", ".join(["%s" % str(channel) for channel
  25. in reader.channels]),
  26. "Fields of View: %s" % len(reader.fields_of_view),
  27. "Z-Levels: %s" % len(reader.z_levels)
  28. ])
  29. self.assertEquals(representation, str(reader))
  30. # not implemented yet
  31. self.assertEquals(reader.pixel_microns, None)
  32. self.assertEquals(len(reader), 1)