TestMFWriter.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import sys
  2. import os.path
  3. from typing import Dict, Optional
  4. import pytest
  5. from unittest.mock import patch, MagicMock, PropertyMock
  6. from UM.PackageManager import PackageManager
  7. from cura.CuraApplication import CuraApplication
  8. sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
  9. import ThreeMFWriter
  10. PLUGIN_ID = "my_plugin"
  11. DISPLAY_NAME = "MyPlugin"
  12. PACKAGE_VERSION = "0.0.1"
  13. SDK_VERSION = "8.0.0"
  14. @pytest.fixture
  15. def package_manager() -> MagicMock:
  16. pm = MagicMock(spec=PackageManager)
  17. pm.getInstalledPackageInfo.return_value = {
  18. "display_name": DISPLAY_NAME,
  19. "package_version": PACKAGE_VERSION,
  20. "sdk_version_semver": SDK_VERSION
  21. }
  22. return pm
  23. @pytest.fixture
  24. def machine_manager() -> MagicMock:
  25. mm = MagicMock(spec=PackageManager)
  26. active_machine = MagicMock()
  27. active_machine.getAllKeys.return_value = ["infill_pattern", "layer_height", "material_bed_temperature"]
  28. active_machine.getProperty.return_value = f"PLUGIN::{PLUGIN_ID}@{PACKAGE_VERSION}::custom_value"
  29. active_machine.getContainers.return_value = []
  30. active_machine.extruderList = []
  31. mm.activeMachine = active_machine
  32. return mm
  33. @pytest.fixture
  34. def application(package_manager, machine_manager):
  35. app = MagicMock()
  36. app.getPackageManager.return_value = package_manager
  37. app.getMachineManager.return_value = machine_manager
  38. return app
  39. def test_enumParsing(application):
  40. with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application)):
  41. packages_metadata = ThreeMFWriter.ThreeMFWriter._getPluginPackageMetadata()[0]
  42. assert packages_metadata.get("id") == PLUGIN_ID
  43. assert packages_metadata.get("display_name") == DISPLAY_NAME
  44. assert packages_metadata.get("package_version") == PACKAGE_VERSION
  45. assert packages_metadata.get("sdk_version_semver") == SDK_VERSION
  46. assert packages_metadata.get("type") == "plugin"