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_versionlist.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import subprocess
  2. import tempfile
  3. import unittest
  4. from pathlib import Path
  5. from dataladmetadatamodel.metadatapath import MetadataPath
  6. from dataladmetadatamodel.versionlist import (
  7. VersionList,
  8. VersionRecord
  9. )
  10. from dataladmetadatamodel.mapper.gitmapper.objectreference import flush_object_references
  11. from .utils import (
  12. assert_dataset_trees_equal,
  13. create_dataset_tree
  14. )
  15. file_test_paths = [
  16. MetadataPath("a/b/c"),
  17. MetadataPath("a/b/a"),
  18. MetadataPath("b"),
  19. MetadataPath("c/d/e"),
  20. MetadataPath("a/x")]
  21. dataset_test_paths = [
  22. [
  23. MetadataPath(""),
  24. MetadataPath("d1"),
  25. MetadataPath("d1/d1.1"),
  26. MetadataPath("d2"),
  27. MetadataPath("d2/d2.1/d2.1.1"),
  28. MetadataPath("d3/d3.1")
  29. ],
  30. [
  31. MetadataPath(""),
  32. MetadataPath("e1"),
  33. MetadataPath("e1/e1.1"),
  34. MetadataPath("e2"),
  35. MetadataPath("e2/e2.1/e2.1.1"),
  36. MetadataPath("e3/e3.1")
  37. ]
  38. ]
  39. class TestVersionList(unittest.TestCase):
  40. def test_basic(self):
  41. VersionList()
  42. def test_copy_end_to_end(self):
  43. print("test_copy_end_to_end")
  44. with \
  45. tempfile.TemporaryDirectory() as original_dir, \
  46. tempfile.TemporaryDirectory() as copy_dir:
  47. subprocess.run(["git", "init", original_dir])
  48. subprocess.run(["git", "init", copy_dir])
  49. dataset_trees = [
  50. create_dataset_tree(
  51. dataset_test_paths[index],
  52. file_test_paths)
  53. for index in range(2)]
  54. dataset_trees[0].write_out(original_dir)
  55. dataset_trees[0].purge()
  56. dataset_trees[1].write_out(original_dir)
  57. version_list = VersionList(initial_set={
  58. "v1": VersionRecord(
  59. "0.1",
  60. MetadataPath("a"),
  61. dataset_trees[0]
  62. ),
  63. "v2": VersionRecord(
  64. "0.2",
  65. MetadataPath("b"),
  66. dataset_trees[1]
  67. )
  68. })
  69. version_list.write_out(original_dir)
  70. path_prefix = "x/y/z"
  71. copied_version_list = version_list.deepcopy(
  72. new_destination=copy_dir,
  73. path_prefix=MetadataPath(path_prefix))
  74. # Check that the mapping state of the original
  75. # has not changed.
  76. self.assertFalse(dataset_trees[0].mtree.mapped)
  77. self.assertTrue(dataset_trees[1].mtree.mapped)
  78. # Read the copied version list
  79. copied_version_list.read_in()
  80. # Check that the copied elements are unmapped
  81. for _, (_, _, copied_dataset_tree) in copied_version_list.get_versioned_elements():
  82. self.assertFalse(copied_dataset_tree.mtree.mapped)
  83. # Compare the version lists, taking modified dataset tree paths into account
  84. for primary_version, (_, path, dataset_tree) in version_list.get_versioned_elements():
  85. expected_path = path_prefix / path
  86. _, copy_path, copied_dataset_tree = copied_version_list.get_versioned_element(primary_version)
  87. self.assertEqual(expected_path, copy_path)
  88. dataset_tree.read_in()
  89. copied_dataset_tree.read_in()
  90. assert_dataset_trees_equal(self, dataset_tree, copied_dataset_tree, True)
  91. # NB! dataset tree copying is tested in dataset-tree related unit tests
  92. if __name__ == '__main__':
  93. unittest.main()