1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
# Copyright (c) 2021 Ultimaker B.V.
# Uranium is released under the terms of the LGPLv3 or higher.
from typing import cast
from unittest.mock import MagicMock
import pytest
from UM.Qt.QtApplication import QtApplication #QTApplication import is required, even though it isn't used.
from UM.Application import Application
from UM.Qt.QtRenderer import QtRenderer
from UM.Signal import Signal
from UM.PluginRegistry import PluginRegistry
from UM.VersionUpgradeManager import VersionUpgradeManager
# This mock application must extend from Application and not QtApplication otherwise some QObjects are created and
# a segfault is raised.
class FixtureApplication(Application):
engineCreatedSignal = Signal()
def __init__(self):
super().__init__(name = "test", version = "1.0", api_version = "8.0.0")
super().initialize()
Signal._signalQueue = self
def functionEvent(self, event):
event.call()
def parseCommandLine(self):
pass
def processEvents(self):
pass
def getRenderer(self):
return MagicMock()
def showMessage(self, message):
pass
@pytest.fixture()
def application():
# Since we need to use it more that once, we create the application the first time and use its instance the second
application = FixtureApplication.getInstance()
if application is None:
application = FixtureApplication()
return application
@pytest.fixture()
def plugin_registry(application):
PluginRegistry._PluginRegistry__instance = None
plugin_registry = PluginRegistry(application)
plugin_registry._plugin_locations = [] # Clear pre-defined plugin locations
return plugin_registry
@pytest.fixture()
def upgrade_manager(application):
VersionUpgradeManager._VersionUpgradeManager__instance = None
upgrade_manager = VersionUpgradeManager(application)
return upgrade_manager
|