[Part]add test for PropertyTopoShapeList
This commit is contained in:
@@ -64,6 +64,7 @@ set(Part_tests
|
||||
parttests/__init__.py
|
||||
parttests/part_test_objects.py
|
||||
parttests/regression_tests.py
|
||||
parttests/TopoShapeListTest.py
|
||||
)
|
||||
|
||||
add_custom_target(PartScripts ALL SOURCES
|
||||
|
||||
@@ -28,6 +28,7 @@ from FreeCAD import Base
|
||||
App = FreeCAD
|
||||
|
||||
from parttests.regression_tests import RegressionTests
|
||||
from parttests.TopoShapeListTest import TopoShapeListTest
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# define the test cases to test the FreeCAD Part module
|
||||
|
||||
58
src/Mod/Part/parttests/TopoShapeListTest.py
Normal file
58
src/Mod/Part/parttests/TopoShapeListTest.py
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# basic test script for PropertyTopoShapeList
|
||||
|
||||
import FreeCAD as App
|
||||
import Part
|
||||
import unittest
|
||||
from PySide import QtCore
|
||||
|
||||
class TopoShapeListTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
"""Creates a document and a FeaturePython that has a PropertyTopoShapeList property"""
|
||||
print("TopoShapeListTest - setting up")
|
||||
self.fileName = "/tmp/TopoShapeListTest.FCStd"
|
||||
self.objName = "TestObject"
|
||||
App.newDocument("TopoShapeList")
|
||||
App.setActiveDocument("TopoShapeList")
|
||||
doc = App.newDocument()
|
||||
obj = doc.addObject("App::FeaturePython", self.objName)
|
||||
obj.addProperty("Part::PropertyTopoShapeList", "Shapes")
|
||||
box = Part.makeBox(1,1,1)
|
||||
box2 = Part.makeBox(1,1,2)
|
||||
box3 = Part.makeBox(1,1,3)
|
||||
obj.Shapes = [box, box2, box3]
|
||||
doc.saveAs(self.fileName)
|
||||
App.closeDocument(doc.Name)
|
||||
print("TopoShapeListTest: setUp complete")
|
||||
|
||||
def tearDown(self):
|
||||
print("TopoShapeListTest finished")
|
||||
App.closeDocument("TopoShapeList")
|
||||
|
||||
def testMakeTopoShapeList(self):
|
||||
"""Tests PropertyTopoShapeList"""
|
||||
print("running TopoShapeListTest")
|
||||
doc = App.openDocument(self.fileName)
|
||||
obj = doc.getObject(self.objName)
|
||||
boxes = obj.Shapes
|
||||
|
||||
maxError = 0.0000001
|
||||
error = abs(1.0 - boxes[0].Volume)
|
||||
self.assertLessEqual(error, maxError, "TopoShapeList entry 0 has wrong volume: {0}".format(boxes[0].Volume))
|
||||
error = abs(2.0 - boxes[1].Volume)
|
||||
self.assertLessEqual(error, maxError, "TopoShapeList entry 1 has wrong volume: {0}".format(boxes[1].Volume))
|
||||
error = abs(3.0 - boxes[2].Volume)
|
||||
self.assertLessEqual(error, maxError, "TopoShapeList entry 2 has wrong volume: {0}".format(boxes[2].Volume))
|
||||
|
||||
twoboxes = [boxes[1], boxes[2]]
|
||||
doc.openTransaction("Change shapes")
|
||||
obj.Shapes = twoboxes
|
||||
doc.commitTransaction()
|
||||
self.assertEqual(len(obj.Shapes), 2, "TopoShapeList has wrong entry count (1): {0}".format(len(obj.Shapes)))
|
||||
|
||||
doc.undo()
|
||||
|
||||
self.assertEqual(len(obj.Shapes), 3, "TopoShapeList has wrong entry count (2): {0}".format(len(obj.Shapes)))
|
||||
|
||||
Reference in New Issue
Block a user