mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-07 05:53:59 -06:00
Add some simple tests to CuraSceneNode
This commit is contained in:
parent
6bb9e6097a
commit
28184ad999
2 changed files with 62 additions and 8 deletions
54
tests/TestCuraSceneNode.py
Normal file
54
tests/TestCuraSceneNode.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
from UM.Math.Polygon import Polygon
|
||||
from UM.Scene.SceneNodeDecorator import SceneNodeDecorator
|
||||
from cura.Scene.CuraSceneNode import CuraSceneNode
|
||||
import pytest
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
class TestConvexHullDecorator(SceneNodeDecorator):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def getConvexHull(self):
|
||||
return Polygon([[5, 5], [-5, 5], [-5, -5], [5, -5]])
|
||||
|
||||
|
||||
class TestInvalidConvexHullDecorator(SceneNodeDecorator):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def getConvexHull(self):
|
||||
return Polygon()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def cura_scene_node():
|
||||
# Replace the SettingOverrideDecorator with an empty decorator
|
||||
with patch("cura.Scene.CuraSceneNode.SettingOverrideDecorator", SceneNodeDecorator):
|
||||
return CuraSceneNode()
|
||||
|
||||
|
||||
class TestCollidesWithAreas:
|
||||
def test_noConvexHull(self, cura_scene_node):
|
||||
assert not cura_scene_node.collidesWithAreas([Polygon([[10, 10], [-10, 10], [-10, -10], [10, -10]])])
|
||||
|
||||
def test_convexHullIntersects(self, cura_scene_node):
|
||||
cura_scene_node.addDecorator(TestConvexHullDecorator())
|
||||
assert cura_scene_node.collidesWithAreas([Polygon([[10, 10], [-10, 10], [-10, -10], [10, -10]])])
|
||||
|
||||
def test_convexHullNoIntersection(self, cura_scene_node):
|
||||
cura_scene_node.addDecorator(TestConvexHullDecorator())
|
||||
|
||||
assert not cura_scene_node.collidesWithAreas([Polygon([[60, 60], [40, 60], [40, 40], [60, 40]])])
|
||||
|
||||
def test_invalidConvexHull(self, cura_scene_node):
|
||||
cura_scene_node.addDecorator(TestInvalidConvexHullDecorator())
|
||||
assert not cura_scene_node.collidesWithAreas([Polygon([[10, 10], [-10, 10], [-10, -10], [10, -10]])])
|
||||
|
||||
|
||||
def test_outsideBuildArea(cura_scene_node):
|
||||
cura_scene_node.setOutsideBuildArea(True)
|
||||
assert cura_scene_node.isOutsideBuildArea
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue