From efe6abb54fe3a0b170dfb10c736c24474aedf83d Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Sun, 30 Jun 2013 13:55:08 -0300 Subject: [PATCH 1/2] Draft: Added test suite --- src/Mod/Draft/CMakeLists.txt | 1 + src/Mod/Draft/TestDraft.py | 72 +++++++++++++++++++++++++++++++ src/Mod/Test/TestApp.py | 1 + src/WindowsInstaller/ModDraft.wxi | 1 + 4 files changed, 75 insertions(+) create mode 100644 src/Mod/Draft/TestDraft.py diff --git a/src/Mod/Draft/CMakeLists.txt b/src/Mod/Draft/CMakeLists.txt index e380eb193..95a21c33f 100644 --- a/src/Mod/Draft/CMakeLists.txt +++ b/src/Mod/Draft/CMakeLists.txt @@ -17,6 +17,7 @@ SET(Draft_SRCS importAirfoilDAT.py macros.py Draft_rc.py + TestDraft.py ) SOURCE_GROUP("" FILES ${Draft_SRCS}) diff --git a/src/Mod/Draft/TestDraft.py b/src/Mod/Draft/TestDraft.py new file mode 100644 index 000000000..0b95f16cf --- /dev/null +++ b/src/Mod/Draft/TestDraft.py @@ -0,0 +1,72 @@ +# Unit test for the Draft module + +#*************************************************************************** +#* (c) Yorik van Havre 2013 * +#* * +#* This file is part of the FreeCAD CAx development system. * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the GNU Lesser General Public License (LGPL) * +#* as published by the Free Software Foundation; either version 2 of * +#* the License, or (at your option) any later version. * +#* for detail see the LICENCE text file. * +#* * +#* FreeCAD is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* GNU Library General Public License for more details. * +#* * +#* You should have received a copy of the GNU Library General Public * +#* License along with FreeCAD; if not, write to the Free Software * +#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +#* USA * +#* * +#* Werner Mayer 2005 * +#***************************************************************************/ + +import FreeCAD, os, unittest, FreeCADGui, Draft + +class DraftTest(unittest.TestCase): + + def setUp(self): + # setting a new document to hold the tests + if FreeCAD.ActiveDocument: + if FreeCAD.ActiveDocument.Name != "DraftTest": + FreeCAD.newDocument("DraftTest") + else: + FreeCAD.newDocument("DraftTest") + FreeCAD.setActiveDocument("DraftTest") + + def testPivy(self): + # first checking if pivy is working + FreeCAD.Console.PrintLog ('Checking Pivy...\n') + from pivy import coin + c = coin.SoCube() + FreeCADGui.ActiveDocument.ActiveView.getSceneGraph().addChild(c) + self.failUnless(c,"Pivy is not working properly") + + def testWire(self): + # testing the Wire tool + FreeCAD.Console.PrintLog ('Checking Draft Wire...\n') + Draft.makeWire([FreeCAD.Vector(0,0,0),FreeCAD.Vector(2,0,0),FreeCAD.Vector(2,2,0)]) + self.failUnless(FreeCAD.ActiveDocument.getObject("DWire"),"Draft Wire failed") + + def testArc(self): + # testing the Arc tool + FreeCAD.Console.PrintLog ('Checking Draft Arc...\n') + Draft.makeCircle(2, startangle=0, endangle=90) + self.failUnless(FreeCAD.ActiveDocument.getObject("Arc"),"Draft Arc failed") + + def testDimension(self): + # testing the Arc tool + FreeCAD.Console.PrintLog ('Checking Draft Dimension...\n') + Draft.makeDimension(FreeCAD.Vector(0,0,0),FreeCAD.Vector(2,0,0),FreeCAD.Vector(1,-1,0)) + self.failUnless(FreeCAD.ActiveDocument.getObject("Dimension"),"Draft Dimension failed") + + def tearDown(self): + #closing doc + #FreeCAD.closeDocument("DraftTest") + pass + + + diff --git a/src/Mod/Test/TestApp.py b/src/Mod/Test/TestApp.py index 2eab8fe40..f70253d05 100644 --- a/src/Mod/Test/TestApp.py +++ b/src/Mod/Test/TestApp.py @@ -51,6 +51,7 @@ def All(): suite.addTest(unittest.defaultTestLoader.loadTestsFromName("TestSketcherGui") ) suite.addTest(unittest.defaultTestLoader.loadTestsFromName("TestPartGui") ) suite.addTest(unittest.defaultTestLoader.loadTestsFromName("TestPartDesignGui") ) + suite.addTest(unittest.defaultTestLoader.loadTestsFromName("TestDraft") ) return suite diff --git a/src/WindowsInstaller/ModDraft.wxi b/src/WindowsInstaller/ModDraft.wxi index 2a212d379..a80dd345e 100644 --- a/src/WindowsInstaller/ModDraft.wxi +++ b/src/WindowsInstaller/ModDraft.wxi @@ -41,6 +41,7 @@ + From 578fefc9b1975691bc59b9f6a24cd2a8ea4082f2 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Thu, 15 Aug 2013 19:24:28 -0300 Subject: [PATCH 2/2] Arch: Added test suite --- src/Mod/Arch/CMakeLists.txt | 1 + src/Mod/Arch/TestArch.py | 53 +++++++++++++++++++ src/Mod/Draft/Draft.py | 8 ++- src/Mod/Draft/TestDraft.py | 88 ++++++++++++++++++++++++++++---- src/Mod/Test/TestApp.py | 1 + src/WindowsInstaller/ModArch.wxi | 1 + 6 files changed, 142 insertions(+), 10 deletions(-) create mode 100644 src/Mod/Arch/TestArch.py diff --git a/src/Mod/Arch/CMakeLists.txt b/src/Mod/Arch/CMakeLists.txt index 16584b8c4..e55bf558f 100644 --- a/src/Mod/Arch/CMakeLists.txt +++ b/src/Mod/Arch/CMakeLists.txt @@ -22,6 +22,7 @@ SET(Arch_SRCS ArchRoof.py importWebGL.py ArchSpace.py + TestArch.py ) SOURCE_GROUP("" FILES ${Arch_SRCS}) diff --git a/src/Mod/Arch/TestArch.py b/src/Mod/Arch/TestArch.py new file mode 100644 index 000000000..7f86153e4 --- /dev/null +++ b/src/Mod/Arch/TestArch.py @@ -0,0 +1,53 @@ +# Unit test for the Arch module + +#*************************************************************************** +#* (c) Yorik van Havre 2013 * +#* * +#* This file is part of the FreeCAD CAx development system. * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the GNU Lesser General Public License (LGPL) * +#* as published by the Free Software Foundation; either version 2 of * +#* the License, or (at your option) any later version. * +#* for detail see the LICENCE text file. * +#* * +#* FreeCAD is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* GNU Library General Public License for more details. * +#* * +#* You should have received a copy of the GNU Library General Public * +#* License along with FreeCAD; if not, write to the Free Software * +#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +#* USA * +#* * +#***************************************************************************/ + +import FreeCAD, os, unittest, FreeCADGui, Arch, Draft + +class ArchTest(unittest.TestCase): + + def setUp(self): + # setting a new document to hold the tests + if FreeCAD.ActiveDocument: + if FreeCAD.ActiveDocument.Name != "ArchTest": + FreeCAD.newDocument("ArchTest") + else: + FreeCAD.newDocument("ArchTest") + FreeCAD.setActiveDocument("ArchTest") + + def testWall(self): + FreeCAD.Console.PrintLog ('Checking Arch Wall...\n') + l=Draft.makeLine(FreeCAD.Vector(0,0,0),FreeCAD.Vector(-2,0,0)) + w = Arch.makeWall(l) + self.failUnless(w,"Arch Wall failed") + + def testStructure(self): + FreeCAD.Console.PrintLog ('Checking Arch Structure...\n') + s = Arch.makeStructure(length=2,width=3,hright=5) + self.failUnless(s,"Arch Structure failed") + + def tearDown(self): + FreeCAD.closeDocument("ArchTest") + pass + diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 211e99eb3..07871b189 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -514,7 +514,11 @@ def makeCircle(radius, placement=None, face=True, startangle=None, endangle=None is passed, its Curve must be a Part.Circle''' import Part, DraftGeomUtils if placement: typecheck([(placement,FreeCAD.Placement)], "makeCircle") - obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","Circle") + if startangle != endangle: + n = "Arc" + else: + n = "Circle" + obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython",n) _Circle(obj) if isinstance(radius,Part.Edge): edge = radius @@ -888,6 +892,8 @@ def makeEllipse(majradius,minradius,placement=None,face=True,support=None): a placement.''' obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","Ellipse") _Ellipse(obj) + if minradius > majradius: + majradius,minradius = minradius,majradius obj.MajorRadius = majradius obj.MinorRadius = minradius obj.Support = support diff --git a/src/Mod/Draft/TestDraft.py b/src/Mod/Draft/TestDraft.py index 0b95f16cf..6c2f613bc 100644 --- a/src/Mod/Draft/TestDraft.py +++ b/src/Mod/Draft/TestDraft.py @@ -21,13 +21,12 @@ #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * #* USA * #* * -#* Werner Mayer 2005 * #***************************************************************************/ import FreeCAD, os, unittest, FreeCADGui, Draft class DraftTest(unittest.TestCase): - + def setUp(self): # setting a new document to hold the tests if FreeCAD.ActiveDocument: @@ -36,36 +35,107 @@ class DraftTest(unittest.TestCase): else: FreeCAD.newDocument("DraftTest") FreeCAD.setActiveDocument("DraftTest") - + def testPivy(self): - # first checking if pivy is working FreeCAD.Console.PrintLog ('Checking Pivy...\n') from pivy import coin c = coin.SoCube() FreeCADGui.ActiveDocument.ActiveView.getSceneGraph().addChild(c) self.failUnless(c,"Pivy is not working properly") + # creation tools + + def testLine(self): + FreeCAD.Console.PrintLog ('Checking Draft Line...\n') + Draft.makeLine(FreeCAD.Vector(0,0,0),FreeCAD.Vector(-2,0,0)) + self.failUnless(FreeCAD.ActiveDocument.getObject("Line"),"Draft Line failed") + def testWire(self): - # testing the Wire tool FreeCAD.Console.PrintLog ('Checking Draft Wire...\n') Draft.makeWire([FreeCAD.Vector(0,0,0),FreeCAD.Vector(2,0,0),FreeCAD.Vector(2,2,0)]) self.failUnless(FreeCAD.ActiveDocument.getObject("DWire"),"Draft Wire failed") + + def testBSpline(self): + FreeCAD.Console.PrintLog ('Checking Draft BSpline...\n') + Draft.makeBSpline([FreeCAD.Vector(0,0,0),FreeCAD.Vector(2,0,0),FreeCAD.Vector(2,2,0)]) + self.failUnless(FreeCAD.ActiveDocument.getObject("BSpline"),"Draft BSpline failed") + def testRectangle(self): + FreeCAD.Console.PrintLog ('Checking Draft Rectangle...\n') + Draft.makeRectangle(4,2) + self.failUnless(FreeCAD.ActiveDocument.getObject("Rectangle"),"Draft Rectangle failed") + def testArc(self): - # testing the Arc tool FreeCAD.Console.PrintLog ('Checking Draft Arc...\n') Draft.makeCircle(2, startangle=0, endangle=90) self.failUnless(FreeCAD.ActiveDocument.getObject("Arc"),"Draft Arc failed") + def testCircle(self): + FreeCAD.Console.PrintLog ('Checking Draft Circle...\n') + Draft.makeCircle(3) + self.failUnless(FreeCAD.ActiveDocument.getObject("Circle"),"Draft Circle failed") + + def testPolygon(self): + FreeCAD.Console.PrintLog ('Checking Draft Polygon...\n') + Draft.makePolygon(5,5) + self.failUnless(FreeCAD.ActiveDocument.getObject("Polygon"),"Draft Polygon failed") + + def testEllipse(self): + FreeCAD.Console.PrintLog ('Checking Draft Ellipse...\n') + Draft.makeEllipse(5,3) + self.failUnless(FreeCAD.ActiveDocument.getObject("Ellipse"),"Draft Ellipse failed") + + def testPoint(self): + FreeCAD.Console.PrintLog ('Checking Draft Point...\n') + Draft.makePoint(5,3,2) + self.failUnless(FreeCAD.ActiveDocument.getObject("Point"),"Draft Point failed") + + def testText(self): + FreeCAD.Console.PrintLog ('Checking Draft Text...\n') + Draft.makeText("Testing Draft") + self.failUnless(FreeCAD.ActiveDocument.getObject("Text"),"Draft Text failed") + + #def testShapeString(self): + # not working ATM because it needs a font file + # FreeCAD.Console.PrintLog ('Checking Draft ShapeString...\n') + # Draft.makeShapeString("Testing Draft") + # self.failUnless(FreeCAD.ActiveDocument.getObject("ShapeString"),"Draft ShapeString failed") + def testDimension(self): - # testing the Arc tool FreeCAD.Console.PrintLog ('Checking Draft Dimension...\n') Draft.makeDimension(FreeCAD.Vector(0,0,0),FreeCAD.Vector(2,0,0),FreeCAD.Vector(1,-1,0)) self.failUnless(FreeCAD.ActiveDocument.getObject("Dimension"),"Draft Dimension failed") + # modification tools + + def testMove(self): + FreeCAD.Console.PrintLog ('Checking Draft Move...\n') + l = Draft.makeLine(FreeCAD.Vector(0,0,0),FreeCAD.Vector(-2,0,0)) + Draft.move(l,FreeCAD.Vector(2,0,0)) + self.failUnless(l.Start == FreeCAD.Vector(2,0,0),"Draft Move failed") + + def testCopy(self): + FreeCAD.Console.PrintLog ('Checking Draft Move with copy...\n') + l = Draft.makeLine(FreeCAD.Vector(0,0,0),FreeCAD.Vector(2,0,0)) + l2 = Draft.move(l,FreeCAD.Vector(2,0,0),copy=True) + self.failUnless(l2,"Draft Move with copy failed") + + def testRotate(self): + FreeCAD.Console.PrintLog ('Checking Draft Rotate...\n') + l = Draft.makeLine(FreeCAD.Vector(2,0,0),FreeCAD.Vector(4,0,0)) + Draft.rotate(l,90) + self.failUnless(l.Start == FreeCAD.Vector(0,2,0),"Draft Rotate failed") + + def testOffset(self): + FreeCAD.Console.PrintLog ('Checking Draft Offset...\n') + r = Draft.makeRectangle(4,2) + r2 = Draft.offset(r,FreeCAD.Vector(-1,-1,0),copy=True) + self.failUnless(r2,"Draft Offset failed") + + # modification tools + def tearDown(self): - #closing doc - #FreeCAD.closeDocument("DraftTest") + FreeCAD.closeDocument("DraftTest") pass diff --git a/src/Mod/Test/TestApp.py b/src/Mod/Test/TestApp.py index f70253d05..cf58c99f5 100644 --- a/src/Mod/Test/TestApp.py +++ b/src/Mod/Test/TestApp.py @@ -52,6 +52,7 @@ def All(): suite.addTest(unittest.defaultTestLoader.loadTestsFromName("TestPartGui") ) suite.addTest(unittest.defaultTestLoader.loadTestsFromName("TestPartDesignGui") ) suite.addTest(unittest.defaultTestLoader.loadTestsFromName("TestDraft") ) + suite.addTest(unittest.defaultTestLoader.loadTestsFromName("TestArch") ) return suite diff --git a/src/WindowsInstaller/ModArch.wxi b/src/WindowsInstaller/ModArch.wxi index 0c4c5f4b8..ea5c0c71d 100644 --- a/src/WindowsInstaller/ModArch.wxi +++ b/src/WindowsInstaller/ModArch.wxi @@ -46,6 +46,7 @@ +