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.

59 lines
2.5 KiB

  1. import unittest
  2. import six
  3. from nd2reader.artificial import ArtificialND2
  4. from nd2reader.label_map import LabelMap
  5. from nd2reader.raw_metadata import RawMetadata
  6. class TestRawMetadata(unittest.TestCase):
  7. def setUp(self):
  8. self.nd2 = ArtificialND2('test_data/test_nd2_raw_metadata001.nd2')
  9. self.raw_text, self.locations, self.file_data = self.nd2.raw_text, self.nd2.locations, self.nd2.data
  10. self.label_map = LabelMap(self.raw_text)
  11. self.metadata = RawMetadata(self.nd2.file_handle, self.label_map)
  12. def test_parse_roi_shape(self):
  13. self.assertEqual(self.metadata._parse_roi_shape(3), 'rectangle')
  14. self.assertEqual(self.metadata._parse_roi_shape(9), 'circle')
  15. self.assertIsNone(self.metadata._parse_roi_shape(-1))
  16. def test_parse_roi_type(self):
  17. self.assertEqual(self.metadata._parse_roi_type(3), 'reference')
  18. self.assertEqual(self.metadata._parse_roi_type(2), 'background')
  19. self.assertEqual(self.metadata._parse_roi_type(4), 'stimulation')
  20. self.assertIsNone(self.metadata._parse_roi_type(-1))
  21. def test_dict(self):
  22. self.assertTrue(type(self.metadata.__dict__) is dict)
  23. def test_parsed_metadata_has_all_keys(self):
  24. metadata = self.metadata.get_parsed_metadata()
  25. self.assertTrue(type(metadata) is dict)
  26. required_keys = ["height", "width", "date", "fields_of_view", "frames", "z_levels", "total_images_per_channel",
  27. "channels", "pixel_microns"]
  28. for required in required_keys:
  29. self.assertTrue(required in metadata)
  30. def test_cached_metadata(self):
  31. metadata_one = self.metadata.get_parsed_metadata()
  32. metadata_two = self.metadata.get_parsed_metadata()
  33. self.assertEqual(metadata_one, metadata_two)
  34. def test_pfs_status(self):
  35. self.assertEqual(self.file_data['pfs_status'], self.metadata.pfs_status[0])
  36. def _assert_dicts_equal(self, parsed_dict, original_dict):
  37. for attribute in original_dict.keys():
  38. parsed_key = six.b(attribute)
  39. self.assertIn(parsed_key, parsed_dict.keys())
  40. if isinstance(parsed_dict[parsed_key], dict):
  41. self._assert_dicts_equal(parsed_dict[parsed_key], original_dict[attribute])
  42. else:
  43. self.assertEqual(parsed_dict[parsed_key], original_dict[attribute])
  44. def test_image_attributes(self):
  45. parsed_dict = self.metadata.image_attributes
  46. self._assert_dicts_equal(parsed_dict, self.file_data['image_attributes'])