Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

test_instanceset.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import unittest
  2. from typing import Tuple
  3. from dataladmetadatamodel.metadata import (
  4. ExtractorConfiguration,
  5. MetadataInstance,
  6. MetadataInstanceSet
  7. )
  8. class TestInstanceSetBase(unittest.TestCase):
  9. def setUp(self) -> None:
  10. self.metadata_instances = {
  11. prefix: self.create_metadata_instance(time_stamp, prefix)
  12. for time_stamp, prefix in ((1.0, "default"), (2.0, "new"))
  13. }
  14. self.metadata_instance_set = MetadataInstanceSet()
  15. self.metadata_instance_set.add_metadata_instance(
  16. self.metadata_instances["default"][1]
  17. )
  18. def create_metadata_instance(self,
  19. time_stamp: float,
  20. prefix: str
  21. ) -> Tuple[ExtractorConfiguration, MetadataInstance]:
  22. extractor_configuration = ExtractorConfiguration(
  23. "1.0",
  24. {"info": f"{prefix}_value"}
  25. )
  26. return (
  27. extractor_configuration,
  28. MetadataInstance(
  29. time_stamp,
  30. f"{prefix}_name",
  31. f"{prefix}_email",
  32. extractor_configuration,
  33. {"metadata 1": f"{prefix}_content"}
  34. )
  35. )
  36. def get_instance(self, prefix):
  37. return self.metadata_instances[prefix][1]
  38. def get_configuration(self, prefix):
  39. return self.metadata_instances[prefix][0]
  40. def assert_equal_to_pattern(self, instance_set: MetadataInstanceSet) -> None:
  41. self.assertListEqual(
  42. self.metadata_instance_set.parameter_set,
  43. instance_set.parameter_set
  44. )
  45. self.assertDictEqual(
  46. self.metadata_instance_set._instances,
  47. instance_set._instances
  48. )
  49. class TestSerialization(TestInstanceSetBase):
  50. def test_object_round_trip(self):
  51. json_obj = self.metadata_instance_set.to_json_obj()
  52. ins2 = MetadataInstanceSet.from_json_obj(json_obj)
  53. self.assert_equal_to_pattern(ins2)
  54. def test_string_round_trip(self):
  55. json_str = self.metadata_instance_set.to_json_str()
  56. ins2 = MetadataInstanceSet.from_json_str(json_str)
  57. self.assert_equal_to_pattern(ins2)
  58. class TestUniqueness(TestInstanceSetBase):
  59. def test_configuration_unity(self):
  60. # Ensure known state
  61. configuration_list = self.metadata_instance_set.configurations
  62. self.assertEqual(1, len(configuration_list))
  63. self.assertEqual(configuration_list[0], self.get_configuration("default"))
  64. # Re-add the only instance
  65. self.metadata_instance_set.add_metadata_instance(
  66. self.metadata_instance_set.get_instance_for_configuration(
  67. configuration_list[0]))
  68. # Ensure nothing has changes
  69. new_configuration_list = self.metadata_instance_set.configurations
  70. self.assertEqual(configuration_list, new_configuration_list)
  71. self.assertEqual(
  72. self.metadata_instance_set.get_instance_for_configuration(
  73. configuration_list[0]
  74. ),
  75. self.get_instance("default")
  76. )
  77. def test_configuration_multiplicity(self):
  78. configuration_list = self.metadata_instance_set.configurations
  79. self.assertEqual(1, len(configuration_list))
  80. self.assertEqual(configuration_list[0], self.get_configuration("default"))
  81. self.metadata_instance_set.add_metadata_instance(self.get_instance("new"))
  82. configuration_list = self.metadata_instance_set.configurations
  83. self.assertEqual(2, len(configuration_list))
  84. self.assertIn(self.get_configuration("default"), configuration_list)
  85. self.assertIn(self.get_configuration("new"), configuration_list)
  86. if __name__ == '__main__':
  87. unittest.main()