test_file_datanode_mixin.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright 2021-2025 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. import filecmp
  12. import os
  13. import pathlib
  14. from taipy import Scope
  15. from taipy.core.common._utils import _normalize_path
  16. from taipy.core.data._data_manager import _DataManager
  17. from taipy.core.data.csv import CSVDataNode
  18. def test_duplicate_data():
  19. path = os.path.join(pathlib.Path(__file__).parent.resolve(), "data_sample", "example.csv")
  20. src = CSVDataNode("foo", Scope.SCENARIO, properties={"path": path, "exposed_type": "pandas"})
  21. copy = CSVDataNode("foo", Scope.SCENARIO, properties={"path": path, "exposed_type": "pandas"})
  22. copy_2 = CSVDataNode("foo", Scope.SCENARIO, properties={"path": path, "exposed_type": "pandas"})
  23. copy_copy = CSVDataNode("foo", Scope.SCENARIO, properties={"path": path, "exposed_type": "pandas"})
  24. _DataManager._repository._save(src)
  25. _DataManager._repository._save(copy)
  26. _DataManager._repository._save(copy_2)
  27. _DataManager._repository._save(copy_copy)
  28. src._duplicate_file(copy)
  29. assert _normalize_path(src.path) == _normalize_path(path)
  30. assert _normalize_path(src.path) != _normalize_path(copy.path)
  31. assert filecmp.cmp(path, copy.path)
  32. assert src.path.count("DUPLICATE_OF") == 0
  33. assert copy.path.count("DUPLICATE_OF") == 1
  34. src._duplicate_file(copy_2)
  35. assert _normalize_path(copy.path) != _normalize_path(copy_2.path)
  36. assert copy_2.path.count("DUPLICATE_OF") == 1
  37. copy._duplicate_file(copy_copy)
  38. assert copy_copy.path.count("DUPLICATE_OF") == 2
  39. os.unlink(copy.path)
  40. os.unlink(copy_2.path)
  41. os.unlink(copy_copy.path)