TestVersionUpgrade26to27.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import configparser #To check whether the appropriate exceptions are raised.
  4. import pytest #To register tests with.
  5. import os.path
  6. import sys
  7. sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
  8. import VersionUpgrade26to27 #The module we're testing.
  9. ## Creates an instance of the upgrader to test with.
  10. @pytest.fixture
  11. def upgrader():
  12. return VersionUpgrade26to27.VersionUpgrade26to27()
  13. test_cfg_version_good_data = [
  14. {
  15. "test_name": "Simple",
  16. "file_data": """[general]
  17. version = 1
  18. """,
  19. "version": 1000000
  20. },
  21. {
  22. "test_name": "Other Data Around",
  23. "file_data": """[nonsense]
  24. life = good
  25. [general]
  26. version = 3
  27. [values]
  28. layer_height = 0.12
  29. infill_sparse_density = 42
  30. """,
  31. "version": 3000000
  32. },
  33. {
  34. "test_name": "Setting Version",
  35. "file_data": """[general]
  36. version = 1
  37. [metadata]
  38. setting_version = 1
  39. """,
  40. "version": 1000001
  41. }
  42. ]
  43. ## Tests the technique that gets the version number from CFG files.
  44. #
  45. # \param data The parametrised data to test with. It contains a test name
  46. # to debug with, the serialised contents of a CFG file and the correct
  47. # version number in that CFG file.
  48. # \param upgrader The instance of the upgrade class to test.
  49. @pytest.mark.parametrize("data", test_cfg_version_good_data)
  50. def test_cfgVersionGood(data, upgrader):
  51. version = upgrader.getCfgVersion(data["file_data"])
  52. assert version == data["version"]
  53. test_upgrade_stacks_with_not_supported_data = [
  54. {
  55. "test_name": "Global stack with Not Supported quality profile",
  56. "file_data": """[general]
  57. version = 3
  58. name = Ultimaker 3
  59. id = Ultimaker 3
  60. [metadata]
  61. type = machine
  62. [containers]
  63. 0 = Ultimaker 3_user
  64. 1 = empty
  65. 2 = um3_global_Normal_Quality
  66. 3 = empty
  67. 4 = empty
  68. 5 = empty
  69. 6 = ultimaker3
  70. """
  71. },
  72. {
  73. "test_name": "Extruder stack left with Not Supported quality profile",
  74. "file_data": """[general]
  75. version = 3
  76. name = Extruder 1
  77. id = ultimaker3_extruder_left #2
  78. [metadata]
  79. position = 0
  80. machine = Ultimaker 3
  81. type = extruder_train
  82. [containers]
  83. 0 = ultimaker3_extruder_left #2_user
  84. 1 = empty
  85. 2 = um3_aa0.4_PVA_Not_Supported_Quality
  86. 3 = generic_pva_ultimaker3_AA_0.4
  87. 4 = ultimaker3_aa04
  88. 5 = ultimaker3_extruder_left #2_settings
  89. 6 = ultimaker3_extruder_left
  90. """
  91. }
  92. ]
  93. ## Tests whether the "Not Supported" quality profiles in the global and extruder stacks are renamed for the 2.7
  94. # version of preferences.
  95. @pytest.mark.parametrize("data", test_upgrade_stacks_with_not_supported_data)
  96. def test_upgradeStacksWithNotSupportedQuality(data, upgrader):
  97. # Read old file
  98. original_parser = configparser.ConfigParser(interpolation = None)
  99. original_parser.read_string(data["file_data"])
  100. # Perform the upgrade.
  101. _, upgraded_stacks = upgrader.upgradeStack(data["file_data"], "<string>")
  102. upgraded_stack = upgraded_stacks[0]
  103. # Find whether the not supported profile has been renamed
  104. parser = configparser.ConfigParser(interpolation = None)
  105. parser.read_string(upgraded_stack)
  106. assert("Not_Supported" not in parser.get("containers", "2"))