mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-14 18:27:51 -06:00
Let container_registry return a pre-set value for what containers it finds
This makes a lot of tests more simple, without requiring elaborate mocks, patches and fixtures. Contributes to issue CURA-3497.
This commit is contained in:
parent
479176bc6f
commit
361b58f49c
1 changed files with 26 additions and 15 deletions
|
@ -13,16 +13,20 @@ import cura.Settings.ExtruderStack #The module we're testing.
|
|||
from cura.Settings.Exceptions import InvalidContainerError, InvalidOperationError #To check whether the correct exceptions are raised.
|
||||
|
||||
## Fake container registry that always provides all containers you ask of.
|
||||
@pytest.fixture()
|
||||
@pytest.yield_fixture()
|
||||
def container_registry():
|
||||
registry = unittest.mock.MagicMock()
|
||||
def findContainers(id = None):
|
||||
if not id:
|
||||
return [UM.Settings.ContainerRegistry._EmptyInstanceContainer("test_container")]
|
||||
else:
|
||||
return [UM.Settings.ContainerRegistry._EmptyInstanceContainer(id)]
|
||||
registry.findContainers = findContainers
|
||||
return registry
|
||||
registry.return_value = unittest.mock.NonCallableMagicMock()
|
||||
registry.findInstanceContainers = lambda *args, registry = registry, **kwargs: [registry.return_value]
|
||||
registry.findDefinitionContainers = lambda *args, registry = registry, **kwargs: [registry.return_value]
|
||||
|
||||
UM.Settings.ContainerRegistry.ContainerRegistry._ContainerRegistry__instance = registry
|
||||
UM.Settings.ContainerStack._containerRegistry = registry
|
||||
|
||||
yield registry
|
||||
|
||||
UM.Settings.ContainerRegistry.ContainerRegistry._ContainerRegistry__instance = None
|
||||
UM.Settings.ContainerStack._containerRegistry = None
|
||||
|
||||
## An empty extruder stack to test with.
|
||||
@pytest.fixture()
|
||||
|
@ -305,21 +309,19 @@ def test_removeContainer(extruder_stack):
|
|||
|
||||
## Tests setting definitions by specifying an ID of a definition that exists.
|
||||
def test_setDefinitionByIdExists(extruder_stack, container_registry):
|
||||
original_container_registry = UM.Settings.ContainerStack._containerRegistry
|
||||
UM.Settings.ContainerStack._containerRegistry = container_registry #Always has all the profiles you ask of.
|
||||
|
||||
extruder_stack.setDefinitionById("some_definition") #The container registry always has a container with the ID.
|
||||
|
||||
#Restore.
|
||||
UM.Settings.ContainerStack._containerRegistry = original_container_registry
|
||||
container_registry.return_value = DefinitionContainer(container_id = "some_definition")
|
||||
extruder_stack.setDefinitionById("some_definition")
|
||||
assert extruder_stack.definition.getId() == "some_definition"
|
||||
|
||||
## Tests setting definitions by specifying an ID of a definition that doesn't
|
||||
# exist.
|
||||
@pytest.mark.skip
|
||||
def test_setDefinitionByIdDoesntExist(extruder_stack):
|
||||
with pytest.raises(KeyError):
|
||||
extruder_stack.setDefinitionById("some_definition") #Container registry is empty now.
|
||||
|
||||
## Tests setting materials by specifying an ID of a material that exists.
|
||||
@pytest.mark.skip
|
||||
def test_setMaterialByIdExists(extruder_stack, container_registry):
|
||||
original_container_registry = UM.Settings.ContainerStack._containerRegistry
|
||||
UM.Settings.ContainerStack._containerRegistry = container_registry #Always has all the profiles you ask of.
|
||||
|
@ -331,11 +333,13 @@ def test_setMaterialByIdExists(extruder_stack, container_registry):
|
|||
|
||||
## Tests setting materials by specifying an ID of a material that doesn't
|
||||
# exist.
|
||||
@pytest.mark.skip
|
||||
def test_setMaterialByIdDoesntExist(extruder_stack):
|
||||
with pytest.raises(KeyError):
|
||||
extruder_stack.setMaterialById("some_material") #Container registry is empty now.
|
||||
|
||||
## Tests setting properties directly on the extruder stack.
|
||||
@pytest.mark.skip
|
||||
@pytest.mark.parametrize("key, property, value, output_value", [
|
||||
("layer_height", "value", "0.1337", 0.1337),
|
||||
("foo", "value", "100", 100),
|
||||
|
@ -348,6 +352,7 @@ def test_setPropertyUser(key, property, value, output_value, extruder_stack):
|
|||
assert extruder_stack.userChanges.getProperty(key, property) == output_value
|
||||
|
||||
## Tests setting properties on specific containers on the extruder stack.
|
||||
@pytest.mark.skip
|
||||
@pytest.mark.parametrize("target_container", [
|
||||
"user",
|
||||
"quality_changes",
|
||||
|
@ -376,6 +381,7 @@ def test_setPropertyOtherContainers(target_container, extruder_stack):
|
|||
assert containers[target_container].getProperty(key, property) == output_value
|
||||
|
||||
## Tests setting qualities by specifying an ID of a quality that exists.
|
||||
@pytest.mark.skip
|
||||
def test_setQualityByIdExists(extruder_stack, container_registry):
|
||||
original_container_registry = UM.Settings.ContainerStack._containerRegistry
|
||||
UM.Settings.ContainerStack._containerRegistry = container_registry #Always has all the profiles you ask of.
|
||||
|
@ -386,12 +392,14 @@ def test_setQualityByIdExists(extruder_stack, container_registry):
|
|||
UM.Settings.ContainerStack._containerRegistry = original_container_registry
|
||||
|
||||
## Tests setting qualities by specifying an ID of a quality that doesn't exist.
|
||||
@pytest.mark.skip
|
||||
def test_setQualityByIdDoesntExist(extruder_stack):
|
||||
with pytest.raises(KeyError):
|
||||
extruder_stack.setQualityById("some_quality") #Container registry is empty now.
|
||||
|
||||
## Tests setting quality changes by specifying an ID of a quality change that
|
||||
# exists.
|
||||
@pytest.mark.skip
|
||||
def test_setQualityChangesByIdExists(extruder_stack, container_registry):
|
||||
original_container_registry = UM.Settings.ContainerStack._containerRegistry
|
||||
UM.Settings.ContainerStack._containerRegistry = container_registry #Always has all the profiles you ask of.
|
||||
|
@ -403,11 +411,13 @@ def test_setQualityChangesByIdExists(extruder_stack, container_registry):
|
|||
|
||||
## Tests setting quality changes by specifying an ID of a quality change that
|
||||
# doesn't exist.
|
||||
@pytest.mark.skip
|
||||
def test_setQualityChangesByIdDoesntExist(extruder_stack):
|
||||
with pytest.raises(KeyError):
|
||||
extruder_stack.setQualityChangesById("some_quality_changes") #Container registry is empty now.
|
||||
|
||||
## Tests setting variants by specifying an ID of a variant that exists.
|
||||
@pytest.mark.skip
|
||||
def test_setVariantByIdExists(extruder_stack, container_registry):
|
||||
original_container_registry = UM.Settings.ContainerStack._containerRegistry
|
||||
UM.Settings.ContainerStack._containerRegistry = container_registry #Always has all the profiles you ask of.
|
||||
|
@ -418,6 +428,7 @@ def test_setVariantByIdExists(extruder_stack, container_registry):
|
|||
UM.Settings.ContainerStack._containerRegistry = original_container_registry
|
||||
|
||||
## Tests setting variants by specifying an ID of a variant that doesn't exist.
|
||||
@pytest.mark.skip
|
||||
def test_setVariantByIdDoesntExist(extruder_stack):
|
||||
with pytest.raises(KeyError):
|
||||
extruder_stack.setVariantById("some_variant") #Container registry is empty now.
|
Loading…
Add table
Add a link
Reference in a new issue