mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-22 06:03:57 -06:00
Fix tests with new lazy-loading technique
The new lazy loading requests different functions from the registry so we need to mock that out. Also fix the manual insertion of things into the lazy-loaded mapping. Contributes to issue CURA-6793.
This commit is contained in:
parent
7348c70af6
commit
5624f0a8ae
1 changed files with 5 additions and 34 deletions
|
@ -29,6 +29,7 @@ def createMockedStack(definition_id: str):
|
||||||
def container_registry():
|
def container_registry():
|
||||||
result = MagicMock()
|
result = MagicMock()
|
||||||
result.findContainerStacks = MagicMock(return_value = [createMockedStack("machine_1"), createMockedStack("machine_2")])
|
result.findContainerStacks = MagicMock(return_value = [createMockedStack("machine_1"), createMockedStack("machine_2")])
|
||||||
|
result.findContainersMetadata = lambda id: [{"id": id}] if id in {"machine_1", "machine_2"} else []
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -43,36 +44,6 @@ def test_containerTreeInit(container_registry):
|
||||||
assert "machine_1" in container_tree.machines
|
assert "machine_1" in container_tree.machines
|
||||||
assert "machine_2" in container_tree.machines
|
assert "machine_2" in container_tree.machines
|
||||||
|
|
||||||
|
|
||||||
def test_newMachineAdded(container_registry):
|
|
||||||
mocked_definition_container = MagicMock(spec = DefinitionContainer)
|
|
||||||
mocked_definition_container.getId = MagicMock(return_value = "machine_3")
|
|
||||||
|
|
||||||
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
|
|
||||||
container_tree = ContainerTree()
|
|
||||||
# machine_3 shouldn't be there, as on init it wasn't in the registry
|
|
||||||
assert "machine_3" not in container_tree.machines
|
|
||||||
|
|
||||||
# It should only react when a globalStack is added.
|
|
||||||
container_tree._machineAdded(mocked_definition_container)
|
|
||||||
assert "machine_3" not in container_tree.machines
|
|
||||||
|
|
||||||
container_tree._machineAdded(createMockedStack("machine_3"))
|
|
||||||
assert "machine_3" in container_tree.machines
|
|
||||||
|
|
||||||
|
|
||||||
def test_alreadyKnownMachineAdded(container_registry):
|
|
||||||
mocked_definition_container = MagicMock(spec = DefinitionContainer)
|
|
||||||
mocked_definition_container.getId = MagicMock(return_value = "machine_2")
|
|
||||||
|
|
||||||
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
|
|
||||||
container_tree = ContainerTree()
|
|
||||||
assert len(container_tree.machines) == 2
|
|
||||||
|
|
||||||
# The ID is already there, so no machine should be added.
|
|
||||||
container_tree._machineAdded(mocked_definition_container)
|
|
||||||
assert len(container_tree.machines) == 2
|
|
||||||
|
|
||||||
def test_getCurrentQualityGroupsNoGlobalStack(container_registry):
|
def test_getCurrentQualityGroupsNoGlobalStack(container_registry):
|
||||||
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
|
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
|
||||||
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = MagicMock(getGlobalContainerStack = MagicMock(return_value = None)))):
|
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = MagicMock(getGlobalContainerStack = MagicMock(return_value = None)))):
|
||||||
|
@ -84,7 +55,7 @@ def test_getCurrentQualityGroupsNoGlobalStack(container_registry):
|
||||||
def test_getCurrentQualityGroups(container_registry, application):
|
def test_getCurrentQualityGroups(container_registry, application):
|
||||||
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
|
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
|
||||||
container_tree = ContainerTree()
|
container_tree = ContainerTree()
|
||||||
container_tree.machines["current_global_stack"] = MagicMock() # Mock so that we can track whether the getQualityGroups function gets called with correct parameters.
|
container_tree.machines.machines["current_global_stack"] = MagicMock() # Mock so that we can track whether the getQualityGroups function gets called with correct parameters.
|
||||||
|
|
||||||
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = application)):
|
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = application)):
|
||||||
result = container_tree.getCurrentQualityGroups()
|
result = container_tree.getCurrentQualityGroups()
|
||||||
|
@ -108,7 +79,7 @@ def test_getCurrentQualityChangesGroupsNoGlobalStack(container_registry):
|
||||||
def test_getCurrentQualityChangesGroups(container_registry, application):
|
def test_getCurrentQualityChangesGroups(container_registry, application):
|
||||||
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
|
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
|
||||||
container_tree = ContainerTree()
|
container_tree = ContainerTree()
|
||||||
container_tree.machines["current_global_stack"] = MagicMock() # Mock so that we can track whether the getQualityGroups function gets called with correct parameters.
|
container_tree.machines.machines["current_global_stack"] = MagicMock() # Mock so that we can track whether the getQualityGroups function gets called with correct parameters.
|
||||||
|
|
||||||
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = application)):
|
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = application)):
|
||||||
result = container_tree.getCurrentQualityChangesGroups()
|
result = container_tree.getCurrentQualityChangesGroups()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue