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.

80 lines
2.5 KiB

  1. """
  2. These tests require that you have a specific ND2 file created by the developer of nd2reader. You will never need to
  3. run them unless you're Jim Rybarski.
  4. """
  5. from nd2reader import Nd2
  6. from datetime import datetime
  7. import unittest
  8. class FunctionalTests(unittest.TestCase):
  9. def setUp(self):
  10. self.nd2 = Nd2("/var/nd2s/FYLM-141111-001.nd2")
  11. def tearDown(self):
  12. self.nd2.close()
  13. def test_shape(self):
  14. self.assertEqual(self.nd2.height, 1280)
  15. self.assertEqual(self.nd2.width, 800)
  16. def test_date(self):
  17. self.assertEqual(self.nd2.date, datetime(2014, 11, 11, 15, 59, 19))
  18. def test_length(self):
  19. self.assertEqual(len(self.nd2), 30528)
  20. def test_frames(self):
  21. self.assertEqual(len(self.nd2.frames), 636)
  22. def test_fovs(self):
  23. self.assertEqual(len(self.nd2.fields_of_view), 8)
  24. def test_channels(self):
  25. self.assertTupleEqual(tuple(sorted(self.nd2.channels)), ('', 'GFP'))
  26. def test_z_levels(self):
  27. self.assertTupleEqual(tuple(self.nd2.z_levels), (0, 1, 2))
  28. def test_image(self):
  29. image = self.nd2[14]
  30. self.assertEqual(image.field_of_view, 2)
  31. self.assertEqual(image.frame_number, 0)
  32. self.assertAlmostEqual(image.timestamp, 19.0340758)
  33. self.assertEqual(image.channel, '')
  34. self.assertEqual(image.z_level, 1)
  35. self.assertEqual(image.height, self.nd2.height)
  36. self.assertEqual(image.width, self.nd2.width)
  37. def test_last_image(self):
  38. image = self.nd2[30526]
  39. self.assertEqual(image.frame_number, 635)
  40. def test_bad_image(self):
  41. image = self.nd2[13]
  42. self.assertIsNone(image)
  43. def test_iteration(self):
  44. images = [image for image in self.nd2[:10]]
  45. self.assertEqual(len(images), 10)
  46. def test_iteration_step(self):
  47. images = [image for image in self.nd2[:10:2]]
  48. self.assertEqual(len(images), 5)
  49. def test_iteration_backwards(self):
  50. images = [image for image in self.nd2[:10:-1]]
  51. self.assertEqual(len(images), 10)
  52. def test_get_image_by_attribute_ok(self):
  53. image = self.nd2.get_image(4, 0, "GFP", 1)
  54. self.assertIsNotNone(image)
  55. image = self.nd2.get_image(4, 0, "", 0)
  56. self.assertIsNotNone(image)
  57. image = self.nd2.get_image(4, 0, "", 1)
  58. self.assertIsNotNone(image)
  59. def test_get_image_by_attribute_none(self):
  60. image = self.nd2.get_image(4, 0, "GFP", 0)
  61. self.assertIsNone(image)