mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-24 07:03:56 -06:00
Add tests for ExtruderManager
This commit is contained in:
parent
1c93dffc22
commit
9ad8d91ff9
3 changed files with 51 additions and 18 deletions
|
@ -11,9 +11,12 @@ import Savitar # Dont remove this line
|
|||
import Arcus # No really. Don't. It needs to be there!
|
||||
from UM.Qt.QtApplication import QtApplication # QtApplication import is required, even though it isn't used.
|
||||
# Even though your IDE says these files are not used, don't believe it. It's lying. They need to be there.
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
|
||||
from cura.CuraApplication import CuraApplication
|
||||
from cura.Settings.ExtruderManager import ExtruderManager
|
||||
from cura.UI.MachineActionManager import MachineActionManager
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
# Create a CuraApplication object that will be shared among all tests. It needs to be initialized.
|
||||
# Since we need to use it more that once, we create the application the first time and use its instance afterwards.
|
||||
|
@ -22,7 +25,24 @@ def application() -> CuraApplication:
|
|||
app = unittest.mock.MagicMock()
|
||||
return app
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def container_registry() -> ContainerRegistry:
|
||||
return MagicMock(name = "ContainerRegistry")
|
||||
|
||||
|
||||
# Returns a MachineActionManager instance.
|
||||
@pytest.fixture()
|
||||
def machine_action_manager(application) -> MachineActionManager:
|
||||
return MachineActionManager(application)
|
||||
|
||||
@pytest.fixture()
|
||||
def extruder_manager(application, container_registry) -> ExtruderManager:
|
||||
if ExtruderManager.getInstance() is not None:
|
||||
# Reset the data
|
||||
ExtruderManager._ExtruderManager__instance = None
|
||||
|
||||
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application)):
|
||||
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value=container_registry)):
|
||||
manager = ExtruderManager()
|
||||
return manager
|
Loading…
Add table
Add a link
Reference in a new issue