mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 03:04:23 +08:00
Add unit test
CURA-10719
This commit is contained in:
parent
9b6abf80d7
commit
c436dd36cf
@ -286,7 +286,7 @@ class ThreeMFWriter(MeshWriter):
|
||||
plugin_ids.add(plugin_id)
|
||||
|
||||
# Go through all stacks and find all the plugin id contained in the project
|
||||
global_stack = Application.getInstance().getMachineManager().activeMachine
|
||||
global_stack = CuraApplication.getInstance().getMachineManager().activeMachine
|
||||
addPluginIdsInStack(global_stack)
|
||||
|
||||
for container in global_stack.getContainers():
|
||||
|
56
plugins/3MFWriter/tests/TestMFWriter.py
Normal file
56
plugins/3MFWriter/tests/TestMFWriter.py
Normal file
@ -0,0 +1,56 @@
|
||||
import sys
|
||||
import os.path
|
||||
from typing import Dict, Optional
|
||||
|
||||
from unittest.mock import patch, MagicMock, PropertyMock
|
||||
|
||||
from UM.PackageManager import PackageManager
|
||||
from cura.CuraApplication import CuraApplication
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
|
||||
|
||||
import ThreeMFWriter
|
||||
|
||||
PLUGIN_ID = "my_plugin"
|
||||
DISPLAY_NAME = "MyPlugin"
|
||||
PACKAGE_VERSION = "0.0.1"
|
||||
SDK_VERSION = "8.0.0"
|
||||
|
||||
|
||||
def package_manager() -> MagicMock:
|
||||
pm = MagicMock(spec=PackageManager)
|
||||
pm.getInstalledPackageInfo.return_value = {
|
||||
"display_name": DISPLAY_NAME,
|
||||
"package_version": PACKAGE_VERSION,
|
||||
"sdk_version_semver": SDK_VERSION
|
||||
}
|
||||
return pm
|
||||
|
||||
|
||||
def machine_manager() -> MagicMock:
|
||||
mm = MagicMock(spec=PackageManager)
|
||||
active_machine = MagicMock()
|
||||
active_machine.getAllKeys.return_value = ["infill_pattern", "layer_height", "material_bed_temperature"]
|
||||
active_machine.getProperty.return_value = f"PLUGIN::{PLUGIN_ID}@{PACKAGE_VERSION}::custom_value"
|
||||
active_machine.getContainers.return_value = []
|
||||
active_machine.extruderList = []
|
||||
mm.activeMachine = active_machine
|
||||
return mm
|
||||
|
||||
|
||||
def application():
|
||||
app = MagicMock()
|
||||
app.getPackageManager.return_value = package_manager()
|
||||
app.getMachineManager.return_value = machine_manager()
|
||||
return app
|
||||
|
||||
|
||||
def test_enumParsing():
|
||||
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application())):
|
||||
packages_metadata = ThreeMFWriter.ThreeMFWriter._getPluginPackageMetadata()[0]
|
||||
|
||||
assert packages_metadata.get("id") == PLUGIN_ID
|
||||
assert packages_metadata.get("display_name") == DISPLAY_NAME
|
||||
assert packages_metadata.get("package_version") == PACKAGE_VERSION
|
||||
assert packages_metadata.get("sdk_version_semver") == SDK_VERSION
|
||||
assert packages_metadata.get("type") == "plugin"
|
Loading…
x
Reference in New Issue
Block a user