unit test for backlinks on expressions

This commit is contained in:
wmayer
2017-10-19 23:49:01 +02:00
parent e06ae2cfde
commit 489c8c9aef

View File

@@ -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)