From 28578fa39087e5b1ac3ea438250ee307bffa50b7 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 19 Oct 2017 23:49:01 +0200 Subject: [PATCH] unit test for backlinks on expressions --- src/Mod/Test/Document.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Mod/Test/Document.py b/src/Mod/Test/Document.py index 25ae722d30..49ca6b4c0e 100644 --- a/src/Mod/Test/Document.py +++ b/src/Mod/Test/Document.py @@ -1254,3 +1254,32 @@ class DocumentPropertyCases(unittest.TestCase): def tearDown(self): #closing doc FreeCAD.closeDocument("PropertyTests") + + +class DocumentExpressionCases(unittest.TestCase): + def setUp(self): + self.Doc = FreeCAD.newDocument() + self.Obj1 = self.Doc.addObject("App::FeatureTest","Test") + self.Obj2 = self.Doc.addObject("App::FeatureTest","Test") + + def testExpression(self): + # set the object twice to test that the backlinks are removed when overwriting the expression + self.Obj2.setExpression('Placement.Rotation.Angle', u'%s.Placement.Rotation.Angle' % self.Obj1.Name) + self.Obj2.setExpression('Placement.Rotation.Angle', u'%s.Placement.Rotation.Angle' % self.Obj1.Name) + self.Obj1.Placement = FreeCAD.Placement(FreeCAD.Vector(0,0,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),10)) + self.Doc.recompute() + self.assertEqual(self.Obj1.Placement.Rotation.Angle, self.Obj2.Placement.Rotation.Angle) + # clear the expression + self.Obj2.setExpression('Placement.Rotation.Angle', None) + self.assertEqual(self.Obj1.Placement.Rotation.Angle, self.Obj2.Placement.Rotation.Angle) + self.Doc.recompute() + self.assertEqual(self.Obj1.Placement.Rotation.Angle, self.Obj2.Placement.Rotation.Angle) + # touch the objects to perform a recompute + self.Obj1.Placement = self.Obj1.Placement + self.Obj2.Placement = self.Obj2.Placement + # must not raise a topological error + self.assertEqual(self.Doc.recompute(), 2) + + def tearDown(self): + #closing doc + FreeCAD.closeDocument(self.Doc.Name)