Detect circular references in sketches, and add corresponding tests (#11716)
* Possible fix for 10482 circular reference regression with tests * Remove redundant test * Cleanup pre PR * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from FreeCAD import Vector
|
||||
from FreeCAD import Vector, newDocument, closeDocument
|
||||
import Part
|
||||
|
||||
import unittest
|
||||
@@ -23,3 +23,27 @@ class RegressionTests(unittest.TestCase):
|
||||
def test_OptimalBox(self):
|
||||
box = Part.makeBox(1, 1, 1)
|
||||
self.assertTrue(box.optimalBoundingBox(True, False).isValid())
|
||||
|
||||
def test_CircularReference(self):
|
||||
# put me in def setup(self): ?
|
||||
self.Doc = newDocument("TestSketchExpr")
|
||||
|
||||
cube = self.Doc.addObject("Part::Box","Cube")
|
||||
cube.setExpression('Length', 'Width + 10mm')
|
||||
with self.assertRaises(RuntimeError) as context:
|
||||
cube.setExpression('Width', 'Length + 10mm')
|
||||
assert "Width reference creates a cyclic dependency." in str(context.exception)
|
||||
|
||||
cube.setExpression('.Placement.Base.x', '.Placement.Base.y + 10mm')
|
||||
with self.assertRaises(RuntimeError) as context:
|
||||
cube.setExpression('.Placement.Base.y', '.Placement.Base.x + 10mm')
|
||||
assert ".Placement.Base.y reference creates a cyclic dependency." in str(context.exception)
|
||||
|
||||
cube.recompute()
|
||||
v1 = cube.Placement.Base
|
||||
cube.recompute()
|
||||
assert cube.Placement.Base.isEqual(v1,1e-6)
|
||||
|
||||
# Put me in def tearDown(self): ?
|
||||
closeDocument(self.Doc.Name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user