TestGlobalStack.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import pytest #This module contains unit tests.
  4. import unittest.mock #To monkeypatch some mocks in place of dependencies.
  5. import cura.Settings.CuraContainerStack #To get the list of container types.
  6. from cura.Settings.Exceptions import InvalidContainerError, InvalidOperationError #To test raising these errors.
  7. from UM.Settings.DefinitionContainer import DefinitionContainer #To test against the class DefinitionContainer.
  8. from UM.Settings.InstanceContainer import InstanceContainer #To test against the class InstanceContainer.
  9. from UM.Settings.SettingInstance import InstanceState
  10. import UM.Settings.ContainerRegistry
  11. import UM.Settings.ContainerStack
  12. import UM.Settings.SettingDefinition #To add settings to the definition.
  13. from cura.Settings.cura_empty_instance_containers import empty_container
  14. ## Gets an instance container with a specified container type.
  15. #
  16. # \param container_type The type metadata for the instance container.
  17. # \return An instance container instance.
  18. def getInstanceContainer(container_type) -> InstanceContainer:
  19. container = InstanceContainer(container_id = "InstanceContainer")
  20. container.setMetaDataEntry("type", container_type)
  21. return container
  22. class DefinitionContainerSubClass(DefinitionContainer):
  23. def __init__(self):
  24. super().__init__(container_id = "SubDefinitionContainer")
  25. class InstanceContainerSubClass(InstanceContainer):
  26. def __init__(self, container_type):
  27. super().__init__(container_id = "SubInstanceContainer")
  28. self.setMetaDataEntry("type", container_type)
  29. #############################START OF TEST CASES################################
  30. ## Tests whether adding a container is properly forbidden.
  31. def test_addContainer(global_stack):
  32. with pytest.raises(InvalidOperationError):
  33. global_stack.addContainer(unittest.mock.MagicMock())
  34. ## Tests adding extruders to the global stack.
  35. def test_addExtruder(global_stack):
  36. mock_definition = unittest.mock.MagicMock()
  37. mock_definition.getProperty = lambda key, property, context = None: 2 if key == "machine_extruder_count" and property == "value" else None
  38. with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock):
  39. global_stack.definition = mock_definition
  40. assert len(global_stack.extruders) == 0
  41. first_extruder = unittest.mock.MagicMock()
  42. first_extruder.getMetaDataEntry = lambda key: 0 if key == "position" else None
  43. with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock):
  44. global_stack.addExtruder(first_extruder)
  45. assert len(global_stack.extruders) == 1
  46. assert global_stack.extruders[0] == first_extruder
  47. second_extruder = unittest.mock.MagicMock()
  48. second_extruder.getMetaDataEntry = lambda key: 1 if key == "position" else None
  49. with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock):
  50. global_stack.addExtruder(second_extruder)
  51. assert len(global_stack.extruders) == 2
  52. assert global_stack.extruders[1] == second_extruder
  53. # Disabled for now for Custom FDM Printer
  54. # with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock):
  55. # with pytest.raises(TooManyExtrudersError): #Should be limited to 2 extruders because of machine_extruder_count.
  56. # global_stack.addExtruder(unittest.mock.MagicMock())
  57. assert len(global_stack.extruders) == 2 #Didn't add the faulty extruder.
  58. #Tests setting user changes profiles to invalid containers.
  59. @pytest.mark.parametrize("container", [
  60. getInstanceContainer(container_type = "wrong container type"),
  61. getInstanceContainer(container_type = "material"), #Existing, but still wrong type.
  62. DefinitionContainer(container_id = "wrong class")
  63. ])
  64. def test_constrainUserChangesInvalid(container, global_stack):
  65. with pytest.raises(InvalidContainerError): #Invalid container, should raise an error.
  66. global_stack.userChanges = container
  67. #Tests setting user changes profiles.
  68. @pytest.mark.parametrize("container", [
  69. getInstanceContainer(container_type = "user"),
  70. InstanceContainerSubClass(container_type = "user")
  71. ])
  72. def test_constrainUserChangesValid(container, global_stack):
  73. global_stack.userChanges = container #Should not give an error.
  74. #Tests setting quality changes profiles to invalid containers.
  75. @pytest.mark.parametrize("container", [
  76. getInstanceContainer(container_type = "wrong container type"),
  77. getInstanceContainer(container_type = "material"), #Existing, but still wrong type.
  78. DefinitionContainer(container_id = "wrong class")
  79. ])
  80. def test_constrainQualityChangesInvalid(container, global_stack):
  81. with pytest.raises(InvalidContainerError): #Invalid container, should raise an error.
  82. global_stack.qualityChanges = container
  83. #Test setting quality changes profiles.
  84. @pytest.mark.parametrize("container", [
  85. getInstanceContainer(container_type = "quality_changes"),
  86. InstanceContainerSubClass(container_type = "quality_changes")
  87. ])
  88. def test_constrainQualityChangesValid(container, global_stack):
  89. global_stack.qualityChanges = container #Should not give an error.
  90. #Tests setting quality profiles to invalid containers.
  91. @pytest.mark.parametrize("container", [
  92. getInstanceContainer(container_type = "wrong container type"),
  93. getInstanceContainer(container_type = "material"), #Existing, but still wrong type.
  94. DefinitionContainer(container_id = "wrong class")
  95. ])
  96. def test_constrainQualityInvalid(container, global_stack):
  97. with pytest.raises(InvalidContainerError): #Invalid container, should raise an error.
  98. global_stack.quality = container
  99. #Test setting quality profiles.
  100. @pytest.mark.parametrize("container", [
  101. getInstanceContainer(container_type = "quality"),
  102. InstanceContainerSubClass(container_type = "quality")
  103. ])
  104. def test_constrainQualityValid(container, global_stack):
  105. global_stack.quality = container #Should not give an error.
  106. #Tests setting materials to invalid containers.
  107. @pytest.mark.parametrize("container", [
  108. getInstanceContainer(container_type = "wrong container type"),
  109. getInstanceContainer(container_type = "quality"), #Existing, but still wrong type.
  110. DefinitionContainer(container_id = "wrong class")
  111. ])
  112. def test_constrainMaterialInvalid(container, global_stack):
  113. with pytest.raises(InvalidContainerError): #Invalid container, should raise an error.
  114. global_stack.material = container
  115. #Test setting materials.
  116. @pytest.mark.parametrize("container", [
  117. getInstanceContainer(container_type = "material"),
  118. InstanceContainerSubClass(container_type = "material")
  119. ])
  120. def test_constrainMaterialValid(container, global_stack):
  121. global_stack.material = container #Should not give an error.
  122. #Tests setting variants to invalid containers.
  123. @pytest.mark.parametrize("container", [
  124. getInstanceContainer(container_type = "wrong container type"),
  125. getInstanceContainer(container_type = "material"), #Existing, but still wrong type.
  126. DefinitionContainer(container_id = "wrong class")
  127. ])
  128. def test_constrainVariantInvalid(container, global_stack):
  129. with pytest.raises(InvalidContainerError): #Invalid container, should raise an error.
  130. global_stack.variant = container
  131. #Test setting variants.
  132. @pytest.mark.parametrize("container", [
  133. getInstanceContainer(container_type = "variant"),
  134. InstanceContainerSubClass(container_type = "variant")
  135. ])
  136. def test_constrainVariantValid(container, global_stack):
  137. global_stack.variant = container #Should not give an error.
  138. #Tests setting definition changes profiles to invalid containers.
  139. @pytest.mark.parametrize("container", [
  140. getInstanceContainer(container_type = "wrong container type"),
  141. getInstanceContainer(container_type = "material"), #Existing, but still wrong type.
  142. DefinitionContainer(container_id = "wrong class")
  143. ])
  144. def test_constrainDefinitionChangesInvalid(container, global_stack):
  145. with pytest.raises(InvalidContainerError): #Invalid container, should raise an error.
  146. global_stack.definitionChanges = container
  147. #Test setting definition changes profiles.
  148. @pytest.mark.parametrize("container", [
  149. getInstanceContainer(container_type = "definition_changes"),
  150. InstanceContainerSubClass(container_type = "definition_changes")
  151. ])
  152. def test_constrainDefinitionChangesValid(container, global_stack):
  153. global_stack.definitionChanges = container #Should not give an error.
  154. #Tests setting definitions to invalid containers.
  155. @pytest.mark.parametrize("container", [
  156. getInstanceContainer(container_type = "wrong class"),
  157. getInstanceContainer(container_type = "material"), #Existing, but still wrong class.
  158. ])
  159. def test_constrainDefinitionInvalid(container, global_stack):
  160. with pytest.raises(InvalidContainerError): #Invalid container, should raise an error.
  161. global_stack.definition = container
  162. #Test setting definitions.
  163. @pytest.mark.parametrize("container", [
  164. DefinitionContainer(container_id = "DefinitionContainer"),
  165. DefinitionContainerSubClass()
  166. ])
  167. def test_constrainDefinitionValid(container, global_stack):
  168. global_stack.definition = container #Should not give an error.
  169. ## Tests whether deserialising completes the missing containers with empty ones. The initial containers are just the
  170. # definition and the definition_changes (that cannot be empty after CURA-5281)
  171. def test_deserializeCompletesEmptyContainers(global_stack):
  172. global_stack._containers = [DefinitionContainer(container_id = "definition"), global_stack.definitionChanges] #Set the internal state of this stack manually.
  173. with unittest.mock.patch("UM.Settings.ContainerStack.ContainerStack.deserialize", unittest.mock.MagicMock()): #Prevent calling super().deserialize.
  174. global_stack.deserialize("")
  175. assert len(global_stack.getContainers()) == len(cura.Settings.CuraContainerStack._ContainerIndexes.IndexTypeMap) #Needs a slot for every type.
  176. for container_type_index in cura.Settings.CuraContainerStack._ContainerIndexes.IndexTypeMap:
  177. if container_type_index in \
  178. (cura.Settings.CuraContainerStack._ContainerIndexes.Definition, cura.Settings.CuraContainerStack._ContainerIndexes.DefinitionChanges): #We're not checking the definition or definition_changes
  179. continue
  180. assert global_stack.getContainer(container_type_index) == empty_container #All others need to be empty.
  181. ## Tests whether an instance container with the wrong type gets removed when deserialising.
  182. def test_deserializeRemovesWrongInstanceContainer(global_stack):
  183. global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = getInstanceContainer(container_type = "wrong type")
  184. global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Definition] = DefinitionContainer(container_id = "some definition")
  185. with unittest.mock.patch("UM.Settings.ContainerStack.ContainerStack.deserialize", unittest.mock.MagicMock()): #Prevent calling super().deserialize.
  186. global_stack.deserialize("")
  187. assert global_stack.quality == global_stack._empty_instance_container #Replaced with empty.
  188. ## Tests whether a container with the wrong class gets removed when deserialising.
  189. def test_deserializeRemovesWrongContainerClass(global_stack):
  190. global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = DefinitionContainer(container_id = "wrong class")
  191. global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Definition] = DefinitionContainer(container_id = "some definition")
  192. with unittest.mock.patch("UM.Settings.ContainerStack.ContainerStack.deserialize", unittest.mock.MagicMock()): #Prevent calling super().deserialize.
  193. global_stack.deserialize("")
  194. assert global_stack.quality == global_stack._empty_instance_container #Replaced with empty.
  195. ## Tests whether an instance container in the definition spot results in an error.
  196. def test_deserializeWrongDefinitionClass(global_stack):
  197. global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Definition] = getInstanceContainer(container_type = "definition") #Correct type but wrong class.
  198. with unittest.mock.patch("UM.Settings.ContainerStack.ContainerStack.deserialize", unittest.mock.MagicMock()): #Prevent calling super().deserialize.
  199. with pytest.raises(UM.Settings.ContainerStack.InvalidContainerStackError): #Must raise an error that there is no definition container.
  200. global_stack.deserialize("")
  201. ## Tests whether an instance container with the wrong type is moved into the correct slot by deserialising.
  202. def test_deserializeMoveInstanceContainer(global_stack):
  203. global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = getInstanceContainer(container_type = "material") #Not in the correct spot.
  204. global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Definition] = DefinitionContainer(container_id = "some definition")
  205. with unittest.mock.patch("UM.Settings.ContainerStack.ContainerStack.deserialize", unittest.mock.MagicMock()): #Prevent calling super().deserialize.
  206. global_stack.deserialize("")
  207. assert global_stack.quality == empty_container
  208. assert global_stack.material != empty_container
  209. ## Tests whether a definition container in the wrong spot is moved into the correct spot by deserialising.
  210. def test_deserializeMoveDefinitionContainer(global_stack):
  211. global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Material] = DefinitionContainer(container_id = "some definition") #Not in the correct spot.
  212. with unittest.mock.patch("UM.Settings.ContainerStack.ContainerStack.deserialize", unittest.mock.MagicMock()): #Prevent calling super().deserialize.
  213. global_stack.deserialize("")
  214. assert global_stack.material == empty_container
  215. assert global_stack.definition != empty_container
  216. ## Tests whether getProperty properly applies the stack-like behaviour on its containers.
  217. def test_getPropertyFallThrough(global_stack):
  218. #A few instance container mocks to put in the stack.
  219. mock_layer_heights = {} #For each container type, a mock container that defines layer height to something unique.
  220. mock_no_settings = {} #For each container type, a mock container that has no settings at all.
  221. container_indexes = cura.Settings.CuraContainerStack._ContainerIndexes #Cache.
  222. for type_id, type_name in container_indexes.IndexTypeMap.items():
  223. container = unittest.mock.MagicMock()
  224. container.getProperty = lambda key, property, context = None, type_id = type_id: type_id if (key == "layer_height" and property == "value") else None #Returns the container type ID as layer height, in order to identify it.
  225. container.hasProperty = lambda key, property: key == "layer_height"
  226. container.getMetaDataEntry = unittest.mock.MagicMock(return_value = type_name)
  227. mock_layer_heights[type_id] = container
  228. container = unittest.mock.MagicMock()
  229. container.getProperty = unittest.mock.MagicMock(return_value = None) #Has no settings at all.
  230. container.hasProperty = unittest.mock.MagicMock(return_value = False)
  231. container.getMetaDataEntry = unittest.mock.MagicMock(return_value = type_name)
  232. mock_no_settings[type_id] = container
  233. global_stack.userChanges = mock_no_settings[container_indexes.UserChanges]
  234. global_stack.qualityChanges = mock_no_settings[container_indexes.QualityChanges]
  235. global_stack.quality = mock_no_settings[container_indexes.Quality]
  236. global_stack.material = mock_no_settings[container_indexes.Material]
  237. global_stack.variant = mock_no_settings[container_indexes.Variant]
  238. global_stack.definitionChanges = mock_no_settings[container_indexes.DefinitionChanges]
  239. with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock): #To guard against the type checking.
  240. global_stack.definition = mock_layer_heights[container_indexes.Definition] #There's a layer height in here!
  241. assert global_stack.getProperty("layer_height", "value") == container_indexes.Definition
  242. global_stack.definitionChanges = mock_layer_heights[container_indexes.DefinitionChanges]
  243. assert global_stack.getProperty("layer_height", "value") == container_indexes.DefinitionChanges
  244. global_stack.variant = mock_layer_heights[container_indexes.Variant]
  245. assert global_stack.getProperty("layer_height", "value") == container_indexes.Variant
  246. global_stack.material = mock_layer_heights[container_indexes.Material]
  247. assert global_stack.getProperty("layer_height", "value") == container_indexes.Material
  248. global_stack.quality = mock_layer_heights[container_indexes.Quality]
  249. assert global_stack.getProperty("layer_height", "value") == container_indexes.Quality
  250. global_stack.qualityChanges = mock_layer_heights[container_indexes.QualityChanges]
  251. assert global_stack.getProperty("layer_height", "value") == container_indexes.QualityChanges
  252. global_stack.userChanges = mock_layer_heights[container_indexes.UserChanges]
  253. assert global_stack.getProperty("layer_height", "value") == container_indexes.UserChanges
  254. ## In definitions, test whether having no resolve allows us to find the value.
  255. def test_getPropertyNoResolveInDefinition(global_stack):
  256. value = unittest.mock.MagicMock() #Just sets the value for bed temperature.
  257. value.getProperty = lambda key, property, context = None: 10 if (key == "material_bed_temperature" and property == "value") else None
  258. with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock): #To guard against the type checking.
  259. global_stack.definition = value
  260. assert global_stack.getProperty("material_bed_temperature", "value") == 10 #No resolve, so fall through to value.
  261. ## In definitions, when the value is asked and there is a resolve function, it must get the resolve first.
  262. def test_getPropertyResolveInDefinition(global_stack):
  263. resolve_and_value = unittest.mock.MagicMock() #Sets the resolve and value for bed temperature.
  264. resolve_and_value.getProperty = lambda key, property, context = None: (7.5 if property == "resolve" else 5) if (key == "material_bed_temperature" and property in ("resolve", "value")) else None #7.5 resolve, 5 value.
  265. with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock): #To guard against the type checking.
  266. global_stack.definition = resolve_and_value
  267. assert global_stack.getProperty("material_bed_temperature", "value") == 7.5 #Resolve wins in the definition.
  268. ## In instance containers, when the value is asked and there is a resolve function, it must get the value first.
  269. def test_getPropertyResolveInInstance(global_stack):
  270. container_indices = cura.Settings.CuraContainerStack._ContainerIndexes
  271. instance_containers = {}
  272. for container_type in container_indices.IndexTypeMap:
  273. instance_containers[container_type] = unittest.mock.MagicMock() #Sets the resolve and value for bed temperature.
  274. instance_containers[container_type].getProperty = lambda key, property, context = None: (7.5 if property == "resolve" else (InstanceState.User if property == "state" else (5 if property != "limit_to_extruder" else "-1"))) if (key == "material_bed_temperature") else None #7.5 resolve, 5 value.
  275. instance_containers[container_type].getMetaDataEntry = unittest.mock.MagicMock(return_value = container_indices.IndexTypeMap[container_type]) #Make queries for the type return the desired type.
  276. instance_containers[container_indices.Definition].getProperty = lambda key, property, context = None: 10 if (key == "material_bed_temperature" and property == "value") else None #Definition only has value.
  277. with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock): #To guard against the type checking.
  278. global_stack.definition = instance_containers[container_indices.Definition] #Stack must have a definition.
  279. #For all instance container slots, the value reigns over resolve.
  280. global_stack.definitionChanges = instance_containers[container_indices.DefinitionChanges]
  281. assert global_stack.getProperty("material_bed_temperature", "value") == 5
  282. global_stack.variant = instance_containers[container_indices.Variant]
  283. assert global_stack.getProperty("material_bed_temperature", "value") == 5
  284. global_stack.material = instance_containers[container_indices.Material]
  285. assert global_stack.getProperty("material_bed_temperature", "value") == 5
  286. global_stack.quality = instance_containers[container_indices.Quality]
  287. assert global_stack.getProperty("material_bed_temperature", "value") == 5
  288. global_stack.qualityChanges = instance_containers[container_indices.QualityChanges]
  289. assert global_stack.getProperty("material_bed_temperature", "value") == 5
  290. global_stack.userChanges = instance_containers[container_indices.UserChanges]
  291. assert global_stack.getProperty("material_bed_temperature", "value") == 5
  292. ## Tests whether the value in instances gets evaluated before the resolve in definitions.
  293. def test_getPropertyInstancesBeforeResolve(global_stack):
  294. value = unittest.mock.MagicMock() #Sets just the value.
  295. value.getProperty = lambda key, property, context = None: (10 if property == "value" else (InstanceState.User if property != "limit_to_extruder" else "-1")) if key == "material_bed_temperature" else None
  296. value.getMetaDataEntry = unittest.mock.MagicMock(return_value = "quality")
  297. resolve = unittest.mock.MagicMock() #Sets just the resolve.
  298. resolve.getProperty = lambda key, property, context = None: 7.5 if (key == "material_bed_temperature" and property == "resolve") else None
  299. with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock): #To guard against the type checking.
  300. global_stack.definition = resolve
  301. global_stack.quality = value
  302. assert global_stack.getProperty("material_bed_temperature", "value") == 10
  303. ## Tests whether the hasUserValue returns true for settings that are changed in the user-changes container.
  304. def test_hasUserValueUserChanges(global_stack):
  305. container = unittest.mock.MagicMock()
  306. container.getMetaDataEntry = unittest.mock.MagicMock(return_value = "user")
  307. container.hasProperty = lambda key, property: key == "layer_height" #Only have the layer_height property set.
  308. global_stack.userChanges = container
  309. assert global_stack.hasUserValue("layer_height")
  310. assert not global_stack.hasUserValue("infill_sparse_density")
  311. assert not global_stack.hasUserValue("")
  312. ## Tests whether the hasUserValue returns true for settings that are changed in the quality-changes container.
  313. def test_hasUserValueQualityChanges(global_stack):
  314. container = unittest.mock.MagicMock()
  315. container.getMetaDataEntry = unittest.mock.MagicMock(return_value = "quality_changes")
  316. container.hasProperty = lambda key, property: key == "layer_height" #Only have the layer_height property set.
  317. global_stack.qualityChanges = container
  318. assert global_stack.hasUserValue("layer_height")
  319. assert not global_stack.hasUserValue("infill_sparse_density")
  320. assert not global_stack.hasUserValue("")
  321. ## Tests whether a container in some other place on the stack is correctly not recognised as user value.
  322. def test_hasNoUserValue(global_stack):
  323. container = unittest.mock.MagicMock()
  324. container.getMetaDataEntry = unittest.mock.MagicMock(return_value = "quality")
  325. container.hasProperty = lambda key, property: key == "layer_height" #Only have the layer_height property set.
  326. global_stack.quality = container
  327. assert not global_stack.hasUserValue("layer_height") #However this container is quality, so it's not a user value.
  328. ## Tests whether inserting a container is properly forbidden.
  329. def test_insertContainer(global_stack):
  330. with pytest.raises(InvalidOperationError):
  331. global_stack.insertContainer(0, unittest.mock.MagicMock())
  332. ## Tests whether removing a container is properly forbidden.
  333. def test_removeContainer(global_stack):
  334. with pytest.raises(InvalidOperationError):
  335. global_stack.removeContainer(unittest.mock.MagicMock())
  336. ## Tests whether changing the next stack is properly forbidden.
  337. def test_setNextStack(global_stack):
  338. with pytest.raises(InvalidOperationError):
  339. global_stack.setNextStack(unittest.mock.MagicMock())
  340. ## Tests setting properties directly on the global stack.
  341. @pytest.mark.parametrize("key, property, value", [
  342. ("layer_height", "value", 0.1337),
  343. ("foo", "value", 100),
  344. ("support_enabled", "value", True),
  345. ("layer_height", "default_value", 0.1337),
  346. ("layer_height", "is_bright_pink", "of course")
  347. ])
  348. def test_setPropertyUser(key, property, value, global_stack):
  349. user_changes = unittest.mock.MagicMock()
  350. user_changes.getMetaDataEntry = unittest.mock.MagicMock(return_value = "user")
  351. global_stack.userChanges = user_changes
  352. global_stack.setProperty(key, property, value) #The actual test.
  353. global_stack.userChanges.setProperty.assert_called_once_with(key, property, value, None, False) #Make sure that the user container gets a setProperty call.