TestCuraSceneNode.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from UM.Math.Polygon import Polygon
  2. from UM.Scene.SceneNodeDecorator import SceneNodeDecorator
  3. from cura.Scene.CuraSceneNode import CuraSceneNode
  4. import pytest
  5. from unittest.mock import patch
  6. class MockedConvexHullDecorator(SceneNodeDecorator):
  7. def __init__(self):
  8. super().__init__()
  9. def getConvexHull(self):
  10. return Polygon([[5, 5], [-5, 5], [-5, -5], [5, -5]])
  11. def getPrintingArea(self):
  12. return Polygon([[5, 5], [-5, 5], [-5, -5], [5, -5]])
  13. class InvalidConvexHullDecorator(SceneNodeDecorator):
  14. def __init__(self):
  15. super().__init__()
  16. def getConvexHull(self):
  17. return Polygon()
  18. @pytest.fixture()
  19. def cura_scene_node():
  20. # Replace the SettingOverrideDecorator with an empty decorator
  21. with patch("cura.Scene.CuraSceneNode.SettingOverrideDecorator", SceneNodeDecorator):
  22. return CuraSceneNode()
  23. class TestCollidesWithAreas:
  24. def test_noConvexHull(self, cura_scene_node):
  25. assert not cura_scene_node.collidesWithAreas([Polygon([[10, 10], [-10, 10], [-10, -10], [10, -10]])])
  26. def test_convexHullIntersects(self, cura_scene_node):
  27. cura_scene_node.addDecorator(MockedConvexHullDecorator())
  28. assert cura_scene_node.collidesWithAreas([Polygon([[10, 10], [-10, 10], [-10, -10], [10, -10]])])
  29. def test_convexHullNoIntersection(self, cura_scene_node):
  30. cura_scene_node.addDecorator(MockedConvexHullDecorator())
  31. assert not cura_scene_node.collidesWithAreas([Polygon([[60, 60], [40, 60], [40, 40], [60, 40]])])
  32. def test_invalidConvexHull(self, cura_scene_node):
  33. cura_scene_node.addDecorator(InvalidConvexHullDecorator())
  34. assert not cura_scene_node.collidesWithAreas([Polygon([[10, 10], [-10, 10], [-10, -10], [10, -10]])])
  35. def test_outsideBuildArea(cura_scene_node):
  36. cura_scene_node.setOutsideBuildArea(True)
  37. assert cura_scene_node.isOutsideBuildArea