TestVersionUpgrade34to35.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import os.path
  4. import sys
  5. sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
  6. import configparser #To parse the resulting config files.
  7. import pytest #To register tests with.
  8. import VersionUpgrade34to35 #The module we're testing.
  9. ## Creates an instance of the upgrader to test with.
  10. @pytest.fixture
  11. def upgrader():
  12. return VersionUpgrade34to35.VersionUpgrade34to35()
  13. test_upgrade_version_nr_data = [
  14. ("Empty config file",
  15. """[general]
  16. version = 5
  17. [metadata]
  18. setting_version = 4
  19. [info]
  20. asked_send_slice_info = True
  21. send_slice_info = True
  22. """
  23. )
  24. ]
  25. ## Tests whether the version numbers are updated.
  26. @pytest.mark.parametrize("test_name, file_data", test_upgrade_version_nr_data)
  27. def test_upgradeVersionNr(test_name, file_data, upgrader):
  28. #Perform the upgrade.
  29. _, upgraded_instances = upgrader.upgradePreferences(file_data, "<string>")
  30. upgraded_instance = upgraded_instances[0]
  31. parser = configparser.ConfigParser(interpolation = None)
  32. parser.read_string(upgraded_instance)
  33. #Check the new version.
  34. assert parser["general"]["version"] == "6"
  35. assert parser["metadata"]["setting_version"] == "5"
  36. # Check if the data collection values have been reset to their defaults
  37. assert parser.get("info", "asked_send_slice_info") == "False"
  38. assert parser.get("info", "send_slice_info") == "True"