TestVersionUpgrade26to27.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 VersionUpgrade26to27 #The module we're testing.
  6. ## Creates an instance of the upgrader to test with.
  7. @pytest.fixture
  8. def upgrader():
  9. return VersionUpgrade26to27.VersionUpgrade26to27()
  10. test_cfg_version_good_data = [
  11. {
  12. "test_name": "Simple",
  13. "file_data": """[general]
  14. version = 1
  15. """,
  16. "version": 1000000
  17. },
  18. {
  19. "test_name": "Other Data Around",
  20. "file_data": """[nonsense]
  21. life = good
  22. [general]
  23. version = 3
  24. [values]
  25. layer_height = 0.12
  26. infill_sparse_density = 42
  27. """,
  28. "version": 3000000
  29. },
  30. {
  31. "test_name": "Negative Version", #Why not?
  32. "file_data": """[general]
  33. version = -20
  34. """,
  35. "version": -20000000
  36. },
  37. {
  38. "test_name": "Setting Version",
  39. "file_data": """[general]
  40. version = 1
  41. [metadata]
  42. setting_version = 1
  43. """,
  44. "version": 1000001
  45. },
  46. {
  47. "test_name": "Negative Setting Version",
  48. "file_data": """[general]
  49. version = 1
  50. [metadata]
  51. setting_version = -3
  52. """,
  53. "version": 999997
  54. }
  55. ]
  56. ## Tests the technique that gets the version number from CFG files.
  57. #
  58. # \param data The parametrised data to test with. It contains a test name
  59. # to debug with, the serialised contents of a CFG file and the correct
  60. # version number in that CFG file.
  61. # \param upgrader The instance of the upgrade class to test.
  62. @pytest.mark.parametrize("data", test_cfg_version_good_data)
  63. def test_cfgVersionGood(data, upgrader):
  64. version = upgrader.getCfgVersion(data["file_data"])
  65. assert version == data["version"]
  66. test_cfg_version_bad_data = [
  67. {
  68. "test_name": "Empty",
  69. "file_data": "",
  70. "exception": configparser.Error #Explicitly not specified further which specific error we're getting, because that depends on the implementation of configparser.
  71. },
  72. {
  73. "test_name": "No General",
  74. "file_data": """[values]
  75. layer_height = 0.1337
  76. """,
  77. "exception": configparser.Error
  78. },
  79. {
  80. "test_name": "No Version",
  81. "file_data": """[general]
  82. true = false
  83. """,
  84. "exception": configparser.Error
  85. },
  86. {
  87. "test_name": "Not a Number",
  88. "file_data": """[general]
  89. version = not-a-text-version-number
  90. """,
  91. "exception": ValueError
  92. },
  93. {
  94. "test_name": "Setting Value NaN",
  95. "file_data": """[general]
  96. version = 4
  97. [metadata]
  98. setting_version = latest_or_something
  99. """,
  100. "exception": ValueError
  101. },
  102. {
  103. "test_name": "Major-Minor",
  104. "file_data": """[general]
  105. version = 1.2
  106. """,
  107. "exception": ValueError
  108. }
  109. ]
  110. ## Tests whether getting a version number from bad CFG files gives an
  111. # exception.
  112. #
  113. # \param data The parametrised data to test with. It contains a test name
  114. # to debug with, the serialised contents of a CFG file and the class of
  115. # exception it needs to throw.
  116. # \param upgrader The instance of the upgrader to test.
  117. @pytest.mark.parametrize("data", test_cfg_version_bad_data)
  118. def test_cfgVersionBad(data, upgrader):
  119. with pytest.raises(data["exception"]):
  120. upgrader.getCfgVersion(data["file_data"])
  121. test_upgrade_stacks_with_not_supported_data = [
  122. {
  123. "test_name": "Global stack with Not Supported quality profile",
  124. "file_data": """[general]
  125. version = 3
  126. name = Ultimaker 3
  127. id = Ultimaker 3
  128. [metadata]
  129. type = machine
  130. [containers]
  131. 0 = Ultimaker 3_user
  132. 1 = empty
  133. 2 = um3_global_Normal_Quality
  134. 3 = empty
  135. 4 = empty
  136. 5 = empty
  137. 6 = ultimaker3
  138. """
  139. },
  140. {
  141. "test_name": "Extruder stack left with Not Supported quality profile",
  142. "file_data": """[general]
  143. version = 3
  144. name = Extruder 1
  145. id = ultimaker3_extruder_left #2
  146. [metadata]
  147. position = 0
  148. machine = Ultimaker 3
  149. type = extruder_train
  150. [containers]
  151. 0 = ultimaker3_extruder_left #2_user
  152. 1 = empty
  153. 2 = um3_aa0.4_PVA_Not_Supported_Quality
  154. 3 = generic_pva_ultimaker3_AA_0.4
  155. 4 = ultimaker3_aa04
  156. 5 = ultimaker3_extruder_left #2_settings
  157. 6 = ultimaker3_extruder_left
  158. """
  159. }
  160. ]
  161. ## Tests whether the "Not Supported" quality profiles in the global and extruder stacks are renamed for the 2.7
  162. # version of preferences.
  163. @pytest.mark.parametrize("data", test_upgrade_stacks_with_not_supported_data)
  164. def test_upgradeStacksWithNotSupportedQuality(data, upgrader):
  165. # Read old file
  166. original_parser = configparser.ConfigParser(interpolation = None)
  167. original_parser.read_string(data["file_data"])
  168. # Perform the upgrade.
  169. _, upgraded_stacks = upgrader.upgradeStack(data["file_data"], "<string>")
  170. upgraded_stack = upgraded_stacks[0]
  171. # Find whether the not supported profile has been renamed
  172. parser = configparser.ConfigParser(interpolation = None)
  173. parser.read_string(upgraded_stack)
  174. assert("Not_Supported" not in parser.get("containers", "2"))