Test: apply clang format
This commit is contained in:
@@ -1,29 +1,30 @@
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2004 Juergen Riegel <juergen.riegel@web.de> *
|
||||
#* *
|
||||
#* 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 *
|
||||
#* *
|
||||
#***************************************************************************/
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2004 Juergen Riegel <juergen.riegel@web.de> *
|
||||
# * *
|
||||
# * 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, tempfile, math
|
||||
from FreeCAD import Base
|
||||
|
||||
|
||||
class ConsoleTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.count = 0
|
||||
@@ -40,20 +41,21 @@ class ConsoleTestCase(unittest.TestCase):
|
||||
import _thread as thread, time
|
||||
except Exception:
|
||||
import thread, time
|
||||
|
||||
def adder():
|
||||
lock.acquire()
|
||||
self.count=self.count+1
|
||||
self.count = self.count + 1
|
||||
# call of Console method is thread-safe
|
||||
FreeCAD.Console.PrintMessage("Call from Python thread: count="+str(self.count)+"\n")
|
||||
FreeCAD.Console.PrintMessage("Call from Python thread: count=" + str(self.count) + "\n")
|
||||
lock.release()
|
||||
|
||||
lock=thread.allocate_lock()
|
||||
lock = thread.allocate_lock()
|
||||
for i in range(10):
|
||||
thread.start_new(adder,())
|
||||
thread.start_new(adder, ())
|
||||
|
||||
time.sleep(3)
|
||||
self.assertEqual(self.count, 10, "Synchronization of threads failed")
|
||||
FreeCAD.Console.PrintMessage(str(self.count)+"\n")
|
||||
FreeCAD.Console.PrintMessage(str(self.count) + "\n")
|
||||
|
||||
def testAsynchronPrintFromThread(self):
|
||||
# http://python-kurs.eu/threads.php
|
||||
@@ -61,43 +63,46 @@ class ConsoleTestCase(unittest.TestCase):
|
||||
import _thread as thread, time
|
||||
except Exception:
|
||||
import thread, time
|
||||
def adder():
|
||||
self.count=self.count+1
|
||||
# call of Console method is thread-safe
|
||||
FreeCAD.Console.PrintMessage("Call from Python thread (not synchronized): count="+str(self.count)+"\n")
|
||||
|
||||
lock=thread.allocate_lock()
|
||||
def adder():
|
||||
self.count = self.count + 1
|
||||
# call of Console method is thread-safe
|
||||
FreeCAD.Console.PrintMessage(
|
||||
"Call from Python thread (not synchronized): count=" + str(self.count) + "\n"
|
||||
)
|
||||
|
||||
lock = thread.allocate_lock()
|
||||
for i in range(10):
|
||||
thread.start_new(adder,())
|
||||
thread.start_new(adder, ())
|
||||
|
||||
time.sleep(3)
|
||||
FreeCAD.Console.PrintMessage(str(self.count)+"\n")
|
||||
FreeCAD.Console.PrintMessage(str(self.count) + "\n")
|
||||
|
||||
# def testStatus(self):
|
||||
# SLog = FreeCAD.GetStatus("Console","Log")
|
||||
# SErr = FreeCAD.GetStatus("Console","Err")
|
||||
# SWrn = FreeCAD.GetStatus("Console","Wrn")
|
||||
# SMsg = FreeCAD.GetStatus("Console","Msg")
|
||||
# FreeCAD.SetStatus("Console","Log",1)
|
||||
# FreeCAD.SetStatus("Console","Err",1)
|
||||
# FreeCAD.SetStatus("Console","Wrn",1)
|
||||
# FreeCAD.SetStatus("Console","Msg",1)
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Msg"),1,"Set and read status failed (Console,Msg)")
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Err"),1,"Set and read status failed (Console,Err)")
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Wrn"),1,"Set and read status failed (Console,Wrn)")
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Log"),1,"Set and read status failed (Console,Log)")
|
||||
# FreeCAD.SetStatus("Console","Log",0)
|
||||
# FreeCAD.SetStatus("Console","Err",0)
|
||||
# FreeCAD.SetStatus("Console","Wrn",0)
|
||||
# FreeCAD.SetStatus("Console","Msg",0)
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Msg"),0,"Set and read status failed (Console,Msg)")
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Err"),0,"Set and read status failed (Console,Err)")
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Wrn"),0,"Set and read status failed (Console,Wrn)")
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Log"),0,"Set and read status failed (Console,Log)")
|
||||
# FreeCAD.SetStatus("Console","Log",SLog)
|
||||
# FreeCAD.SetStatus("Console","Err",SErr)
|
||||
# FreeCAD.SetStatus("Console","Wrn",SWrn)
|
||||
# FreeCAD.SetStatus("Console","Msg",SMsg)
|
||||
# def testStatus(self):
|
||||
# SLog = FreeCAD.GetStatus("Console","Log")
|
||||
# SErr = FreeCAD.GetStatus("Console","Err")
|
||||
# SWrn = FreeCAD.GetStatus("Console","Wrn")
|
||||
# SMsg = FreeCAD.GetStatus("Console","Msg")
|
||||
# FreeCAD.SetStatus("Console","Log",1)
|
||||
# FreeCAD.SetStatus("Console","Err",1)
|
||||
# FreeCAD.SetStatus("Console","Wrn",1)
|
||||
# FreeCAD.SetStatus("Console","Msg",1)
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Msg"),1,"Set and read status failed (Console,Msg)")
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Err"),1,"Set and read status failed (Console,Err)")
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Wrn"),1,"Set and read status failed (Console,Wrn)")
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Log"),1,"Set and read status failed (Console,Log)")
|
||||
# FreeCAD.SetStatus("Console","Log",0)
|
||||
# FreeCAD.SetStatus("Console","Err",0)
|
||||
# FreeCAD.SetStatus("Console","Wrn",0)
|
||||
# FreeCAD.SetStatus("Console","Msg",0)
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Msg"),0,"Set and read status failed (Console,Msg)")
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Err"),0,"Set and read status failed (Console,Err)")
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Wrn"),0,"Set and read status failed (Console,Wrn)")
|
||||
# self.assertEqual(FreeCAD.GetStatus("Console","Log"),0,"Set and read status failed (Console,Log)")
|
||||
# FreeCAD.SetStatus("Console","Log",SLog)
|
||||
# FreeCAD.SetStatus("Console","Err",SErr)
|
||||
# FreeCAD.SetStatus("Console","Wrn",SWrn)
|
||||
# FreeCAD.SetStatus("Console","Msg",SMsg)
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
@@ -105,20 +110,22 @@ class ConsoleTestCase(unittest.TestCase):
|
||||
def testILoggerBlocker(self):
|
||||
if FreeCAD.GuiUp:
|
||||
import QtUnitGui
|
||||
|
||||
QtUnitGui.testILoggerBlocker()
|
||||
|
||||
|
||||
class ParameterTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.TestPar = FreeCAD.ParamGet("System parameter:Test")
|
||||
|
||||
def testGroup(self):
|
||||
#FreeCAD.Console.PrintLog("Base::ParameterTestCase::testGroup\n")
|
||||
# FreeCAD.Console.PrintLog("Base::ParameterTestCase::testGroup\n")
|
||||
# check on Group creation
|
||||
Temp = self.TestPar.GetGroup("44")
|
||||
self.assertTrue(self.TestPar.HasGroup("44"),"Test on created group failed")
|
||||
self.assertTrue(self.TestPar.HasGroup("44"), "Test on created group failed")
|
||||
# check on Deletion
|
||||
self.TestPar.RemGroup("44")
|
||||
self.assertTrue(self.TestPar.HasGroup("44"),"A referenced group must not be deleted")
|
||||
self.assertTrue(self.TestPar.HasGroup("44"), "A referenced group must not be deleted")
|
||||
Temp = 0
|
||||
|
||||
def testGroupNames(self):
|
||||
@@ -132,205 +139,203 @@ class ParameterTestCase(unittest.TestCase):
|
||||
|
||||
# check on special conditions
|
||||
def testInt(self):
|
||||
#FreeCAD.Console.PrintLog("Base::ParameterTestCase::testInt\n")
|
||||
#Temp = FreeCAD.ParamGet("System parameter:Test/44")
|
||||
# FreeCAD.Console.PrintLog("Base::ParameterTestCase::testInt\n")
|
||||
# Temp = FreeCAD.ParamGet("System parameter:Test/44")
|
||||
# check on Int
|
||||
self.TestPar.SetInt("44",4711)
|
||||
self.assertEqual(self.TestPar.GetInt("44"), 4711,"In and out error at Int")
|
||||
self.TestPar.SetInt("44", 4711)
|
||||
self.assertEqual(self.TestPar.GetInt("44"), 4711, "In and out error at Int")
|
||||
# check on Deletion
|
||||
self.TestPar.RemInt("44")
|
||||
self.assertEqual(self.TestPar.GetInt("44",1), 1,"Deletion error at Int")
|
||||
|
||||
self.assertEqual(self.TestPar.GetInt("44", 1), 1, "Deletion error at Int")
|
||||
|
||||
def testBool(self):
|
||||
#FreeCAD.Console.PrintLog("Base::ParameterTestCase::testBool\n")
|
||||
# FreeCAD.Console.PrintLog("Base::ParameterTestCase::testBool\n")
|
||||
# check on Int
|
||||
self.TestPar.SetBool("44",1)
|
||||
self.assertEqual(self.TestPar.GetBool("44"), 1,"In and out error at Bool")
|
||||
self.TestPar.SetBool("44", 1)
|
||||
self.assertEqual(self.TestPar.GetBool("44"), 1, "In and out error at Bool")
|
||||
# check on Deletion
|
||||
self.TestPar.RemBool("44")
|
||||
self.assertEqual(self.TestPar.GetBool("44",0), 0,"Deletion error at Bool")
|
||||
self.assertEqual(self.TestPar.GetBool("44", 0), 0, "Deletion error at Bool")
|
||||
|
||||
def testFloat(self):
|
||||
#FreeCAD.Console.PrintLog("Base::ParameterTestCase::testFloat\n")
|
||||
#Temp = FreeCAD.ParamGet("System parameter:Test/44")
|
||||
# FreeCAD.Console.PrintLog("Base::ParameterTestCase::testFloat\n")
|
||||
# Temp = FreeCAD.ParamGet("System parameter:Test/44")
|
||||
# check on Int
|
||||
self.TestPar.SetFloat("44",4711.4711)
|
||||
self.assertEqual(self.TestPar.GetFloat("44"), 4711.4711,"In and out error at Float")
|
||||
self.TestPar.SetFloat("44", 4711.4711)
|
||||
self.assertEqual(self.TestPar.GetFloat("44"), 4711.4711, "In and out error at Float")
|
||||
# check on Deletion
|
||||
self.TestPar.RemFloat("44")
|
||||
self.assertEqual(self.TestPar.GetFloat("44",1.1), 1.1,"Deletion error at Float")
|
||||
self.assertEqual(self.TestPar.GetFloat("44", 1.1), 1.1, "Deletion error at Float")
|
||||
|
||||
def testString(self):
|
||||
#FreeCAD.Console.PrintLog("Base::ParameterTestCase::testFloat\n")
|
||||
#Temp = FreeCAD.ParamGet("System parameter:Test/44")
|
||||
# FreeCAD.Console.PrintLog("Base::ParameterTestCase::testFloat\n")
|
||||
# Temp = FreeCAD.ParamGet("System parameter:Test/44")
|
||||
# check on Int
|
||||
self.TestPar.SetString("44","abcdefgh")
|
||||
self.assertEqual(self.TestPar.GetString("44"), "abcdefgh","In and out error at String")
|
||||
self.TestPar.SetString("44", "abcdefgh")
|
||||
self.assertEqual(self.TestPar.GetString("44"), "abcdefgh", "In and out error at String")
|
||||
# check on Deletion
|
||||
self.TestPar.RemString("44")
|
||||
self.assertEqual(self.TestPar.GetString("44","hallo"), "hallo","Deletion error at String")
|
||||
self.assertEqual(self.TestPar.GetString("44", "hallo"), "hallo", "Deletion error at String")
|
||||
|
||||
def testNesting(self):
|
||||
# Parameter testing
|
||||
#FreeCAD.Console.PrintLog("Base::ParameterTestCase::testNesting\n")
|
||||
# FreeCAD.Console.PrintLog("Base::ParameterTestCase::testNesting\n")
|
||||
for i in range(50):
|
||||
self.TestPar.SetFloat(str(i),4711.4711)
|
||||
self.TestPar.SetInt(str(i),4711)
|
||||
self.TestPar.SetBool(str(i),1)
|
||||
self.TestPar.SetFloat(str(i), 4711.4711)
|
||||
self.TestPar.SetInt(str(i), 4711)
|
||||
self.TestPar.SetBool(str(i), 1)
|
||||
Temp = self.TestPar.GetGroup(str(i))
|
||||
for l in range(50):
|
||||
Temp.SetFloat(str(l),4711.4711)
|
||||
Temp.SetInt(str(l),4711)
|
||||
Temp.SetBool(str(l),1)
|
||||
Temp.SetFloat(str(l), 4711.4711)
|
||||
Temp.SetInt(str(l), 4711)
|
||||
Temp.SetBool(str(l), 1)
|
||||
Temp = 0
|
||||
|
||||
def testExportImport(self):
|
||||
# Parameter testing
|
||||
#FreeCAD.Console.PrintLog("Base::ParameterTestCase::testNesting\n")
|
||||
self.TestPar.SetFloat("ExTest",4711.4711)
|
||||
self.TestPar.SetInt("ExTest",4711)
|
||||
self.TestPar.SetString("ExTest","4711")
|
||||
self.TestPar.SetBool("ExTest",1)
|
||||
# FreeCAD.Console.PrintLog("Base::ParameterTestCase::testNesting\n")
|
||||
self.TestPar.SetFloat("ExTest", 4711.4711)
|
||||
self.TestPar.SetInt("ExTest", 4711)
|
||||
self.TestPar.SetString("ExTest", "4711")
|
||||
self.TestPar.SetBool("ExTest", 1)
|
||||
Temp = self.TestPar.GetGroup("ExTest")
|
||||
Temp.SetFloat("ExTest",4711.4711)
|
||||
Temp.SetInt("ExTest",4711)
|
||||
Temp.SetString("ExTest","4711")
|
||||
Temp.SetBool("ExTest",1)
|
||||
Temp.SetFloat("ExTest", 4711.4711)
|
||||
Temp.SetInt("ExTest", 4711)
|
||||
Temp.SetString("ExTest", "4711")
|
||||
Temp.SetBool("ExTest", 1)
|
||||
TempPath = tempfile.gettempdir() + os.sep + "ExportTest.FCExport"
|
||||
|
||||
self.TestPar.Export(TempPath)
|
||||
Temp = self.TestPar.GetGroup("ImportTest")
|
||||
Temp.Import(TempPath)
|
||||
self.assertEqual(Temp.GetFloat("ExTest"), 4711.4711,"ExportImport error")
|
||||
self.assertEqual(Temp.GetFloat("ExTest"), 4711.4711, "ExportImport error")
|
||||
Temp = 0
|
||||
|
||||
def tearDown(self):
|
||||
#remove all
|
||||
# remove all
|
||||
TestPar = FreeCAD.ParamGet("System parameter:Test")
|
||||
TestPar.Clear()
|
||||
|
||||
|
||||
class AlgebraTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def testAngle(self):
|
||||
v1 = FreeCAD.Vector(0,0,0.000001)
|
||||
v2 = FreeCAD.Vector(0,0.000001,0)
|
||||
self.assertAlmostEqual(v1.getAngle(v2), math.pi/2)
|
||||
self.assertAlmostEqual(v2.getAngle(v1), math.pi/2)
|
||||
v1 = FreeCAD.Vector(0, 0, 0.000001)
|
||||
v2 = FreeCAD.Vector(0, 0.000001, 0)
|
||||
self.assertAlmostEqual(v1.getAngle(v2), math.pi / 2)
|
||||
self.assertAlmostEqual(v2.getAngle(v1), math.pi / 2)
|
||||
|
||||
def testVector2d(self):
|
||||
v = FreeCAD.Base.Vector2d(1.0, 1.0)
|
||||
v.rotate(math.pi/2)
|
||||
v.rotate(math.pi / 2)
|
||||
self.assertAlmostEqual(v.x, -1.0)
|
||||
self.assertAlmostEqual(v.y, 1.0)
|
||||
|
||||
def testAngleWithNullVector(self):
|
||||
v1 = FreeCAD.Vector(0,0,0)
|
||||
v2 = FreeCAD.Vector(0,1,0)
|
||||
v1 = FreeCAD.Vector(0, 0, 0)
|
||||
v2 = FreeCAD.Vector(0, 1, 0)
|
||||
self.assertTrue(math.isnan(v1.getAngle(v2)))
|
||||
self.assertTrue(math.isnan(v2.getAngle(v1)))
|
||||
|
||||
def testMatrix(self):
|
||||
m=FreeCAD.Matrix(4,2,1,0,1,1,1,0,0,0,1,0,0,0,0,1)
|
||||
u=m.multiply(m.inverse())
|
||||
self.assertEqual(u, FreeCAD.Matrix(),"Invalid inverse of matrix")
|
||||
m = FreeCAD.Matrix(4, 2, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1)
|
||||
u = m.multiply(m.inverse())
|
||||
self.assertEqual(u, FreeCAD.Matrix(), "Invalid inverse of matrix")
|
||||
|
||||
def testRotAndMoveMatrix(self):
|
||||
m1=FreeCAD.Matrix()
|
||||
m1.move(10,5,-3)
|
||||
m1.rotateY(.2)
|
||||
m2=FreeCAD.Matrix()
|
||||
m2.rotateY(.2)
|
||||
m2.move(10,5,-3)
|
||||
m3=FreeCAD.Matrix()
|
||||
m3.move(10,5,-3)
|
||||
m4=FreeCAD.Matrix()
|
||||
m4.rotateY(.2)
|
||||
self.assertNotEqual(m1, m3*m4, "Wrong multiplication order")
|
||||
self.assertEqual(m1, m4*m3 , "Wrong multiplication order")
|
||||
self.assertEqual(m2, m3*m4 , "Wrong multiplication order")
|
||||
self.assertNotEqual(m2, m4*m3, "Wrong multiplication order")
|
||||
|
||||
m1 = FreeCAD.Matrix()
|
||||
m1.move(10, 5, -3)
|
||||
m1.rotateY(0.2)
|
||||
m2 = FreeCAD.Matrix()
|
||||
m2.rotateY(0.2)
|
||||
m2.move(10, 5, -3)
|
||||
m3 = FreeCAD.Matrix()
|
||||
m3.move(10, 5, -3)
|
||||
m4 = FreeCAD.Matrix()
|
||||
m4.rotateY(0.2)
|
||||
self.assertNotEqual(m1, m3 * m4, "Wrong multiplication order")
|
||||
self.assertEqual(m1, m4 * m3, "Wrong multiplication order")
|
||||
self.assertEqual(m2, m3 * m4, "Wrong multiplication order")
|
||||
self.assertNotEqual(m2, m4 * m3, "Wrong multiplication order")
|
||||
|
||||
def testRotationFromMatrix(self):
|
||||
m1 = FreeCAD.Matrix()
|
||||
m1.rotateZ(.2)
|
||||
m1.rotateZ(0.2)
|
||||
m1.scale(0.5)
|
||||
m1.rotateY(.2)
|
||||
m1.rotateY(0.2)
|
||||
m1.scale(3)
|
||||
m1.move(10,5,-3)
|
||||
m1.move(10, 5, -3)
|
||||
r1 = FreeCAD.Rotation(m1)
|
||||
m2 = FreeCAD.Matrix()
|
||||
m2.rotateZ(.2)
|
||||
m2.rotateY(.2)
|
||||
m2.move(10,5,-3)
|
||||
r2 = FreeCAD.Rotation(m2)
|
||||
self.assertTrue(r1.isSame(r2, 1e-7), 'Scale on matrix influenced rotation')
|
||||
m2.rotateZ(0.2)
|
||||
m2.rotateY(0.2)
|
||||
m2.move(10, 5, -3)
|
||||
r2 = FreeCAD.Rotation(m2)
|
||||
self.assertTrue(r1.isSame(r2, 1e-7), "Scale on matrix influenced rotation")
|
||||
m3 = FreeCAD.Matrix()
|
||||
m3.scale(-1)
|
||||
r3 = FreeCAD.Rotation(m3)
|
||||
r0 = FreeCAD.Rotation()
|
||||
self.assertTrue(r3.isSame(r0, 1e-7), 'Scale on matrix influenced rotation')
|
||||
self.assertTrue(r3.isSame(r0, 1e-7), "Scale on matrix influenced rotation")
|
||||
m4 = FreeCAD.Matrix()
|
||||
m4.scale(1.25,1.0,0.25)
|
||||
m4.move(4,5,6)
|
||||
r24 = FreeCAD.Rotation(m2*m4)
|
||||
r42 = FreeCAD.Rotation(m4*m2)
|
||||
self.assertTrue(r2.isSame(r24, 1e-7), 'Scale on matrix influenced rotation')
|
||||
self.assertTrue(r2.isSame(r42, 1e-7), 'Scale on matrix influenced rotation')
|
||||
m4.scale(1.25, 1.0, 0.25)
|
||||
m4.move(4, 5, 6)
|
||||
r24 = FreeCAD.Rotation(m2 * m4)
|
||||
r42 = FreeCAD.Rotation(m4 * m2)
|
||||
self.assertTrue(r2.isSame(r24, 1e-7), "Scale on matrix influenced rotation")
|
||||
self.assertTrue(r2.isSame(r42, 1e-7), "Scale on matrix influenced rotation")
|
||||
|
||||
|
||||
def testRotation(self):
|
||||
r=FreeCAD.Rotation(1,0,0,0) # 180 deg around (1,0,0)
|
||||
self.assertEqual(r.Axis, FreeCAD.Vector(1,0,0))
|
||||
r = FreeCAD.Rotation(1, 0, 0, 0) # 180 deg around (1,0,0)
|
||||
self.assertEqual(r.Axis, FreeCAD.Vector(1, 0, 0))
|
||||
self.assertAlmostEqual(math.fabs(r.Angle), math.fabs(math.pi))
|
||||
|
||||
r=r.multiply(r) # identity
|
||||
self.assertEqual(r.Axis, FreeCAD.Vector(0,0,1))
|
||||
r = r.multiply(r) # identity
|
||||
self.assertEqual(r.Axis, FreeCAD.Vector(0, 0, 1))
|
||||
self.assertAlmostEqual(r.Angle, 0)
|
||||
|
||||
r=FreeCAD.Rotation(1,0,0,0)
|
||||
r.Q=(0,0,0,1) # update axis and angle
|
||||
s=FreeCAD.Rotation(0,0,0,1)
|
||||
r = FreeCAD.Rotation(1, 0, 0, 0)
|
||||
r.Q = (0, 0, 0, 1) # update axis and angle
|
||||
s = FreeCAD.Rotation(0, 0, 0, 1)
|
||||
self.assertEqual(r.Axis, s.Axis)
|
||||
self.assertAlmostEqual(r.Angle, s.Angle)
|
||||
self.assertTrue(r.isSame(s))
|
||||
|
||||
r=FreeCAD.Rotation(1,0,0,0)
|
||||
r.Matrix=FreeCAD.Matrix() # update axis and angle
|
||||
s=FreeCAD.Rotation(0,0,0,1)
|
||||
r = FreeCAD.Rotation(1, 0, 0, 0)
|
||||
r.Matrix = FreeCAD.Matrix() # update axis and angle
|
||||
s = FreeCAD.Rotation(0, 0, 0, 1)
|
||||
self.assertEqual(r.Axis, s.Axis)
|
||||
self.assertAlmostEqual(r.Angle, s.Angle)
|
||||
self.assertTrue(r.isSame(s))
|
||||
|
||||
r=FreeCAD.Rotation(1,0,0,0)
|
||||
r.Axes=(FreeCAD.Vector(0,0,1),FreeCAD.Vector(0,0,1)) # update axis and angle
|
||||
s=FreeCAD.Rotation(0,0,0,1)
|
||||
r = FreeCAD.Rotation(1, 0, 0, 0)
|
||||
r.Axes = (FreeCAD.Vector(0, 0, 1), FreeCAD.Vector(0, 0, 1)) # update axis and angle
|
||||
s = FreeCAD.Rotation(0, 0, 0, 1)
|
||||
self.assertEqual(r.Axis, s.Axis)
|
||||
self.assertAlmostEqual(r.Angle, s.Angle)
|
||||
self.assertTrue(r.isSame(s))
|
||||
|
||||
#add 360 deg to angle
|
||||
r=FreeCAD.Rotation(FreeCAD.Vector(1,0,0),270)
|
||||
s=FreeCAD.Rotation(FreeCAD.Vector(1,0,0),270+360)
|
||||
# add 360 deg to angle
|
||||
r = FreeCAD.Rotation(FreeCAD.Vector(1, 0, 0), 270)
|
||||
s = FreeCAD.Rotation(FreeCAD.Vector(1, 0, 0), 270 + 360)
|
||||
self.assertEqual(r.Axis, s.Axis)
|
||||
#self.assertAlmostEqual(r.Angle, s.Angle + 2*math.pi)
|
||||
# self.assertAlmostEqual(r.Angle, s.Angle + 2*math.pi)
|
||||
self.assertTrue(r.isSame(s))
|
||||
|
||||
#subtract 360 deg from angle using Euler angles
|
||||
r=FreeCAD.Rotation(0,0,180)
|
||||
# subtract 360 deg from angle using Euler angles
|
||||
r = FreeCAD.Rotation(0, 0, 180)
|
||||
r.invert()
|
||||
s=FreeCAD.Rotation(0,0,-180)
|
||||
s = FreeCAD.Rotation(0, 0, -180)
|
||||
self.assertTrue(r.isSame(s))
|
||||
|
||||
#subtract 360 deg from angle using quaternion
|
||||
r=FreeCAD.Rotation(1,0,0,0)
|
||||
s=FreeCAD.Rotation(-1,0,0,0)
|
||||
#angles have the same sign
|
||||
# subtract 360 deg from angle using quaternion
|
||||
r = FreeCAD.Rotation(1, 0, 0, 0)
|
||||
s = FreeCAD.Rotation(-1, 0, 0, 0)
|
||||
# angles have the same sign
|
||||
if r.Angle * s.Angle > 0:
|
||||
self.assertEqual(r.Axis, s.Axis*(-1))
|
||||
self.assertEqual(r.Axis, s.Axis * (-1))
|
||||
else:
|
||||
self.assertAlmostEqual(r.Angle, -s.Angle)
|
||||
self.assertTrue(r.isSame(s))
|
||||
@@ -338,10 +343,10 @@ class AlgebraTestCase(unittest.TestCase):
|
||||
self.assertTrue(r.isSame(s))
|
||||
|
||||
# gimbal lock (north pole)
|
||||
r=FreeCAD.Rotation()
|
||||
r = FreeCAD.Rotation()
|
||||
r.setYawPitchRoll(20, 90, 10)
|
||||
a=r.getYawPitchRoll()
|
||||
s=FreeCAD.Rotation()
|
||||
a = r.getYawPitchRoll()
|
||||
s = FreeCAD.Rotation()
|
||||
s.setYawPitchRoll(*a)
|
||||
self.assertAlmostEqual(a[0], 0.0)
|
||||
self.assertAlmostEqual(a[1], 90.0)
|
||||
@@ -349,10 +354,10 @@ class AlgebraTestCase(unittest.TestCase):
|
||||
self.assertTrue(r.isSame(s, 1e-12))
|
||||
|
||||
# gimbal lock (south pole)
|
||||
r=FreeCAD.Rotation()
|
||||
r = FreeCAD.Rotation()
|
||||
r.setYawPitchRoll(20, -90, 10)
|
||||
a=r.getYawPitchRoll()
|
||||
s=FreeCAD.Rotation()
|
||||
a = r.getYawPitchRoll()
|
||||
s = FreeCAD.Rotation()
|
||||
s.setYawPitchRoll(*a)
|
||||
self.assertAlmostEqual(a[0], 0.0)
|
||||
self.assertAlmostEqual(a[1], -90.0)
|
||||
@@ -382,20 +387,20 @@ class AlgebraTestCase(unittest.TestCase):
|
||||
plm = FreeCAD.Placement()
|
||||
rot.Matrix = FreeCAD.Matrix(1, 1, 0, 0, 1, 0, 0, 0, 1)
|
||||
|
||||
|
||||
def testYawPitchRoll(self):
|
||||
def getYPR1(yaw, pitch, roll):
|
||||
r = FreeCAD.Rotation()
|
||||
r.setYawPitchRoll(yaw, pitch, roll)
|
||||
return r
|
||||
|
||||
def getYPR2(yaw, pitch, roll):
|
||||
rx = FreeCAD.Rotation()
|
||||
ry = FreeCAD.Rotation()
|
||||
rz = FreeCAD.Rotation()
|
||||
|
||||
rx.Axis = FreeCAD.Vector(1,0,0)
|
||||
ry.Axis = FreeCAD.Vector(0,1,0)
|
||||
rz.Axis = FreeCAD.Vector(0,0,1)
|
||||
rx.Axis = FreeCAD.Vector(1, 0, 0)
|
||||
ry.Axis = FreeCAD.Vector(0, 1, 0)
|
||||
rz.Axis = FreeCAD.Vector(0, 0, 1)
|
||||
|
||||
rx.Angle = math.radians(roll)
|
||||
ry.Angle = math.radians(pitch)
|
||||
@@ -404,9 +409,9 @@ class AlgebraTestCase(unittest.TestCase):
|
||||
return rz.multiply(ry).multiply(rx)
|
||||
|
||||
angles = []
|
||||
angles.append((10,10,10))
|
||||
angles.append((13,45,-24))
|
||||
angles.append((10,-90,20))
|
||||
angles.append((10, 10, 10))
|
||||
angles.append((13, 45, -24))
|
||||
angles.append((10, -90, 20))
|
||||
|
||||
for i in angles:
|
||||
r = getYPR1(*i)
|
||||
@@ -414,21 +419,31 @@ class AlgebraTestCase(unittest.TestCase):
|
||||
self.assertTrue(r.isSame(s, 1e-12))
|
||||
|
||||
def testBounding(self):
|
||||
b=FreeCAD.BoundBox()
|
||||
b = FreeCAD.BoundBox()
|
||||
b.setVoid()
|
||||
self.assertFalse(b.isValid(),"Bbox is not invalid")
|
||||
b.add(0,0,0)
|
||||
self.assertFalse(b.isValid(), "Bbox is not invalid")
|
||||
b.add(0, 0, 0)
|
||||
self.assertTrue(b.isValid(), "Bbox is invalid")
|
||||
self.assertEqual(b.XLength, 0, "X length > 0")
|
||||
self.assertEqual(b.YLength, 0, "Y length > 0")
|
||||
self.assertEqual(b.ZLength, 0, "Z length > 0")
|
||||
self.assertEqual(b.Center, FreeCAD.Vector(0,0,0), "Center is not at (0,0,0)")
|
||||
self.assertEqual(b.Center, FreeCAD.Vector(0, 0, 0), "Center is not at (0,0,0)")
|
||||
self.assertTrue(b.isInside(b.Center), "Center is not inside Bbox")
|
||||
b.add(2,2,2)
|
||||
self.assertTrue(b.isInside(b.getIntersectionPoint(b.Center,FreeCAD.Vector(0,1,0))),"Intersection point is not inside Bbox")
|
||||
self.assertTrue(b.intersect(b),"Bbox doesn't intersect with itself")
|
||||
self.assertFalse(b.intersected(FreeCAD.BoundBox(4,4,4,6,6,6)).isValid(),"Bbox should not intersect with Bbox outside")
|
||||
self.assertEqual(b.intersected(FreeCAD.BoundBox(-2,-2,-2,2,2,2)).Center, b.Center,"Bbox is not a full subset")
|
||||
b.add(2, 2, 2)
|
||||
self.assertTrue(
|
||||
b.isInside(b.getIntersectionPoint(b.Center, FreeCAD.Vector(0, 1, 0))),
|
||||
"Intersection point is not inside Bbox",
|
||||
)
|
||||
self.assertTrue(b.intersect(b), "Bbox doesn't intersect with itself")
|
||||
self.assertFalse(
|
||||
b.intersected(FreeCAD.BoundBox(4, 4, 4, 6, 6, 6)).isValid(),
|
||||
"Bbox should not intersect with Bbox outside",
|
||||
)
|
||||
self.assertEqual(
|
||||
b.intersected(FreeCAD.BoundBox(-2, -2, -2, 2, 2, 2)).Center,
|
||||
b.Center,
|
||||
"Bbox is not a full subset",
|
||||
)
|
||||
|
||||
def testMultLeftOrRight(self):
|
||||
doc = FreeCAD.newDocument()
|
||||
@@ -451,12 +466,13 @@ class AlgebraTestCase(unittest.TestCase):
|
||||
|
||||
FreeCAD.closeDocument(doc.Name)
|
||||
|
||||
|
||||
class MatrixTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.mat = FreeCAD.Matrix()
|
||||
|
||||
def testOrder(self):
|
||||
self.mat = FreeCAD.Matrix(1.0,2.0,3.0,4.0)
|
||||
self.mat = FreeCAD.Matrix(1.0, 2.0, 3.0, 4.0)
|
||||
self.assertEqual(self.mat.A11, 1.0)
|
||||
self.assertEqual(self.mat.A12, 2.0)
|
||||
self.assertEqual(self.mat.A13, 3.0)
|
||||
@@ -507,18 +523,20 @@ class MatrixTestCase(unittest.TestCase):
|
||||
|
||||
def testMatrixPlacementMatrix(self):
|
||||
# Example taken from https://forum.freecad.org/viewtopic.php?f=3&t=61000
|
||||
mat = FreeCAD.Matrix(-0.470847778020266,
|
||||
0.8150598976807029,
|
||||
0.3376088628746235,
|
||||
-11.25290913640202,
|
||||
-0.8822144756796808,
|
||||
-0.4350066260577338,
|
||||
-0.180185641360483,
|
||||
-2876.45492562325,
|
||||
1.955470978815492e-9,
|
||||
-0.3826834326750831,
|
||||
0.923879538425552,
|
||||
941.3822018176414)
|
||||
mat = FreeCAD.Matrix(
|
||||
-0.470847778020266,
|
||||
0.8150598976807029,
|
||||
0.3376088628746235,
|
||||
-11.25290913640202,
|
||||
-0.8822144756796808,
|
||||
-0.4350066260577338,
|
||||
-0.180185641360483,
|
||||
-2876.45492562325,
|
||||
1.955470978815492e-9,
|
||||
-0.3826834326750831,
|
||||
0.923879538425552,
|
||||
941.3822018176414,
|
||||
)
|
||||
plm = FreeCAD.Placement(mat)
|
||||
mat = plm.toMatrix()
|
||||
self.assertEqual(mat.hasScale(), FreeCAD.ScaleType.NoScaling)
|
||||
@@ -528,60 +546,60 @@ class MatrixTestCase(unittest.TestCase):
|
||||
self.mat * "string"
|
||||
|
||||
def testUnity(self):
|
||||
mat = FreeCAD.Matrix(2,0,0,0, 0,1,0,0, 0,0,2,0, 0,0,0,-1)
|
||||
mat = FreeCAD.Matrix(2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, -1)
|
||||
self.assertFalse(mat.isUnity())
|
||||
mat.unity()
|
||||
self.assertTrue(mat.isUnity())
|
||||
|
||||
def testPower(self):
|
||||
mat = FreeCAD.Matrix(2,0,0,0, 0,1,0,0, 0,0,2,0, 0,0,0,-1)
|
||||
mat = FreeCAD.Matrix(2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, -1)
|
||||
with self.assertRaises(NotImplementedError):
|
||||
mat ** "string"
|
||||
|
||||
mat2 = mat ** 0
|
||||
mat2 = mat**0
|
||||
self.assertTrue(mat2.isUnity())
|
||||
self.assertEqual(mat ** -1, mat.inverse())
|
||||
self.assertEqual(mat ** 1, mat)
|
||||
self.assertEqual(mat ** 2, mat * mat)
|
||||
self.assertEqual(mat ** 3, mat * mat * mat)
|
||||
self.assertEqual(mat**-1, mat.inverse())
|
||||
self.assertEqual(mat**1, mat)
|
||||
self.assertEqual(mat**2, mat * mat)
|
||||
self.assertEqual(mat**3, mat * mat * mat)
|
||||
mat.nullify()
|
||||
with self.assertRaises(RuntimeError):
|
||||
mat ** -1
|
||||
mat**-1
|
||||
|
||||
def testScale(self):
|
||||
self.mat.scale(1., 2., 3.)
|
||||
self.mat.scale(1.0, 2.0, 3.0)
|
||||
self.assertEqual(self.mat.determinant(), 6.0)
|
||||
self.assertEqual(self.mat.hasScale(), FreeCAD.ScaleType.NonUniformLeft)
|
||||
self.mat.unity()
|
||||
self.assertEqual(self.mat.hasScale(), FreeCAD.ScaleType.NoScaling)
|
||||
self.mat.scale(2., 2., 2.)
|
||||
self.mat.scale(2.0, 2.0, 2.0)
|
||||
self.assertEqual(self.mat.hasScale(), FreeCAD.ScaleType.Uniform)
|
||||
self.mat.rotateX(1.0)
|
||||
self.assertEqual(self.mat.hasScale(), FreeCAD.ScaleType.Uniform)
|
||||
self.mat.scale(1., 2., 3.)
|
||||
self.mat.scale(1.0, 2.0, 3.0)
|
||||
self.assertEqual(self.mat.hasScale(), FreeCAD.ScaleType.NonUniformLeft)
|
||||
self.mat.unity()
|
||||
self.mat.scale(1., 2., 3.)
|
||||
self.mat.scale(1.0, 2.0, 3.0)
|
||||
self.mat.rotateX(1.0)
|
||||
self.assertEqual(self.mat.hasScale(), FreeCAD.ScaleType.NonUniformRight)
|
||||
self.mat.unity()
|
||||
self.mat.setCol(0, FreeCAD.Vector(1,2,3))
|
||||
self.mat.setCol(1, FreeCAD.Vector(1,2,3))
|
||||
self.mat.setCol(2, FreeCAD.Vector(1,2,3))
|
||||
self.mat.setCol(0, FreeCAD.Vector(1, 2, 3))
|
||||
self.mat.setCol(1, FreeCAD.Vector(1, 2, 3))
|
||||
self.mat.setCol(2, FreeCAD.Vector(1, 2, 3))
|
||||
self.assertEqual(self.mat.hasScale(), FreeCAD.ScaleType.Other)
|
||||
self.mat.unity()
|
||||
self.mat.setRow(0, FreeCAD.Vector(1,2,3))
|
||||
self.mat.setRow(1, FreeCAD.Vector(1,2,3))
|
||||
self.mat.setRow(2, FreeCAD.Vector(1,2,3))
|
||||
self.mat.setRow(0, FreeCAD.Vector(1, 2, 3))
|
||||
self.mat.setRow(1, FreeCAD.Vector(1, 2, 3))
|
||||
self.mat.setRow(2, FreeCAD.Vector(1, 2, 3))
|
||||
self.assertEqual(self.mat.hasScale(), FreeCAD.ScaleType.Other)
|
||||
self.mat.unity()
|
||||
self.mat.scale(-1.)
|
||||
self.mat.scale(-1.0)
|
||||
self.assertEqual(self.mat.hasScale(), FreeCAD.ScaleType.Uniform)
|
||||
self.mat.scale(-2.)
|
||||
self.mat.scale(-2.0)
|
||||
self.assertEqual(self.mat.hasScale(), FreeCAD.ScaleType.Uniform)
|
||||
|
||||
def testShearing(self):
|
||||
self.mat.setRow(1, FreeCAD.Vector(0,1,1))
|
||||
self.mat.setRow(1, FreeCAD.Vector(0, 1, 1))
|
||||
self.assertEqual(self.mat.hasScale(), FreeCAD.ScaleType.Other)
|
||||
|
||||
def testMultLeftOrRight(self):
|
||||
@@ -589,7 +607,7 @@ class MatrixTestCase(unittest.TestCase):
|
||||
mat1.rotateX(1.0)
|
||||
|
||||
mat2 = FreeCAD.Matrix()
|
||||
mat2.scale(1., 2., 3.)
|
||||
mat2.scale(1.0, 2.0, 3.0)
|
||||
self.assertEqual((mat1 * mat2).hasScale(), FreeCAD.ScaleType.NonUniformRight)
|
||||
self.assertEqual((mat2 * mat1).hasScale(), FreeCAD.ScaleType.NonUniformLeft)
|
||||
|
||||
@@ -612,12 +630,12 @@ class MatrixTestCase(unittest.TestCase):
|
||||
self.mat.row("string")
|
||||
self.assertEqual(type(self.mat.col(0)), FreeCAD.Vector)
|
||||
self.assertEqual(type(self.mat.row(0)), FreeCAD.Vector)
|
||||
self.mat.setCol(0, FreeCAD.Vector(1,0,0))
|
||||
self.mat.setRow(0, FreeCAD.Vector(1,0,0))
|
||||
self.mat.setCol(0, FreeCAD.Vector(1, 0, 0))
|
||||
self.mat.setRow(0, FreeCAD.Vector(1, 0, 0))
|
||||
|
||||
def testTrace(self):
|
||||
self.mat.scale(2., 2., 2.)
|
||||
self.assertEqual(self.mat.trace(), FreeCAD.Vector(2., 2., 2.))
|
||||
self.mat.scale(2.0, 2.0, 2.0)
|
||||
self.assertEqual(self.mat.trace(), FreeCAD.Vector(2.0, 2.0, 2.0))
|
||||
|
||||
def testNumberProtocol(self):
|
||||
with self.assertRaises(NotImplementedError):
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -31,23 +31,37 @@
|
||||
#include "UnitTestPy.h"
|
||||
|
||||
|
||||
class ILoggerBlockerTest : public Base::ILogger
|
||||
class ILoggerBlockerTest: public Base::ILogger
|
||||
{
|
||||
public:
|
||||
~ILoggerBlockerTest() override {Base::Console().DetachObserver(this);}
|
||||
~ILoggerBlockerTest() override
|
||||
{
|
||||
Base::Console().DetachObserver(this);
|
||||
}
|
||||
|
||||
const char *Name() override {return "ILoggerBlockerTest";}
|
||||
const char* Name() override
|
||||
{
|
||||
return "ILoggerBlockerTest";
|
||||
}
|
||||
|
||||
void flush() {buffer.str("");buffer.clear();}
|
||||
void flush()
|
||||
{
|
||||
buffer.str("");
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
void SendLog(const std::string& notifiername, const std::string& msg, Base::LogStyle level,
|
||||
Base::IntendedRecipient recipient, Base::ContentType content) override{
|
||||
(void) notifiername;
|
||||
(void) msg;
|
||||
(void) recipient;
|
||||
(void) content;
|
||||
void SendLog(const std::string& notifiername,
|
||||
const std::string& msg,
|
||||
Base::LogStyle level,
|
||||
Base::IntendedRecipient recipient,
|
||||
Base::ContentType content) override
|
||||
{
|
||||
(void)notifiername;
|
||||
(void)msg;
|
||||
(void)recipient;
|
||||
(void)content;
|
||||
|
||||
switch(level){
|
||||
switch (level) {
|
||||
case Base::LogStyle::Warning:
|
||||
buffer << "WRN";
|
||||
break;
|
||||
@@ -68,7 +82,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void runSingleTest(const char* comment, std::string expectedResult) {
|
||||
void runSingleTest(const char* comment, std::string expectedResult)
|
||||
{
|
||||
Base::Console().Log(comment);
|
||||
flush();
|
||||
Base::Console().Log("LOG");
|
||||
@@ -76,8 +91,10 @@ public:
|
||||
Base::Console().Warning("WRN");
|
||||
Base::Console().Error("ERR");
|
||||
Base::Console().Critical("CMS");
|
||||
if (buffer.str() != expectedResult)
|
||||
throw Py::RuntimeError("ILoggerTest: " + buffer.str() + " different from " + expectedResult);
|
||||
if (buffer.str() != expectedResult) {
|
||||
throw Py::RuntimeError("ILoggerTest: " + buffer.str() + " different from "
|
||||
+ expectedResult);
|
||||
}
|
||||
}
|
||||
|
||||
void runTest()
|
||||
@@ -89,12 +106,16 @@ public:
|
||||
}
|
||||
runSingleTest("Print all", "LOGMSGWRNERRCMS");
|
||||
{
|
||||
Base::ILoggerBlocker blocker("ILoggerBlockerTest", Base::ConsoleSingleton::MsgType_Err | Base::ConsoleSingleton::MsgType_Wrn);
|
||||
Base::ILoggerBlocker blocker("ILoggerBlockerTest",
|
||||
Base::ConsoleSingleton::MsgType_Err
|
||||
| Base::ConsoleSingleton::MsgType_Wrn);
|
||||
runSingleTest("Error & Warning blocked", "LOGMSGCMS");
|
||||
}
|
||||
runSingleTest("Print all", "LOGMSGWRNERRCMS");
|
||||
{
|
||||
Base::ILoggerBlocker blocker("ILoggerBlockerTest", Base::ConsoleSingleton::MsgType_Log | Base::ConsoleSingleton::MsgType_Txt);
|
||||
Base::ILoggerBlocker blocker("ILoggerBlockerTest",
|
||||
Base::ConsoleSingleton::MsgType_Log
|
||||
| Base::ConsoleSingleton::MsgType_Txt);
|
||||
runSingleTest("Log & Message blocked", "WRNERRCMS");
|
||||
}
|
||||
runSingleTest("Print all", "LOGMSGWRNERRCMS");
|
||||
@@ -102,15 +123,21 @@ public:
|
||||
Base::ILoggerBlocker blocker("ILoggerBlockerTest", Base::ConsoleSingleton::MsgType_Err);
|
||||
runSingleTest("Nested : Error blocked", "LOGMSGWRNCMS");
|
||||
{
|
||||
Base::ILoggerBlocker blocker2("ILoggerBlockerTest", Base::ConsoleSingleton::MsgType_Err | Base::ConsoleSingleton::MsgType_Wrn);
|
||||
runSingleTest("Nested : Warning blocked + Error (from nesting) + Error (redundancy)", "LOGMSGCMS");
|
||||
Base::ILoggerBlocker blocker2("ILoggerBlockerTest",
|
||||
Base::ConsoleSingleton::MsgType_Err
|
||||
| Base::ConsoleSingleton::MsgType_Wrn);
|
||||
runSingleTest(
|
||||
"Nested : Warning blocked + Error (from nesting) + Error (redundancy)",
|
||||
"LOGMSGCMS");
|
||||
}
|
||||
runSingleTest("Nested : Error still blocked", "LOGMSGWRNCMS");
|
||||
}
|
||||
runSingleTest("Print all", "LOGMSGWRNERRCMS");
|
||||
{
|
||||
Base::ILoggerBlocker blocker("ILoggerBlockerTest");
|
||||
Base::Console().SetEnabledMsgType("ILoggerBlockerTest", Base::ConsoleSingleton::MsgType_Log, true);
|
||||
Base::Console().SetEnabledMsgType("ILoggerBlockerTest",
|
||||
Base::ConsoleSingleton::MsgType_Log,
|
||||
true);
|
||||
runSingleTest("Log is enabled but a warning is triggered in debug mode", "LOG");
|
||||
}
|
||||
runSingleTest("Print all", "LOGMSGWRNERRCMS");
|
||||
@@ -121,68 +148,77 @@ private:
|
||||
};
|
||||
|
||||
|
||||
namespace TestGui {
|
||||
class Module : public Py::ExtensionModule<Module>
|
||||
namespace TestGui
|
||||
{
|
||||
class Module: public Py::ExtensionModule<Module>
|
||||
{
|
||||
|
||||
public:
|
||||
Module() : Py::ExtensionModule<Module>("QtUnitGui")
|
||||
Module()
|
||||
: Py::ExtensionModule<Module>("QtUnitGui")
|
||||
{
|
||||
TestGui::UnitTestDialogPy::init_type();
|
||||
add_varargs_method("UnitTest",&Module::new_UnitTest,"UnitTest");
|
||||
add_varargs_method("setTest",&Module::setTest,"setTest");
|
||||
add_varargs_method("addTest",&Module::addTest,"addTest");
|
||||
add_varargs_method("runTest",&Module::runTest,"runTest");
|
||||
add_varargs_method("testILoggerBlocker",&Module::testILoggerBlocker,"testILoggerBlocker");
|
||||
initialize("This module is the QtUnitGui module"); // register with Python
|
||||
add_varargs_method("UnitTest", &Module::new_UnitTest, "UnitTest");
|
||||
add_varargs_method("setTest", &Module::setTest, "setTest");
|
||||
add_varargs_method("addTest", &Module::addTest, "addTest");
|
||||
add_varargs_method("runTest", &Module::runTest, "runTest");
|
||||
add_varargs_method("testILoggerBlocker", &Module::testILoggerBlocker, "testILoggerBlocker");
|
||||
initialize("This module is the QtUnitGui module");// register with Python
|
||||
}
|
||||
|
||||
private:
|
||||
Py::Object new_UnitTest(const Py::Tuple& args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args.ptr(), ""))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "")) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
return Py::asObject(new TestGui::UnitTestDialogPy());
|
||||
}
|
||||
Py::Object setTest(const Py::Tuple& args)
|
||||
{
|
||||
char *pstr=nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "|s", &pstr))
|
||||
char* pstr = nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "|s", &pstr)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
|
||||
if (pstr)
|
||||
if (pstr) {
|
||||
dlg->setUnitTest(QString::fromLatin1(pstr));
|
||||
}
|
||||
dlg->show();
|
||||
dlg->raise();
|
||||
return Py::None();
|
||||
}
|
||||
Py::Object addTest(const Py::Tuple& args)
|
||||
{
|
||||
char *pstr=nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "|s", &pstr))
|
||||
char* pstr = nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "|s", &pstr)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
|
||||
if (pstr)
|
||||
if (pstr) {
|
||||
dlg->addUnitTest(QString::fromLatin1(pstr));
|
||||
}
|
||||
dlg->show();
|
||||
dlg->raise();
|
||||
return Py::None();
|
||||
}
|
||||
Py::Object runTest(const Py::Tuple& args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args.ptr(), ""))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "")) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
|
||||
bool success = dlg->runCurrentTest();
|
||||
return Py::Boolean(success);
|
||||
}
|
||||
Py::Object testILoggerBlocker(const Py::Tuple& args) {
|
||||
(void) args;
|
||||
Py::Object testILoggerBlocker(const Py::Tuple& args)
|
||||
{
|
||||
(void)args;
|
||||
ILoggerBlockerTest iltest;
|
||||
Base::Console().AttachObserver(static_cast<Base::ILogger *>(&iltest));
|
||||
Base::Console().AttachObserver(static_cast<Base::ILogger*>(&iltest));
|
||||
Base::Console().SetConnectionMode(Base::ConsoleSingleton::Direct);
|
||||
iltest.runTest();
|
||||
return Py::None();
|
||||
@@ -194,7 +230,7 @@ PyObject* initModule()
|
||||
return Base::Interpreter().addModule(new Module);
|
||||
}
|
||||
|
||||
}
|
||||
}// namespace TestGui
|
||||
|
||||
void loadTestResource()
|
||||
{
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
|
||||
// point at which warnings of overly long specifiers disabled (needed for VC6)
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning( disable : 4251 )
|
||||
# pragma warning( disable : 4503 )
|
||||
# pragma warning( disable : 4786 ) // specifier longer then 255 chars
|
||||
#pragma warning(disable : 4251)
|
||||
#pragma warning(disable : 4503)
|
||||
#pragma warning(disable : 4786)// specifier longer then 255 chars
|
||||
#endif
|
||||
|
||||
// Qt Toolkit
|
||||
@@ -39,6 +39,6 @@
|
||||
#include <QEventLoop>
|
||||
#include <QMessageBox>
|
||||
|
||||
#endif //_PreComp_
|
||||
#endif//_PreComp_
|
||||
|
||||
#endif // __PRECOMPILED_GUI__
|
||||
#endif// __PRECOMPILED_GUI__
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <QFontMetrics>
|
||||
# include <QMessageBox>
|
||||
#include <QFontMetrics>
|
||||
#include <QMessageBox>
|
||||
#endif
|
||||
|
||||
#include <Base/Interpreter.h>
|
||||
@@ -37,7 +37,7 @@ using namespace TestGui;
|
||||
|
||||
/* TRANSLATOR TestGui::UnitTestDialog */
|
||||
|
||||
UnitTestDialog* UnitTestDialog::_instance=nullptr;
|
||||
UnitTestDialog* UnitTestDialog::_instance = nullptr;
|
||||
|
||||
/**
|
||||
* Creates and returns the one and only instance of this dialog.
|
||||
@@ -45,18 +45,19 @@ UnitTestDialog* UnitTestDialog::_instance=nullptr;
|
||||
UnitTestDialog* UnitTestDialog::instance()
|
||||
{
|
||||
// not initialized?
|
||||
if (!_instance)
|
||||
if (!_instance) {
|
||||
_instance = new UnitTestDialog(Gui::getMainWindow());
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructs the instance of this dialog.
|
||||
*/
|
||||
void UnitTestDialog::destruct ()
|
||||
void UnitTestDialog::destruct()
|
||||
{
|
||||
if (_instance) {
|
||||
UnitTestDialog *pTmp = _instance;
|
||||
UnitTestDialog* pTmp = _instance;
|
||||
_instance = nullptr;
|
||||
delete pTmp;
|
||||
}
|
||||
@@ -78,13 +79,13 @@ bool UnitTestDialog::hasInstance()
|
||||
* true to construct a modal dialog.
|
||||
*/
|
||||
UnitTestDialog::UnitTestDialog(QWidget* parent, Qt::WindowFlags f)
|
||||
: QDialog(parent, f)
|
||||
, ui(new Ui_UnitTest)
|
||||
: QDialog(parent, f)
|
||||
, ui(new Ui_UnitTest)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setupConnections();
|
||||
|
||||
setProgressColor(QColor(40,210,43)); // a darker green
|
||||
setProgressColor(QColor(40, 210, 43));// a darker green
|
||||
ui->progressBar->setAlignment(Qt::AlignCenter);
|
||||
|
||||
// red items
|
||||
@@ -100,15 +101,13 @@ UnitTestDialog::~UnitTestDialog() = default;
|
||||
|
||||
void UnitTestDialog::setupConnections()
|
||||
{
|
||||
connect(ui->treeViewFailure, &QTreeWidget::itemDoubleClicked,
|
||||
this, &UnitTestDialog::onTreeViewFailureItemDoubleClicked);
|
||||
connect(ui->helpButton, &QPushButton::clicked,
|
||||
this, &UnitTestDialog::onHelpButtonClicked);
|
||||
connect(ui->aboutButton, &QPushButton::clicked,
|
||||
this, &UnitTestDialog::onAboutButtonClicked);
|
||||
connect(ui->startButton, &QPushButton::clicked,
|
||||
this, &UnitTestDialog::onStartButtonClicked);
|
||||
|
||||
connect(ui->treeViewFailure,
|
||||
&QTreeWidget::itemDoubleClicked,
|
||||
this,
|
||||
&UnitTestDialog::onTreeViewFailureItemDoubleClicked);
|
||||
connect(ui->helpButton, &QPushButton::clicked, this, &UnitTestDialog::onHelpButtonClicked);
|
||||
connect(ui->aboutButton, &QPushButton::clicked, this, &UnitTestDialog::onAboutButtonClicked);
|
||||
connect(ui->startButton, &QPushButton::clicked, this, &UnitTestDialog::onStartButtonClicked);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,23 +115,22 @@ void UnitTestDialog::setupConnections()
|
||||
*/
|
||||
void UnitTestDialog::setProgressColor(const QColor& col)
|
||||
{
|
||||
QString qss = QString::fromLatin1(
|
||||
"QProgressBar {\n"
|
||||
" border: 2px solid grey;\n"
|
||||
" border-radius: 5px;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"QProgressBar::chunk {\n"
|
||||
" background-color: %1;\n"
|
||||
"}"
|
||||
).arg(col.name());
|
||||
QString qss = QString::fromLatin1("QProgressBar {\n"
|
||||
" border: 2px solid grey;\n"
|
||||
" border-radius: 5px;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"QProgressBar::chunk {\n"
|
||||
" background-color: %1;\n"
|
||||
"}")
|
||||
.arg(col.name());
|
||||
ui->progressBar->setStyleSheet(qss);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a dialog to display a detailed description about the error.
|
||||
*/
|
||||
void UnitTestDialog::onTreeViewFailureItemDoubleClicked(QTreeWidgetItem * item, int column)
|
||||
void UnitTestDialog::onTreeViewFailureItemDoubleClicked(QTreeWidgetItem* item, int column)
|
||||
{
|
||||
Q_UNUSED(column);
|
||||
|
||||
@@ -146,7 +144,7 @@ void UnitTestDialog::onTreeViewFailureItemDoubleClicked(QTreeWidgetItem * item,
|
||||
// truncate the visible text when it's too long
|
||||
if (text.count(QLatin1Char('\n')) > 20) {
|
||||
QStringList lines = text.split(QLatin1Char('\n'));
|
||||
lines.erase(lines.begin()+20, lines.end());
|
||||
lines.erase(lines.begin() + 20, lines.end());
|
||||
text = lines.join(QLatin1String("\n"));
|
||||
}
|
||||
if (text.size() > 1000) {
|
||||
@@ -162,11 +160,13 @@ void UnitTestDialog::onTreeViewFailureItemDoubleClicked(QTreeWidgetItem * item,
|
||||
*/
|
||||
void UnitTestDialog::onHelpButtonClicked()
|
||||
{
|
||||
QMessageBox::information(this, tr("Help"), tr(
|
||||
"Enter the name of a callable object which, when called, will return a TestCase.\n"
|
||||
"Click 'start', and the test thus produced will be run.\n\n"
|
||||
"Double click on an error in the tree view to see more information about it, "
|
||||
"including the stack trace."));
|
||||
QMessageBox::information(
|
||||
this,
|
||||
tr("Help"),
|
||||
tr("Enter the name of a callable object which, when called, will return a TestCase.\n"
|
||||
"Click 'start', and the test thus produced will be run.\n\n"
|
||||
"Double click on an error in the tree view to see more information about it, "
|
||||
"including the stack trace."));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,10 +174,12 @@ void UnitTestDialog::onHelpButtonClicked()
|
||||
*/
|
||||
void UnitTestDialog::onAboutButtonClicked()
|
||||
{
|
||||
QMessageBox::information(this, tr("About FreeCAD UnitTest"), tr(
|
||||
"Copyright (c) Werner Mayer\n\n"
|
||||
"FreeCAD UnitTest is part of FreeCAD and supports writing Unit Tests for "
|
||||
"ones own modules."));
|
||||
QMessageBox::information(
|
||||
this,
|
||||
tr("About FreeCAD UnitTest"),
|
||||
tr("Copyright (c) Werner Mayer\n\n"
|
||||
"FreeCAD UnitTest is part of FreeCAD and supports writing Unit Tests for "
|
||||
"ones own modules."));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,15 +188,14 @@ void UnitTestDialog::onAboutButtonClicked()
|
||||
void UnitTestDialog::onStartButtonClicked()
|
||||
{
|
||||
reset();
|
||||
setProgressColor(QColor(40,210,43)); // a darker green
|
||||
setProgressColor(QColor(40, 210, 43));// a darker green
|
||||
ui->startButton->setDisabled(true);
|
||||
try {
|
||||
Base::Interpreter().runString(
|
||||
"import qtunittest, gc\n"
|
||||
"__qt_test__=qtunittest.QtTestRunner(0,\"\")\n"
|
||||
"__qt_test__.runClicked()\n"
|
||||
"del __qt_test__\n"
|
||||
"gc.collect()\n");
|
||||
Base::Interpreter().runString("import qtunittest, gc\n"
|
||||
"__qt_test__=qtunittest.QtTestRunner(0,\"\")\n"
|
||||
"__qt_test__.runClicked()\n"
|
||||
"del __qt_test__\n"
|
||||
"gc.collect()\n");
|
||||
}
|
||||
catch (const Base::PyException& e) {
|
||||
std::string msg = e.what();
|
||||
@@ -238,10 +239,10 @@ void UnitTestDialog::reset()
|
||||
{
|
||||
ui->progressBar->reset();
|
||||
ui->treeViewFailure->clear();
|
||||
ui->textLabelRunCt->setText (QString::fromLatin1("<font color=\"#0000ff\">0</font>"));
|
||||
ui->textLabelRunCt->setText(QString::fromLatin1("<font color=\"#0000ff\">0</font>"));
|
||||
ui->textLabelFailCt->setText(QString::fromLatin1("<font color=\"#0000ff\">0</font>"));
|
||||
ui->textLabelErrCt->setText (QString::fromLatin1("<font color=\"#0000ff\">0</font>"));
|
||||
ui->textLabelRemCt->setText (QString::fromLatin1("<font color=\"#0000ff\">0</font>"));
|
||||
ui->textLabelErrCt->setText(QString::fromLatin1("<font color=\"#0000ff\">0</font>"));
|
||||
ui->textLabelRemCt->setText(QString::fromLatin1("<font color=\"#0000ff\">0</font>"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,9 +251,10 @@ void UnitTestDialog::reset()
|
||||
void UnitTestDialog::addUnitTest(const QString& unit)
|
||||
{
|
||||
int ct = ui->comboTests->count();
|
||||
for (int i=0; i<ct; i++) {
|
||||
if (ui->comboTests->itemText(i) == unit)
|
||||
for (int i = 0; i < ct; i++) {
|
||||
if (ui->comboTests->itemText(i) == unit) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ui->comboTests->addItem(unit);
|
||||
@@ -264,7 +266,7 @@ void UnitTestDialog::addUnitTest(const QString& unit)
|
||||
void UnitTestDialog::setUnitTest(const QString& unit)
|
||||
{
|
||||
addUnitTest(unit);
|
||||
for (int i=0; i<ui->comboTests->count(); i++) {
|
||||
for (int i = 0; i < ui->comboTests->count(); i++) {
|
||||
if (ui->comboTests->itemText(i) == unit) {
|
||||
ui->comboTests->setCurrentIndex(i);
|
||||
break;
|
||||
@@ -318,7 +320,7 @@ void UnitTestDialog::setStatusText(const QString& text)
|
||||
*/
|
||||
void UnitTestDialog::setProgressFraction(float fraction, const QString& color)
|
||||
{
|
||||
if (fraction==0.0f) {
|
||||
if (fraction == 0.0f) {
|
||||
ui->progressBar->setRange(0, 100);
|
||||
}
|
||||
else {
|
||||
@@ -326,7 +328,7 @@ void UnitTestDialog::setProgressFraction(float fraction, const QString& color)
|
||||
setProgressColor(Qt::red);
|
||||
}
|
||||
|
||||
ui->progressBar->setValue((int)(100*fraction));
|
||||
ui->progressBar->setValue((int)(100 * fraction));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,7 +347,7 @@ void UnitTestDialog::clearErrorList()
|
||||
void UnitTestDialog::insertError(const QString& failure, const QString& details)
|
||||
{
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeViewFailure);
|
||||
item->setText(0,failure);
|
||||
item->setText(0, failure);
|
||||
item->setForeground(0, Qt::red);
|
||||
item->setData(0, Qt::UserRole, QVariant(details));
|
||||
}
|
||||
|
||||
@@ -31,10 +31,11 @@
|
||||
|
||||
class QTreeWidgetItem;
|
||||
|
||||
namespace TestGui {
|
||||
namespace TestGui
|
||||
{
|
||||
class Ui_UnitTest;
|
||||
|
||||
class UnitTestDialog : public QDialog
|
||||
class UnitTestDialog: public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -66,7 +67,7 @@ protected:
|
||||
void setProgressColor(const QColor& col);
|
||||
|
||||
private:
|
||||
void onTreeViewFailureItemDoubleClicked (QTreeWidgetItem * item, int column);
|
||||
void onTreeViewFailureItemDoubleClicked(QTreeWidgetItem* item, int column);
|
||||
void onHelpButtonClicked();
|
||||
void onAboutButtonClicked();
|
||||
void onStartButtonClicked();
|
||||
@@ -77,8 +78,7 @@ private:
|
||||
static UnitTestDialog* _instance;
|
||||
};
|
||||
|
||||
} // namespace TestGui
|
||||
}// namespace TestGui
|
||||
|
||||
|
||||
#endif // TESTGUI_UNITTESTIMP_H
|
||||
|
||||
#endif// TESTGUI_UNITTESTIMP_H
|
||||
|
||||
@@ -22,14 +22,14 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <QApplication>
|
||||
# include <QEventLoop>
|
||||
#include <QApplication>
|
||||
#include <QEventLoop>
|
||||
#endif
|
||||
|
||||
#include <Base/Exception.h>
|
||||
|
||||
#include "UnitTestPy.h"
|
||||
#include "UnitTestImp.h"
|
||||
#include "UnitTestPy.h"
|
||||
|
||||
|
||||
using namespace TestGui;
|
||||
@@ -44,20 +44,22 @@ void UnitTestDialogPy::init_type()
|
||||
behaviors().supportGetattr();
|
||||
behaviors().supportSetattr();
|
||||
|
||||
add_varargs_method("clearErrorList",&UnitTestDialogPy::clearErrorList,"clearErrorList");
|
||||
add_varargs_method("insertError",&UnitTestDialogPy::insertError,"insertError");
|
||||
add_varargs_method("setUnitTest",&UnitTestDialogPy::setUnitTest,"setUnitTest");
|
||||
add_varargs_method("getUnitTest",&UnitTestDialogPy::getUnitTest,"getUnitTest");
|
||||
add_varargs_method("setStatusText",&UnitTestDialogPy::setStatusText,"setStatusText");
|
||||
add_varargs_method("setProgressFraction",&UnitTestDialogPy::setProgressFrac,"setProgressFraction");
|
||||
add_varargs_method("errorDialog",&UnitTestDialogPy::errorDialog,"errorDialog");
|
||||
add_varargs_method("setRunCount",&UnitTestDialogPy::setRunCount,"setRunCount");
|
||||
add_varargs_method("setFailCount",&UnitTestDialogPy::setFailCount,"setFailCount");
|
||||
add_varargs_method("setErrorCount",&UnitTestDialogPy::setErrorCount,"setErrorCount");
|
||||
add_varargs_method("setRemainCount",&UnitTestDialogPy::setRemainCount,"setRemainCount");
|
||||
add_varargs_method("updateGUI",&UnitTestDialogPy::updateGUI,"updateGUI");
|
||||
add_varargs_method("addUnitTest",&UnitTestDialogPy::addUnitTest,"addUnitTest");
|
||||
add_varargs_method("clearUnitTests",&UnitTestDialogPy::clearUnitTests,"clearUnitTests");
|
||||
add_varargs_method("clearErrorList", &UnitTestDialogPy::clearErrorList, "clearErrorList");
|
||||
add_varargs_method("insertError", &UnitTestDialogPy::insertError, "insertError");
|
||||
add_varargs_method("setUnitTest", &UnitTestDialogPy::setUnitTest, "setUnitTest");
|
||||
add_varargs_method("getUnitTest", &UnitTestDialogPy::getUnitTest, "getUnitTest");
|
||||
add_varargs_method("setStatusText", &UnitTestDialogPy::setStatusText, "setStatusText");
|
||||
add_varargs_method("setProgressFraction",
|
||||
&UnitTestDialogPy::setProgressFrac,
|
||||
"setProgressFraction");
|
||||
add_varargs_method("errorDialog", &UnitTestDialogPy::errorDialog, "errorDialog");
|
||||
add_varargs_method("setRunCount", &UnitTestDialogPy::setRunCount, "setRunCount");
|
||||
add_varargs_method("setFailCount", &UnitTestDialogPy::setFailCount, "setFailCount");
|
||||
add_varargs_method("setErrorCount", &UnitTestDialogPy::setErrorCount, "setErrorCount");
|
||||
add_varargs_method("setRemainCount", &UnitTestDialogPy::setRemainCount, "setRemainCount");
|
||||
add_varargs_method("updateGUI", &UnitTestDialogPy::updateGUI, "updateGUI");
|
||||
add_varargs_method("addUnitTest", &UnitTestDialogPy::addUnitTest, "addUnitTest");
|
||||
add_varargs_method("clearUnitTests", &UnitTestDialogPy::clearUnitTests, "clearUnitTests");
|
||||
}
|
||||
|
||||
UnitTestDialogPy::UnitTestDialogPy() = default;
|
||||
@@ -69,30 +71,32 @@ Py::Object UnitTestDialogPy::repr()
|
||||
return Py::String("UnitTest");
|
||||
}
|
||||
|
||||
Py::Object UnitTestDialogPy::getattr(const char * attr)
|
||||
Py::Object UnitTestDialogPy::getattr(const char* attr)
|
||||
{
|
||||
return Py::PythonExtension<UnitTestDialogPy>::getattr(attr);
|
||||
}
|
||||
|
||||
int UnitTestDialogPy::setattr(const char * attr, const Py::Object & value)
|
||||
int UnitTestDialogPy::setattr(const char* attr, const Py::Object& value)
|
||||
{
|
||||
return Py::PythonExtension<UnitTestDialogPy>::setattr(attr, value);
|
||||
}
|
||||
|
||||
Py::Object UnitTestDialogPy::clearErrorList(const Py::Tuple& args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args.ptr(), ""))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "")) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
UnitTestDialog::instance()->clearErrorList();
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
Py::Object UnitTestDialogPy::insertError(const Py::Tuple& args)
|
||||
{
|
||||
char *failure=nullptr;
|
||||
char *details=nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "ss", &failure,&details))
|
||||
char* failure = nullptr;
|
||||
char* details = nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "ss", &failure, &details)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
UnitTestDialog::instance()->insertError(QString::fromLatin1(failure),
|
||||
QString::fromLatin1(details));
|
||||
@@ -101,9 +105,10 @@ Py::Object UnitTestDialogPy::insertError(const Py::Tuple& args)
|
||||
|
||||
Py::Object UnitTestDialogPy::setUnitTest(const Py::Tuple& args)
|
||||
{
|
||||
char *pstr=nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
|
||||
char* pstr = nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
UnitTestDialog::instance()->setUnitTest(QString::fromLatin1(pstr));
|
||||
return Py::None();
|
||||
@@ -111,16 +116,18 @@ Py::Object UnitTestDialogPy::setUnitTest(const Py::Tuple& args)
|
||||
|
||||
Py::Object UnitTestDialogPy::getUnitTest(const Py::Tuple& args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args.ptr(), ""))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "")) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
return Py::String((const char*)UnitTestDialog::instance()->getUnitTest().toLatin1());
|
||||
}
|
||||
|
||||
Py::Object UnitTestDialogPy::setStatusText(const Py::Tuple& args)
|
||||
{
|
||||
char *pstr=nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
|
||||
char* pstr = nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
UnitTestDialog::instance()->setStatusText(QString::fromLatin1(pstr));
|
||||
return Py::None();
|
||||
@@ -129,32 +136,37 @@ Py::Object UnitTestDialogPy::setStatusText(const Py::Tuple& args)
|
||||
Py::Object UnitTestDialogPy::setProgressFrac(const Py::Tuple& args)
|
||||
{
|
||||
float fraction;
|
||||
char* pColor=nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "f|s",&fraction, &pColor))
|
||||
char* pColor = nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "f|s", &fraction, &pColor)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
if (pColor)
|
||||
UnitTestDialog::instance()->setProgressFraction(fraction,QString::fromLatin1(pColor));
|
||||
else
|
||||
UnitTestDialog::instance()->setProgressFraction(fraction);
|
||||
if (pColor) {
|
||||
UnitTestDialog::instance()->setProgressFraction(fraction, QString::fromLatin1(pColor));
|
||||
}
|
||||
else {
|
||||
UnitTestDialog::instance()->setProgressFraction(fraction);
|
||||
}
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
Py::Object UnitTestDialogPy::errorDialog(const Py::Tuple& args)
|
||||
{
|
||||
char *title=nullptr;
|
||||
char *message=nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "ss", &title, &message))
|
||||
char* title = nullptr;
|
||||
char* message = nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "ss", &title, &message)) {
|
||||
throw Py::Exception();
|
||||
UnitTestDialog::instance()->showErrorDialog(title,message);
|
||||
}
|
||||
UnitTestDialog::instance()->showErrorDialog(title, message);
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
Py::Object UnitTestDialogPy::setRunCount(const Py::Tuple& args)
|
||||
{
|
||||
int count;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "i", &count))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "i", &count)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
UnitTestDialog::instance()->setRunCount(count);
|
||||
return Py::None();
|
||||
}
|
||||
@@ -162,8 +174,9 @@ Py::Object UnitTestDialogPy::setRunCount(const Py::Tuple& args)
|
||||
Py::Object UnitTestDialogPy::setFailCount(const Py::Tuple& args)
|
||||
{
|
||||
int count;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "i", &count))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "i", &count)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
UnitTestDialog::instance()->setFailCount(count);
|
||||
return Py::None();
|
||||
}
|
||||
@@ -171,8 +184,9 @@ Py::Object UnitTestDialogPy::setFailCount(const Py::Tuple& args)
|
||||
Py::Object UnitTestDialogPy::setErrorCount(const Py::Tuple& args)
|
||||
{
|
||||
int count;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "i", &count))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "i", &count)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
UnitTestDialog::instance()->setErrorCount(count);
|
||||
return Py::None();
|
||||
}
|
||||
@@ -180,25 +194,28 @@ Py::Object UnitTestDialogPy::setErrorCount(const Py::Tuple& args)
|
||||
Py::Object UnitTestDialogPy::setRemainCount(const Py::Tuple& args)
|
||||
{
|
||||
int count;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "i", &count))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "i", &count)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
UnitTestDialog::instance()->setRemainCount(count);
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
Py::Object UnitTestDialogPy::updateGUI(const Py::Tuple& args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args.ptr(), ""))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "")) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
Py::Object UnitTestDialogPy::addUnitTest(const Py::Tuple& args)
|
||||
{
|
||||
char *pstr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
|
||||
char* pstr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
|
||||
dlg->addUnitTest(QString::fromLatin1(pstr));
|
||||
@@ -207,8 +224,9 @@ Py::Object UnitTestDialogPy::addUnitTest(const Py::Tuple& args)
|
||||
|
||||
Py::Object UnitTestDialogPy::clearUnitTests(const Py::Tuple& args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args.ptr(), ""))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "")) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
UnitTestDialog::instance()->clearUnitTests();
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
@@ -32,41 +32,40 @@ namespace TestGui
|
||||
{
|
||||
|
||||
class UnitTestDialog;
|
||||
class UnitTestDialogPy : public Py::PythonExtension<UnitTestDialogPy>
|
||||
class UnitTestDialogPy: public Py::PythonExtension<UnitTestDialogPy>
|
||||
{
|
||||
public:
|
||||
static void init_type(); // announce properties and methods
|
||||
static void init_type();// announce properties and methods
|
||||
|
||||
UnitTestDialogPy();
|
||||
~UnitTestDialogPy() override;
|
||||
|
||||
Py::Object repr() override;
|
||||
Py::Object getattr(const char *) override;
|
||||
int setattr(const char *, const Py::Object &) override;
|
||||
Py::Object getattr(const char*) override;
|
||||
int setattr(const char*, const Py::Object&) override;
|
||||
|
||||
Py::Object clearErrorList (const Py::Tuple&);
|
||||
Py::Object insertError (const Py::Tuple&);
|
||||
Py::Object setUnitTest (const Py::Tuple&);
|
||||
Py::Object getUnitTest (const Py::Tuple&);
|
||||
Py::Object setStatusText (const Py::Tuple&);
|
||||
Py::Object setProgressFrac (const Py::Tuple&);
|
||||
Py::Object errorDialog (const Py::Tuple&);
|
||||
Py::Object setRunCount (const Py::Tuple&);
|
||||
Py::Object setFailCount (const Py::Tuple&);
|
||||
Py::Object setErrorCount (const Py::Tuple&);
|
||||
Py::Object setRemainCount (const Py::Tuple&);
|
||||
Py::Object updateGUI (const Py::Tuple&);
|
||||
Py::Object addUnitTest (const Py::Tuple&);
|
||||
Py::Object clearUnitTests (const Py::Tuple&);
|
||||
Py::Object clearErrorList(const Py::Tuple&);
|
||||
Py::Object insertError(const Py::Tuple&);
|
||||
Py::Object setUnitTest(const Py::Tuple&);
|
||||
Py::Object getUnitTest(const Py::Tuple&);
|
||||
Py::Object setStatusText(const Py::Tuple&);
|
||||
Py::Object setProgressFrac(const Py::Tuple&);
|
||||
Py::Object errorDialog(const Py::Tuple&);
|
||||
Py::Object setRunCount(const Py::Tuple&);
|
||||
Py::Object setFailCount(const Py::Tuple&);
|
||||
Py::Object setErrorCount(const Py::Tuple&);
|
||||
Py::Object setRemainCount(const Py::Tuple&);
|
||||
Py::Object updateGUI(const Py::Tuple&);
|
||||
Py::Object addUnitTest(const Py::Tuple&);
|
||||
Py::Object clearUnitTests(const Py::Tuple&);
|
||||
|
||||
private:
|
||||
using method_varargs_handler = PyObject* (*)(PyObject *_self, PyObject *_args);
|
||||
using method_varargs_handler = PyObject* (*)(PyObject* _self, PyObject* _args);
|
||||
static method_varargs_handler pycxx_handler;
|
||||
static PyObject *method_varargs_ext_handler(PyObject *_self, PyObject *_args);
|
||||
static PyObject* method_varargs_ext_handler(PyObject* _self, PyObject* _args);
|
||||
};
|
||||
|
||||
} //namespace TESTGUI_UNITTESTPY_H
|
||||
}// namespace TestGui
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,33 +1,35 @@
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2001,2002 Juergen Riegel <juergen.riegel@web.de> *
|
||||
#* *
|
||||
#* 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 Lesser 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 *
|
||||
#* *
|
||||
#***************************************************************************/
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2001,2002 Juergen Riegel <juergen.riegel@web.de> *
|
||||
# * *
|
||||
# * 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 Lesser 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 *
|
||||
# * *
|
||||
# ***************************************************************************/
|
||||
|
||||
# FreeCAD init script of the test module
|
||||
|
||||
# Base system tests
|
||||
FreeCAD.__unit_test__ += [ "BaseTests",
|
||||
"UnitTests",
|
||||
"Document",
|
||||
"Metadata",
|
||||
"StringHasher",
|
||||
"UnicodeTests",
|
||||
"TestPythonSyntax" ]
|
||||
FreeCAD.__unit_test__ += [
|
||||
"BaseTests",
|
||||
"UnitTests",
|
||||
"Document",
|
||||
"Metadata",
|
||||
"StringHasher",
|
||||
"UnicodeTests",
|
||||
"TestPythonSyntax",
|
||||
]
|
||||
|
||||
@@ -1,80 +1,95 @@
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2002,2003 Juergen Riegel <juergen.riegel@web.de> *
|
||||
#* *
|
||||
#* 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 Lesser 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 *
|
||||
#* *
|
||||
#***************************************************************************/
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2002,2003 Juergen Riegel <juergen.riegel@web.de> *
|
||||
# * *
|
||||
# * 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 Lesser 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 *
|
||||
# * *
|
||||
# ***************************************************************************/
|
||||
|
||||
# Test gui init module
|
||||
|
||||
class TestWorkbench ( Workbench ):
|
||||
|
||||
class TestWorkbench(Workbench):
|
||||
"Test workbench object"
|
||||
|
||||
def __init__(self):
|
||||
self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/Test/Resources/icons/TestWorkbench.svg"
|
||||
self.__class__.Icon = (
|
||||
FreeCAD.getResourceDir() + "Mod/Test/Resources/icons/TestWorkbench.svg"
|
||||
)
|
||||
self.__class__.MenuText = "Test Framework"
|
||||
self.__class__.ToolTip = "Test Framework"
|
||||
|
||||
def Initialize(self):
|
||||
import TestGui
|
||||
|
||||
list = ["Test_Test","Test_TestAll","Test_TestDoc","Test_TestBase"]
|
||||
self.appendToolbar("TestTools",list)
|
||||
list = ["Test_Test", "Test_TestAll", "Test_TestDoc", "Test_TestBase"]
|
||||
self.appendToolbar("TestTools", list)
|
||||
|
||||
menu = ["Test &Commands","TestToolsGui"]
|
||||
list = ["Std_TestQM","Std_TestReloadQM","Test_Test","Test_TestAll","Test_TestDoc","Test_TestBase"]
|
||||
self.appendCommandbar("TestToolsGui",list)
|
||||
self.appendMenu(menu,list)
|
||||
menu = ["Test &Commands", "TestToolsGui"]
|
||||
list = [
|
||||
"Std_TestQM",
|
||||
"Std_TestReloadQM",
|
||||
"Test_Test",
|
||||
"Test_TestAll",
|
||||
"Test_TestDoc",
|
||||
"Test_TestBase",
|
||||
]
|
||||
self.appendCommandbar("TestToolsGui", list)
|
||||
self.appendMenu(menu, list)
|
||||
|
||||
menu = ["Test &Commands","TestToolsText"]
|
||||
list = ["Test_TestAllText","Test_TestDocText","Test_TestBaseText"]
|
||||
self.appendCommandbar("TestToolsText",list)
|
||||
self.appendMenu(menu,list)
|
||||
menu = ["Test &Commands", "TestToolsText"]
|
||||
list = ["Test_TestAllText", "Test_TestDocText", "Test_TestBaseText"]
|
||||
self.appendCommandbar("TestToolsText", list)
|
||||
self.appendMenu(menu, list)
|
||||
|
||||
menu = ["Test &Commands","TestToolsMenu"]
|
||||
menu = ["Test &Commands", "TestToolsMenu"]
|
||||
list = ["Test_TestCreateMenu", "Test_TestDeleteMenu", "Test_TestWork"]
|
||||
self.appendCommandbar("TestToolsMenu",list)
|
||||
self.appendMenu(menu,list)
|
||||
self.appendCommandbar("TestToolsMenu", list)
|
||||
self.appendMenu(menu, list)
|
||||
|
||||
menu = ["Test &Commands","TestFeatureMenu"]
|
||||
menu = ["Test &Commands", "TestFeatureMenu"]
|
||||
list = ["Test_InsertFeature"]
|
||||
self.appendCommandbar("TestFeature",list)
|
||||
self.appendMenu(menu,list)
|
||||
self.appendCommandbar("TestFeature", list)
|
||||
self.appendMenu(menu, list)
|
||||
|
||||
menu = ["Test &Commands","Progress bar"]
|
||||
list = ["Std_TestProgress1", "Std_TestProgress2", "Std_TestProgress3", "Std_TestProgress4", "Std_TestProgress5"]
|
||||
self.appendMenu(menu,list)
|
||||
menu = ["Test &Commands", "Progress bar"]
|
||||
list = [
|
||||
"Std_TestProgress1",
|
||||
"Std_TestProgress2",
|
||||
"Std_TestProgress3",
|
||||
"Std_TestProgress4",
|
||||
"Std_TestProgress5",
|
||||
]
|
||||
self.appendMenu(menu, list)
|
||||
|
||||
menu = ["Test &Commands","Console"]
|
||||
menu = ["Test &Commands", "Console"]
|
||||
list = ["Std_TestConsoleOutput"]
|
||||
self.appendMenu(menu,list)
|
||||
self.appendMenu(menu, list)
|
||||
|
||||
menu = ["Test &Commands","MDI"]
|
||||
menu = ["Test &Commands", "MDI"]
|
||||
list = ["Std_MDITest1", "Std_MDITest2", "Std_MDITest3"]
|
||||
self.appendMenu(menu,list)
|
||||
self.appendMenu(menu, list)
|
||||
|
||||
list = ["Std_ViewExample1", "Std_ViewExample2", "Std_ViewExample3"]
|
||||
self.appendMenu("Inventor View",list)
|
||||
self.appendMenu("Inventor View", list)
|
||||
|
||||
|
||||
Gui.addWorkbench(TestWorkbench())
|
||||
|
||||
# Base system tests
|
||||
FreeCAD.__unit_test__ += [ "Workbench",
|
||||
"Menu",
|
||||
"Menu.MenuDeleteCases",
|
||||
"Menu.MenuCreateCases" ]
|
||||
FreeCAD.__unit_test__ += ["Workbench", "Menu", "Menu.MenuDeleteCases", "Menu.MenuCreateCases"]
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2005 Werner Mayer <werner.wm.mayer@gmx.de> *
|
||||
#* *
|
||||
#* 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 *
|
||||
#***************************************************************************/
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2005 Werner Mayer <werner.wm.mayer@gmx.de> *
|
||||
# * *
|
||||
# * 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 *
|
||||
# ***************************************************************************/
|
||||
|
||||
# Menu test module
|
||||
|
||||
import FreeCAD, os, unittest, FreeCADGui
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# ---------------------------------------------------------------------------
|
||||
# define the functions to test the FreeCAD base code
|
||||
#---------------------------------------------------------------------------
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
#def suite():
|
||||
# def suite():
|
||||
# suite = unittest.TestSuite()
|
||||
# suite.addTest(DocTestCase("DocumentProperties"))
|
||||
# suite.addTest(DocTestCase("DocumentLabels"))
|
||||
@@ -40,52 +40,51 @@ import FreeCAD, os, unittest, FreeCADGui
|
||||
|
||||
|
||||
class MenuCreateCases(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
FreeCADGui.activateWorkbench("TestWorkbench")
|
||||
FreeCAD.Console.PrintLog ('Setup Test menu...\n')
|
||||
list = ["Test_TestAll","Test_TestDoc","Test_TestBase","Test_TestWork"]
|
||||
w = FreeCADGui.getWorkbench('TestWorkbench')
|
||||
w.appendMenu("TestMenu",list)
|
||||
FreeCAD.Console.PrintLog("Setup Test menu...\n")
|
||||
list = ["Test_TestAll", "Test_TestDoc", "Test_TestBase", "Test_TestWork"]
|
||||
w = FreeCADGui.getWorkbench("TestWorkbench")
|
||||
w.appendMenu("TestMenu", list)
|
||||
|
||||
def testMenu(self):
|
||||
# check menu for items
|
||||
FreeCAD.Console.PrintLog ('Checking Test menu...\n')
|
||||
w = FreeCADGui.getWorkbench('TestWorkbench')
|
||||
FreeCAD.Console.PrintLog("Checking Test menu...\n")
|
||||
w = FreeCADGui.getWorkbench("TestWorkbench")
|
||||
list = w.listMenus()
|
||||
self.b = False
|
||||
for i in list:
|
||||
if i == 'TestMenu': self.b=True
|
||||
self.failUnless(self.b,"Test menu not found")
|
||||
if i == "TestMenu":
|
||||
self.b = True
|
||||
self.failUnless(self.b, "Test menu not found")
|
||||
|
||||
def tearDown(self):
|
||||
if self.b:
|
||||
FreeCAD.Console.PrintLog ('Test menu successfully added\n')
|
||||
else:
|
||||
FreeCAD.Console.PrintLog ('Adding Test menu failed\n')
|
||||
if self.b:
|
||||
FreeCAD.Console.PrintLog("Test menu successfully added\n")
|
||||
else:
|
||||
FreeCAD.Console.PrintLog("Adding Test menu failed\n")
|
||||
|
||||
|
||||
class MenuDeleteCases(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
FreeCADGui.activateWorkbench("TestWorkbench")
|
||||
FreeCAD.Console.PrintLog ('Remove Test menu...\n')
|
||||
w = FreeCADGui.getWorkbench('TestWorkbench')
|
||||
FreeCAD.Console.PrintLog("Remove Test menu...\n")
|
||||
w = FreeCADGui.getWorkbench("TestWorkbench")
|
||||
w.removeMenu("TestMenu")
|
||||
|
||||
def testMenu(self):
|
||||
# check menu for items
|
||||
FreeCAD.Console.PrintLog ('Checking Test menu...\n')
|
||||
w = FreeCADGui.getWorkbench('TestWorkbench')
|
||||
FreeCAD.Console.PrintLog("Checking Test menu...\n")
|
||||
w = FreeCADGui.getWorkbench("TestWorkbench")
|
||||
list = w.listMenus()
|
||||
self.b = True
|
||||
for i in list:
|
||||
if i == 'TestMenu': self.b=False
|
||||
self.failUnless(self.b==True,"Test menu still added")
|
||||
if i == "TestMenu":
|
||||
self.b = False
|
||||
self.failUnless(self.b == True, "Test menu still added")
|
||||
|
||||
def tearDown(self):
|
||||
if self.b:
|
||||
FreeCAD.Console.PrintLog ('Test menu successfully removed\n')
|
||||
else:
|
||||
FreeCAD.Console.PrintLog ('Removing Test menu failed\n')
|
||||
|
||||
if self.b:
|
||||
FreeCAD.Console.PrintLog("Test menu successfully removed\n")
|
||||
else:
|
||||
FreeCAD.Console.PrintLog("Removing Test menu failed\n")
|
||||
|
||||
@@ -28,8 +28,8 @@ import os
|
||||
import codecs
|
||||
import tempfile
|
||||
|
||||
class TestMetadata(unittest.TestCase):
|
||||
|
||||
class TestMetadata(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.test_dir = os.path.join(FreeCAD.getHomePath(), "Mod", "Test", "TestData")
|
||||
|
||||
@@ -40,15 +40,24 @@ class TestMetadata(unittest.TestCase):
|
||||
except Exception:
|
||||
self.fail("Metadata construction from XML file failed")
|
||||
|
||||
with self.assertRaises(FreeCAD.Base.XMLBaseException, msg="Metadata construction from XML file with bad root node did not raise an exception"):
|
||||
with self.assertRaises(
|
||||
FreeCAD.Base.XMLBaseException,
|
||||
msg="Metadata construction from XML file with bad root node did not raise an exception",
|
||||
):
|
||||
filename = os.path.join(self.test_dir, "bad_root_node.xml")
|
||||
md = FreeCAD.Metadata(filename)
|
||||
|
||||
with self.assertRaises(FreeCAD.Base.XMLBaseException, msg="Metadata construction from invalid XML file did not raise an exception"):
|
||||
with self.assertRaises(
|
||||
FreeCAD.Base.XMLBaseException,
|
||||
msg="Metadata construction from invalid XML file did not raise an exception",
|
||||
):
|
||||
filename = os.path.join(self.test_dir, "bad_xml.xml")
|
||||
md = FreeCAD.Metadata(filename)
|
||||
|
||||
with self.assertRaises(FreeCAD.Base.XMLBaseException, msg="Metadata construction from XML file with invalid version did not raise an exception"):
|
||||
with self.assertRaises(
|
||||
FreeCAD.Base.XMLBaseException,
|
||||
msg="Metadata construction from XML file with invalid version did not raise an exception",
|
||||
):
|
||||
filename = os.path.join(self.test_dir, "bad_version.xml")
|
||||
md = FreeCAD.Metadata(filename)
|
||||
|
||||
@@ -66,7 +75,7 @@ class TestMetadata(unittest.TestCase):
|
||||
# Tags that are lists of elements:
|
||||
maintainers = md.Maintainer
|
||||
self.assertEqual(len(maintainers), 2)
|
||||
|
||||
|
||||
authors = md.Author
|
||||
self.assertEqual(len(authors), 3)
|
||||
|
||||
@@ -112,9 +121,10 @@ class TestMetadata(unittest.TestCase):
|
||||
def test_file_path(self):
|
||||
# Issue 7112
|
||||
try:
|
||||
filename = os.path.join(tempfile.gettempdir(), b'H\xc3\xa5vard.xml'.decode("utf-8"))
|
||||
filename = os.path.join(tempfile.gettempdir(), b"H\xc3\xa5vard.xml".decode("utf-8"))
|
||||
xmlfile = codecs.open(filename, mode="w", encoding="utf-8")
|
||||
xmlfile.write(r"""<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
xmlfile.write(
|
||||
r"""<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<package format="1" xmlns="https://wiki.freecad.org/Package_Metadata">
|
||||
<name>test</name>
|
||||
<description>Text</description>
|
||||
@@ -125,14 +135,15 @@ class TestMetadata(unittest.TestCase):
|
||||
<classname>Workbench</classname>
|
||||
</workbench>
|
||||
</content>
|
||||
</package>""")
|
||||
</package>"""
|
||||
)
|
||||
xmlfile.close()
|
||||
md = FreeCAD.Metadata(filename)
|
||||
self.assertEqual(md.Name, "test")
|
||||
self.assertEqual(md.Description, "Text")
|
||||
self.assertEqual(md.Version, "1.0.0")
|
||||
except UnicodeEncodeError as e:
|
||||
print ("Ignore UnicodeEncodeError in test_file_path:\n{}".format(str(e)))
|
||||
print("Ignore UnicodeEncodeError in test_file_path:\n{}".format(str(e)))
|
||||
|
||||
def test_content_item_tags(self):
|
||||
filename = os.path.join(self.test_dir, "content_items.xml")
|
||||
@@ -162,11 +173,13 @@ class TestMetadata(unittest.TestCase):
|
||||
elif workbench.Classname == "TestWorkbenchD":
|
||||
found[3] = True
|
||||
dependencies = workbench.Depend
|
||||
expected_dependencies = {"DependencyA":{"type":"automatic","found":False},
|
||||
"InternalWorkbench":{"type":"internal","found":False},
|
||||
"AddonWorkbench":{"type":"addon","found":False},
|
||||
"PythonPackage":{"type":"python","found":False},
|
||||
"DependencyB":{"type":"automatic","found":False}}
|
||||
expected_dependencies = {
|
||||
"DependencyA": {"type": "automatic", "found": False},
|
||||
"InternalWorkbench": {"type": "internal", "found": False},
|
||||
"AddonWorkbench": {"type": "addon", "found": False},
|
||||
"PythonPackage": {"type": "python", "found": False},
|
||||
"DependencyB": {"type": "automatic", "found": False},
|
||||
}
|
||||
for dep in dependencies:
|
||||
self.assertTrue(dep["package"] in expected_dependencies)
|
||||
self.assertEqual(dep["type"], expected_dependencies[dep["package"]]["type"])
|
||||
@@ -174,8 +187,9 @@ class TestMetadata(unittest.TestCase):
|
||||
for name, expected_dep in expected_dependencies.items():
|
||||
self.assertTrue(expected_dep["found"], f"Failed to load dependency '{name}'")
|
||||
for f in found:
|
||||
self.assertTrue(f,f"One of the expected workbenches was not found in the metadata file")
|
||||
|
||||
self.assertTrue(
|
||||
f, f"One of the expected workbenches was not found in the metadata file"
|
||||
)
|
||||
|
||||
def test_last_supported_version(self):
|
||||
pass
|
||||
@@ -190,4 +204,4 @@ class TestMetadata(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_min_python_version(self):
|
||||
pass
|
||||
pass
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2023 Mario Passaglia <mpassaglia[at]cbc.uba.ar> *
|
||||
#* *
|
||||
#* This file is part of FreeCAD. *
|
||||
#* *
|
||||
#* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
#* under the terms of the GNU Lesser General Public License as *
|
||||
#* published by the Free Software Foundation, either version 2.1 of the *
|
||||
#* License, or (at your option) any later version. *
|
||||
#* *
|
||||
#* 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 *
|
||||
#* Lesser General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Lesser General Public *
|
||||
#* License along with FreeCAD. If not, see *
|
||||
#* <https://www.gnu.org/licenses/>. *
|
||||
#* *
|
||||
#**************************************************************************/
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2023 Mario Passaglia <mpassaglia[at]cbc.uba.ar> *
|
||||
# * *
|
||||
# * This file is part of FreeCAD. *
|
||||
# * *
|
||||
# * FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
# * under the terms of the GNU Lesser General Public License as *
|
||||
# * published by the Free Software Foundation, either version 2.1 of the *
|
||||
# * License, or (at your option) any later version. *
|
||||
# * *
|
||||
# * 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 *
|
||||
# * Lesser General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Lesser General Public *
|
||||
# * License along with FreeCAD. If not, see *
|
||||
# * <https://www.gnu.org/licenses/>. *
|
||||
# * *
|
||||
# **************************************************************************/
|
||||
|
||||
import FreeCAD
|
||||
import unittest
|
||||
|
||||
@@ -1,34 +1,35 @@
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2002 Juergen Riegel <juergen.riegel@web.de> *
|
||||
#* *
|
||||
#* 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 *
|
||||
#* *
|
||||
#***************************************************************************/
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2002 Juergen Riegel <juergen.riegel@web.de> *
|
||||
# * *
|
||||
# * 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
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# ---------------------------------------------------------------------------
|
||||
# define the functions to test the FreeCAD base code
|
||||
#---------------------------------------------------------------------------
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def tryLoadingTest(testName):
|
||||
"Loads and returns testName, or a failing TestCase if unsuccessful."
|
||||
@@ -37,6 +38,7 @@ def tryLoadingTest(testName):
|
||||
return unittest.defaultTestLoader.loadTestsFromName(testName)
|
||||
|
||||
except ImportError:
|
||||
|
||||
class LoadFailed(unittest.TestCase):
|
||||
def __init__(self, testName):
|
||||
# setattr() first, because TestCase ctor checks for methodName.
|
||||
@@ -52,6 +54,7 @@ def tryLoadingTest(testName):
|
||||
|
||||
return LoadFailed(testName)
|
||||
|
||||
|
||||
def All():
|
||||
# Registered tests
|
||||
tests = FreeCAD.__unit_test__
|
||||
@@ -63,6 +66,7 @@ def All():
|
||||
|
||||
return suite
|
||||
|
||||
|
||||
def PrintAll():
|
||||
# Registered tests
|
||||
tests = FreeCAD.__unit_test__
|
||||
|
||||
@@ -1,43 +1,47 @@
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2001,2002 Juergen Riegel <juergen.riegel@web.de> *
|
||||
#* *
|
||||
#* 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 *
|
||||
#* *
|
||||
#***************************************************************************/
|
||||
# -*- coding: utf-8 -*-
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2001,2002 Juergen Riegel <juergen.riegel@web.de> *
|
||||
# * *
|
||||
# * 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 *
|
||||
# * *
|
||||
# ***************************************************************************/
|
||||
|
||||
# FreeCAD Part module
|
||||
#
|
||||
# Part design module
|
||||
|
||||
# import FreeCAD modules
|
||||
import FreeCAD,FreeCADGui
|
||||
import FreeCAD, FreeCADGui
|
||||
|
||||
# import the App Test module
|
||||
import TestApp #Test as Module name not possible
|
||||
import TestApp # Test as Module name not possible
|
||||
import sys
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# ---------------------------------------------------------------------------
|
||||
# define the Commands of the Test Application module
|
||||
#---------------------------------------------------------------------------
|
||||
# ---------------------------------------------------------------------------
|
||||
class TestCmd:
|
||||
"""Opens a Qt dialog with all inserted unit tests"""
|
||||
|
||||
def Activated(self):
|
||||
import QtUnitGui
|
||||
|
||||
tests = FreeCAD.__unit_test__
|
||||
|
||||
QtUnitGui.addTest("TestApp.All")
|
||||
@@ -46,81 +50,115 @@ class TestCmd:
|
||||
QtUnitGui.addTest(test)
|
||||
|
||||
def GetResources(self):
|
||||
return {'MenuText': 'Self-test...', 'ToolTip': 'Runs a self-test to check if the application works properly'}
|
||||
return {
|
||||
"MenuText": "Self-test...",
|
||||
"ToolTip": "Runs a self-test to check if the application works properly",
|
||||
}
|
||||
|
||||
|
||||
class TestAllCmd:
|
||||
"Test all commando object"
|
||||
|
||||
def Activated(self):
|
||||
import QtUnitGui
|
||||
|
||||
QtUnitGui.addTest("TestApp.All")
|
||||
QtUnitGui.setTest("TestApp.All")
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Std_Tool1', 'MenuText': 'Test all', 'ToolTip': 'Runs all tests at once (can take very long!)'}
|
||||
return {
|
||||
"Pixmap": "Std_Tool1",
|
||||
"MenuText": "Test all",
|
||||
"ToolTip": "Runs all tests at once (can take very long!)",
|
||||
}
|
||||
|
||||
|
||||
class TestDocCmd:
|
||||
"Document test commando object"
|
||||
|
||||
def Activated(self):
|
||||
import QtUnitGui
|
||||
|
||||
QtUnitGui.addTest("Document")
|
||||
QtUnitGui.setTest("Document")
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Std_Tool1',
|
||||
'MenuText': 'Test Document',
|
||||
'ToolTip' : 'Test the document (creation, save, load and destruction)'}
|
||||
return {
|
||||
"Pixmap": "Std_Tool1",
|
||||
"MenuText": "Test Document",
|
||||
"ToolTip": "Test the document (creation, save, load and destruction)",
|
||||
}
|
||||
|
||||
|
||||
class TestBaseCmd:
|
||||
"Base test commando object"
|
||||
|
||||
def Activated(self):
|
||||
import QtUnitGui
|
||||
|
||||
QtUnitGui.addTest("BaseTests")
|
||||
QtUnitGui.setTest("BaseTests")
|
||||
|
||||
def GetResources(self):
|
||||
return {
|
||||
'Pixmap' : 'Std_Tool1',
|
||||
'MenuText': 'Test base',
|
||||
'ToolTip' : 'Test the basic functions of FreeCAD'
|
||||
}
|
||||
"Pixmap": "Std_Tool1",
|
||||
"MenuText": "Test base",
|
||||
"ToolTip": "Test the basic functions of FreeCAD",
|
||||
}
|
||||
|
||||
|
||||
class TestAllTextCmd:
|
||||
"Test all commando object"
|
||||
|
||||
def Activated(self):
|
||||
import unittest, TestApp
|
||||
unittest.TextTestRunner(stream=sys.stdout,verbosity=2).run(unittest.defaultTestLoader.loadTestsFromName("TestApp.All"))
|
||||
|
||||
unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(
|
||||
unittest.defaultTestLoader.loadTestsFromName("TestApp.All")
|
||||
)
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Std_Tool1',
|
||||
'MenuText': 'Test all',
|
||||
'ToolTip' : 'Runs all tests at once (can take very long!)'
|
||||
}
|
||||
return {
|
||||
"Pixmap": "Std_Tool1",
|
||||
"MenuText": "Test all",
|
||||
"ToolTip": "Runs all tests at once (can take very long!)",
|
||||
}
|
||||
|
||||
|
||||
class TestDocTextCmd:
|
||||
"Document test commando object"
|
||||
|
||||
def Activated(self):
|
||||
TestApp.TestText("Document")
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Std_Tool1',
|
||||
'MenuText': 'Test Document',
|
||||
'ToolTip' : 'Test the document (creation, save, load and destruction)'}
|
||||
return {
|
||||
"Pixmap": "Std_Tool1",
|
||||
"MenuText": "Test Document",
|
||||
"ToolTip": "Test the document (creation, save, load and destruction)",
|
||||
}
|
||||
|
||||
|
||||
class TestBaseTextCmd:
|
||||
"Base test commando object"
|
||||
|
||||
def Activated(self):
|
||||
TestApp.TestText("BaseTests")
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Std_Tool1',
|
||||
'MenuText': 'Test base',
|
||||
'ToolTip' : 'Test the basic functions of FreeCAD'}
|
||||
return {
|
||||
"Pixmap": "Std_Tool1",
|
||||
"MenuText": "Test base",
|
||||
"ToolTip": "Test the basic functions of FreeCAD",
|
||||
}
|
||||
|
||||
|
||||
class TestWorkbenchCmd:
|
||||
"Workbench test"
|
||||
|
||||
def Activated(self):
|
||||
i=0
|
||||
while (i<20):
|
||||
i = 0
|
||||
while i < 20:
|
||||
FreeCADGui.activateWorkbench("MeshWorkbench")
|
||||
FreeCADGui.updateGui()
|
||||
FreeCADGui.activateWorkbench("NoneWorkbench")
|
||||
@@ -128,36 +166,48 @@ class TestWorkbenchCmd:
|
||||
FreeCADGui.activateWorkbench("PartWorkbench")
|
||||
FreeCADGui.updateGui()
|
||||
print(i)
|
||||
i=i+1
|
||||
i = i + 1
|
||||
FreeCADGui.activateWorkbench("TestWorkbench")
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Std_Tool1',
|
||||
'MenuText': 'Test workbench',
|
||||
'ToolTip' : 'Test the switching of workbenches in FreeCAD'}
|
||||
return {
|
||||
"Pixmap": "Std_Tool1",
|
||||
"MenuText": "Test workbench",
|
||||
"ToolTip": "Test the switching of workbenches in FreeCAD",
|
||||
}
|
||||
|
||||
|
||||
class TestCreateMenuCmd:
|
||||
"Base test commando object"
|
||||
|
||||
def Activated(self):
|
||||
TestApp.TestText("Menu.MenuCreateCases")
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Std_Tool1',
|
||||
'MenuText': 'Add menu',
|
||||
'ToolTip' : 'Test the menu stuff of FreeCAD'}
|
||||
return {
|
||||
"Pixmap": "Std_Tool1",
|
||||
"MenuText": "Add menu",
|
||||
"ToolTip": "Test the menu stuff of FreeCAD",
|
||||
}
|
||||
|
||||
|
||||
class TestDeleteMenuCmd:
|
||||
"Base test commando object"
|
||||
|
||||
def Activated(self):
|
||||
TestApp.TestText("Menu.MenuDeleteCases")
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Std_Tool1',
|
||||
'MenuText': 'Remove menu',
|
||||
'ToolTip' : 'Test the menu stuff of FreeCAD'}
|
||||
return {
|
||||
"Pixmap": "Std_Tool1",
|
||||
"MenuText": "Remove menu",
|
||||
"ToolTip": "Test the menu stuff of FreeCAD",
|
||||
}
|
||||
|
||||
|
||||
class TestInsertFeatureCmd:
|
||||
"Base test commando object"
|
||||
|
||||
def Activated(self):
|
||||
if FreeCAD.activeDocument() is not None:
|
||||
FreeCAD.activeDocument().addObject("App::FeatureTest")
|
||||
@@ -165,21 +215,24 @@ class TestInsertFeatureCmd:
|
||||
FreeCAD.PrintMessage("No active document.\n")
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Std_Tool1',
|
||||
'MenuText': 'Insert a TestFeature',
|
||||
'ToolTip' : 'Insert a TestFeature in the active Document'}
|
||||
return {
|
||||
"Pixmap": "Std_Tool1",
|
||||
"MenuText": "Insert a TestFeature",
|
||||
"ToolTip": "Insert a TestFeature in the active Document",
|
||||
}
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Adds the commands to the FreeCAD command manager
|
||||
#---------------------------------------------------------------------------
|
||||
FreeCADGui.addCommand('Test_Test' ,TestCmd())
|
||||
FreeCADGui.addCommand('Test_TestAllText' ,TestAllTextCmd())
|
||||
FreeCADGui.addCommand('Test_TestDocText' ,TestDocTextCmd())
|
||||
FreeCADGui.addCommand('Test_TestBaseText',TestBaseTextCmd())
|
||||
FreeCADGui.addCommand('Test_TestAll' ,TestAllCmd())
|
||||
FreeCADGui.addCommand('Test_TestDoc' ,TestDocCmd())
|
||||
FreeCADGui.addCommand('Test_TestBase' ,TestBaseCmd())
|
||||
FreeCADGui.addCommand('Test_TestWork' ,TestWorkbenchCmd())
|
||||
FreeCADGui.addCommand('Test_TestCreateMenu' ,TestCreateMenuCmd())
|
||||
FreeCADGui.addCommand('Test_TestDeleteMenu' ,TestDeleteMenuCmd())
|
||||
FreeCADGui.addCommand('Test_InsertFeature' ,TestInsertFeatureCmd())
|
||||
# ---------------------------------------------------------------------------
|
||||
FreeCADGui.addCommand("Test_Test", TestCmd())
|
||||
FreeCADGui.addCommand("Test_TestAllText", TestAllTextCmd())
|
||||
FreeCADGui.addCommand("Test_TestDocText", TestDocTextCmd())
|
||||
FreeCADGui.addCommand("Test_TestBaseText", TestBaseTextCmd())
|
||||
FreeCADGui.addCommand("Test_TestAll", TestAllCmd())
|
||||
FreeCADGui.addCommand("Test_TestDoc", TestDocCmd())
|
||||
FreeCADGui.addCommand("Test_TestBase", TestBaseCmd())
|
||||
FreeCADGui.addCommand("Test_TestWork", TestWorkbenchCmd())
|
||||
FreeCADGui.addCommand("Test_TestCreateMenu", TestCreateMenuCmd())
|
||||
FreeCADGui.addCommand("Test_TestDeleteMenu", TestDeleteMenuCmd())
|
||||
FreeCADGui.addCommand("Test_InsertFeature", TestInsertFeatureCmd())
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2018 looooo <sppedflyer@gmail.com> *
|
||||
#* *
|
||||
#* 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 *
|
||||
#* *
|
||||
#***************************************************************************/
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2018 looooo <sppedflyer@gmail.com> *
|
||||
# * *
|
||||
# * 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 os
|
||||
import ast
|
||||
@@ -34,7 +34,7 @@ def test_python_syntax(rootdir, whitelist=None):
|
||||
for fn in files:
|
||||
kargs = {}
|
||||
kargs["encoding"] = "utf-8"
|
||||
if (not fn in whitelist) and os.path.splitext(fn)[1] == '.py':
|
||||
if (not fn in whitelist) and os.path.splitext(fn)[1] == ".py":
|
||||
with open(os.path.join(sub_dir, fn), **kargs) as py_file:
|
||||
try:
|
||||
ast.parse(py_file.read())
|
||||
@@ -45,17 +45,23 @@ def test_python_syntax(rootdir, whitelist=None):
|
||||
for i, m in enumerate(log):
|
||||
message += str(i + 1) + " " + m + "\n"
|
||||
if log:
|
||||
raise RuntimeError("there are some files not parse-able with the used python-interpreter" + message)
|
||||
raise RuntimeError(
|
||||
"there are some files not parse-able with the used python-interpreter" + message
|
||||
)
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
class PythonSyntaxTestCase(unittest.TestCase):
|
||||
"""
|
||||
Test Case to test python syntax of all python files in FreeCAD
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.whitelist = []
|
||||
self.whitelist += ["ap203_configuration_controlled_3d_design_of_mechanical_parts_and_assemblies_mim_lf.py"]
|
||||
self.whitelist += [
|
||||
"ap203_configuration_controlled_3d_design_of_mechanical_parts_and_assemblies_mim_lf.py"
|
||||
]
|
||||
self.whitelist += ["automotive_design.py"]
|
||||
self.whitelist += ["ifc2x3.py"]
|
||||
self.whitelist += ["ifc4.py"]
|
||||
|
||||
@@ -1,71 +1,69 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2007 Juergen Riegel <juergen.riegel@web.de> *
|
||||
#* *
|
||||
#* 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 *
|
||||
#* *
|
||||
#***************************************************************************/
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2007 Juergen Riegel <juergen.riegel@web.de> *
|
||||
# * *
|
||||
# * 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 *
|
||||
# * *
|
||||
# ***************************************************************************/
|
||||
|
||||
# Open and edit only in UTF-8 !!!!!!
|
||||
|
||||
import FreeCAD, os, unittest, tempfile
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# ---------------------------------------------------------------------------
|
||||
# define the functions to test the FreeCAD Document code
|
||||
#---------------------------------------------------------------------------
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class UnicodeBasicCases(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.Doc = FreeCAD.newDocument("CreateTest")
|
||||
def setUp(self):
|
||||
self.Doc = FreeCAD.newDocument("CreateTest")
|
||||
|
||||
def testUnicodeLabel(self):
|
||||
L1 = self.Doc.addObject("App::FeatureTest","Label_1")
|
||||
L1.Label = u"हिन्दी"
|
||||
self.failUnless(L1.Label == u"हिन्दी")
|
||||
def testUnicodeLabel(self):
|
||||
L1 = self.Doc.addObject("App::FeatureTest", "Label_1")
|
||||
L1.Label = "हिन्दी"
|
||||
self.failUnless(L1.Label == "हिन्दी")
|
||||
|
||||
def tearDown(self):
|
||||
# closing doc
|
||||
FreeCAD.closeDocument("CreateTest")
|
||||
|
||||
def tearDown(self):
|
||||
#closing doc
|
||||
FreeCAD.closeDocument("CreateTest")
|
||||
|
||||
class DocumentSaveRestoreCases(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.Doc = FreeCAD.newDocument("SaveRestoreTests")
|
||||
L1 = self.Doc.addObject("App::FeatureTest","Label_1")
|
||||
L1.Label = u"हिन्दी"
|
||||
self.TempPath = tempfile.gettempdir()
|
||||
FreeCAD.Console.PrintLog( ' Using temp path: ' + self.TempPath + '\n')
|
||||
|
||||
def testSaveAndRestore(self):
|
||||
# saving and restoring
|
||||
SaveName = self.TempPath + os.sep + "UnicodeTest.FCStd"
|
||||
self.Doc.saveAs(SaveName)
|
||||
FreeCAD.closeDocument("SaveRestoreTests")
|
||||
self.Doc = FreeCAD.open(SaveName)
|
||||
self.failUnless(self.Doc.Label_1.Label == u"हिन्दी")
|
||||
FreeCAD.closeDocument("UnicodeTest")
|
||||
FreeCAD.newDocument("SaveRestoreTests")
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
#closing doc
|
||||
FreeCAD.closeDocument("SaveRestoreTests")
|
||||
def setUp(self):
|
||||
self.Doc = FreeCAD.newDocument("SaveRestoreTests")
|
||||
L1 = self.Doc.addObject("App::FeatureTest", "Label_1")
|
||||
L1.Label = "हिन्दी"
|
||||
self.TempPath = tempfile.gettempdir()
|
||||
FreeCAD.Console.PrintLog(" Using temp path: " + self.TempPath + "\n")
|
||||
|
||||
def testSaveAndRestore(self):
|
||||
# saving and restoring
|
||||
SaveName = self.TempPath + os.sep + "UnicodeTest.FCStd"
|
||||
self.Doc.saveAs(SaveName)
|
||||
FreeCAD.closeDocument("SaveRestoreTests")
|
||||
self.Doc = FreeCAD.open(SaveName)
|
||||
self.failUnless(self.Doc.Label_1.Label == "हिन्दी")
|
||||
FreeCAD.closeDocument("UnicodeTest")
|
||||
FreeCAD.newDocument("SaveRestoreTests")
|
||||
|
||||
def tearDown(self):
|
||||
# closing doc
|
||||
FreeCAD.closeDocument("SaveRestoreTests")
|
||||
|
||||
@@ -1,44 +1,47 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2010 Juergen Riegel <juergen.riegel@web.de> *
|
||||
#* *
|
||||
#* 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 *
|
||||
#* *
|
||||
#***************************************************************************/
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2010 Juergen Riegel <juergen.riegel@web.de> *
|
||||
# * *
|
||||
# * 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
|
||||
import unittest
|
||||
import math
|
||||
|
||||
|
||||
def tu(str):
|
||||
return FreeCAD.Units.Quantity(str).Value
|
||||
|
||||
|
||||
def ts(q):
|
||||
return q.UserString
|
||||
|
||||
|
||||
def ts2(q):
|
||||
return FreeCAD.Units.Quantity(q.UserString).UserString
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# ---------------------------------------------------------------------------
|
||||
# define the functions to test the FreeCAD UnitApi code
|
||||
#---------------------------------------------------------------------------
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def compare(x, y):
|
||||
@@ -49,24 +52,24 @@ class UnitBasicCases(unittest.TestCase):
|
||||
def setUp(self):
|
||||
par = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units")
|
||||
dec = par.GetInt("Decimals")
|
||||
self.delta = math.pow(10,-dec)
|
||||
self.delta = math.pow(10, -dec)
|
||||
|
||||
def testConversions(self):
|
||||
#tu = FreeCAD.Units.translateUnit
|
||||
self.assertTrue(compare(tu('10 m'), 10000.0))
|
||||
self.assertTrue(compare(tu('3/8 in'), 9.525))
|
||||
self.assertTrue(compare(tu('100 km/h'), 27777.77777777))
|
||||
self.assertTrue(compare(tu('m^2*kg*s^-3*A^-2'), 1000000.0))
|
||||
self.assertTrue(compare(tu('(m^2*kg)/(A^2*s^3)'), 1000000.0))
|
||||
self.assertTrue(compare(tu('2*pi rad'), 360.0))
|
||||
self.assertTrue(compare(tu('2*pi rad') / tu('gon'), 400.0))
|
||||
self.assertTrue(compare(tu('999 kg') / tu('1 m^3'), 0.000009999))
|
||||
# tu = FreeCAD.Units.translateUnit
|
||||
self.assertTrue(compare(tu("10 m"), 10000.0))
|
||||
self.assertTrue(compare(tu("3/8 in"), 9.525))
|
||||
self.assertTrue(compare(tu("100 km/h"), 27777.77777777))
|
||||
self.assertTrue(compare(tu("m^2*kg*s^-3*A^-2"), 1000000.0))
|
||||
self.assertTrue(compare(tu("(m^2*kg)/(A^2*s^3)"), 1000000.0))
|
||||
self.assertTrue(compare(tu("2*pi rad"), 360.0))
|
||||
self.assertTrue(compare(tu("2*pi rad") / tu("gon"), 400.0))
|
||||
self.assertTrue(compare(tu("999 kg") / tu("1 m^3"), 0.000009999))
|
||||
|
||||
def testImperial(self):
|
||||
#tu = FreeCAD.Units.translateUnit
|
||||
self.assertTrue(compare(tu('3/8in'), 9.525))
|
||||
#self.assertTrue(compare(tu('1fo(3+7/16)in'),392.112500))thisgivesaparsersyntaxerror!!!
|
||||
self.assertTrue(compare(tu('1\'(3+7/16)"'), 392.112500))
|
||||
# tu = FreeCAD.Units.translateUnit
|
||||
self.assertTrue(compare(tu("3/8in"), 9.525))
|
||||
# self.assertTrue(compare(tu('1fo(3+7/16)in'),392.112500))thisgivesaparsersyntaxerror!!!
|
||||
self.assertTrue(compare(tu("1'(3+7/16)\""), 392.112500))
|
||||
|
||||
psi = FreeCAD.Units.parseQuantity("1psi")
|
||||
mpa = psi.getValueAs("MPa").Value
|
||||
@@ -91,7 +94,7 @@ class UnitBasicCases(unittest.TestCase):
|
||||
def testDivide(self):
|
||||
qu1 = FreeCAD.Units.Quantity("1 m/s")
|
||||
qu2 = FreeCAD.Units.Quantity("m/s")
|
||||
self.assertTrue(qu1/qu2, 1)
|
||||
self.assertTrue(qu1 / qu2, 1)
|
||||
|
||||
def testSchemes(self):
|
||||
schemes = FreeCAD.Units.listSchemas()
|
||||
@@ -101,20 +104,41 @@ class UnitBasicCases(unittest.TestCase):
|
||||
for i in range(num):
|
||||
t = FreeCAD.Units.schemaTranslate(psi, i)
|
||||
v = FreeCAD.Units.parseQuantity(t[0]).getValueAs("psi")
|
||||
self.assertAlmostEqual(1, v.Value, msg="Failed with \"{0}\" scheme: {1} != 1 (delta: {2})".format(schemes[i], v.Value, self.delta), delta=self.delta)
|
||||
self.assertAlmostEqual(
|
||||
1,
|
||||
v.Value,
|
||||
msg='Failed with "{0}" scheme: {1} != 1 (delta: {2})'.format(
|
||||
schemes[i], v.Value, self.delta
|
||||
),
|
||||
delta=self.delta,
|
||||
)
|
||||
|
||||
ksi = FreeCAD.Units.parseQuantity("1ksi")
|
||||
for i in range(num):
|
||||
t = FreeCAD.Units.schemaTranslate(ksi, i)
|
||||
v = FreeCAD.Units.parseQuantity(t[0]).getValueAs("ksi")
|
||||
self.assertAlmostEqual(1, v.Value, msg="Failed with \"{0}\" scheme: {1} != 1 (delta: {2})".format(schemes[i], v.Value, self.delta), delta=self.delta)
|
||||
self.assertAlmostEqual(
|
||||
1,
|
||||
v.Value,
|
||||
msg='Failed with "{0}" scheme: {1} != 1 (delta: {2})'.format(
|
||||
schemes[i], v.Value, self.delta
|
||||
),
|
||||
delta=self.delta,
|
||||
)
|
||||
|
||||
vacuum_permittivity = FreeCAD.Units.parseQuantity("1F/m")
|
||||
vacuum_permittivity.Format = {"NumberFormat" : FreeCAD.Units.NumberFormat.Scientific}
|
||||
vacuum_permittivity.Format = {"NumberFormat": FreeCAD.Units.NumberFormat.Scientific}
|
||||
for i in range(num):
|
||||
t = FreeCAD.Units.schemaTranslate(vacuum_permittivity, i)
|
||||
v = FreeCAD.Units.parseQuantity(t[0]).getValueAs("F/m")
|
||||
self.assertAlmostEqual(1, v.Value, msg="Failed with \"{0}\" scheme: {1} != 1 (delta: {2})".format(schemes[i], v.Value, self.delta), delta=self.delta)
|
||||
self.assertAlmostEqual(
|
||||
1,
|
||||
v.Value,
|
||||
msg='Failed with "{0}" scheme: {1} != 1 (delta: {2})'.format(
|
||||
schemes[i], v.Value, self.delta
|
||||
),
|
||||
delta=self.delta,
|
||||
)
|
||||
|
||||
def testSchemeTranslation(self):
|
||||
quantities = []
|
||||
@@ -126,33 +150,37 @@ class UnitBasicCases(unittest.TestCase):
|
||||
for i in quantities:
|
||||
q1 = getattr(FreeCAD.Units, i)
|
||||
q1 = FreeCAD.Units.Quantity(q1)
|
||||
q1.Format = {'Precision': 16}
|
||||
q1.Format = {"Precision": 16}
|
||||
for idx, val in enumerate(schemes):
|
||||
[t, amountPerUnit, unit] = FreeCAD.Units.schemaTranslate(q1, idx)
|
||||
try:
|
||||
q2 = FreeCAD.Units.Quantity(t)
|
||||
if math.fabs(q1.Value - q2.Value) > 0.01:
|
||||
print (" {} : {} : {} : {} : {}".format(q1, q2, t, i, val).encode("utf-8").strip())
|
||||
print(
|
||||
" {} : {} : {} : {} : {}".format(q1, q2, t, i, val)
|
||||
.encode("utf-8")
|
||||
.strip()
|
||||
)
|
||||
except Exception as e:
|
||||
print ("{} : {} : {} : {}".format(q1, i, val, e).encode("utf-8").strip())
|
||||
print("{} : {} : {} : {}".format(q1, i, val, e).encode("utf-8").strip())
|
||||
|
||||
def testVoltage(self):
|
||||
q1 = FreeCAD.Units.Quantity("1e20 V")
|
||||
t = FreeCAD.Units.schemaTranslate(q1, 0) # Standard
|
||||
t = FreeCAD.Units.schemaTranslate(q1, 0) # Standard
|
||||
q2 = FreeCAD.Units.Quantity(t[0])
|
||||
self.assertAlmostEqual(q1.Value, q2.Value, delta=self.delta)
|
||||
|
||||
def testEnergy(self):
|
||||
q1 = FreeCAD.Units.Quantity("1e20 J")
|
||||
t = FreeCAD.Units.schemaTranslate(q1, 0) # Standard
|
||||
t = FreeCAD.Units.schemaTranslate(q1, 0) # Standard
|
||||
q2 = FreeCAD.Units.Quantity(t[0])
|
||||
self.assertAlmostEqual(q1.Value, q2.Value, delta=self.delta)
|
||||
|
||||
def testTrigonometric(self):
|
||||
#tu=FreeCAD.Units.translateUnit
|
||||
self.assertTrue(compare(tu('sin(pi)'), math.sin(math.pi)))
|
||||
self.assertTrue(compare(tu('cos(pi)'), math.cos(math.pi)))
|
||||
self.assertTrue(compare(tu('tan(pi)'), math.tan(math.pi)))
|
||||
# tu=FreeCAD.Units.translateUnit
|
||||
self.assertTrue(compare(tu("sin(pi)"), math.sin(math.pi)))
|
||||
self.assertTrue(compare(tu("cos(pi)"), math.cos(math.pi)))
|
||||
self.assertTrue(compare(tu("tan(pi)"), math.tan(math.pi)))
|
||||
|
||||
def testQuantity(self):
|
||||
length = FreeCAD.Units.Quantity(1, "m")
|
||||
@@ -160,34 +188,34 @@ class UnitBasicCases(unittest.TestCase):
|
||||
self.assertEqual(length.Unit, FreeCAD.Units.Length)
|
||||
|
||||
def testToString(self):
|
||||
value = FreeCAD.Units.toNumber(1023, 'g', 2)
|
||||
value = FreeCAD.Units.toNumber(1023, "g", 2)
|
||||
self.assertEqual(float(value), 1000)
|
||||
|
||||
value = FreeCAD.Units.toNumber(1023, 'g', 3)
|
||||
value = FreeCAD.Units.toNumber(1023, "g", 3)
|
||||
self.assertEqual(float(value), 1020)
|
||||
|
||||
value = FreeCAD.Units.toNumber(1023, 'f', 2)
|
||||
value = FreeCAD.Units.toNumber(1023, "f", 2)
|
||||
self.assertEqual(float(value), 1023)
|
||||
|
||||
value = FreeCAD.Units.toNumber(1023, 'e', 1)
|
||||
value = FreeCAD.Units.toNumber(1023, "e", 1)
|
||||
self.assertEqual(float(value), 1000)
|
||||
|
||||
value = FreeCAD.Units.toNumber(1023, 'e', 2)
|
||||
value = FreeCAD.Units.toNumber(1023, "e", 2)
|
||||
self.assertEqual(float(value), 1020)
|
||||
|
||||
value = FreeCAD.Units.toNumber(1023, 'e', 3)
|
||||
value = FreeCAD.Units.toNumber(1023, "e", 3)
|
||||
self.assertEqual(float(value), 1023)
|
||||
|
||||
q = FreeCAD.Units.Quantity("1023")
|
||||
value = FreeCAD.Units.toNumber(q, 'f', 2)
|
||||
value = FreeCAD.Units.toNumber(q, "f", 2)
|
||||
self.assertEqual(float(value), 1023)
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
FreeCAD.Units.toNumber("1023", 'g', 2)
|
||||
FreeCAD.Units.toNumber("1023", "g", 2)
|
||||
with self.assertRaises(ValueError):
|
||||
FreeCAD.Units.toNumber(1023, 'gg', 2)
|
||||
FreeCAD.Units.toNumber(1023, "gg", 2)
|
||||
with self.assertRaises(ValueError):
|
||||
FreeCAD.Units.toNumber(1023, 's', 2)
|
||||
FreeCAD.Units.toNumber(1023, "s", 2)
|
||||
|
||||
def testIssue6735(self):
|
||||
FreeCAD.Units.Quantity("1400.0 N/mm^2")
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2006 Werner Mayer <werner.wm.mayer@gmx.de> *
|
||||
#* *
|
||||
#* 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 *
|
||||
#* *
|
||||
#***************************************************************************/
|
||||
# -*- coding: utf-8 -*-
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2006 Werner Mayer <werner.wm.mayer@gmx.de> *
|
||||
# * *
|
||||
# * 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 *
|
||||
# * *
|
||||
# ***************************************************************************/
|
||||
|
||||
# Workbench test module
|
||||
|
||||
@@ -29,58 +30,69 @@ import tempfile
|
||||
from PySide import QtWidgets, QtCore
|
||||
from PySide.QtWidgets import QApplication
|
||||
|
||||
|
||||
class CallableCheckWarning:
|
||||
def __call__(self):
|
||||
diag = QApplication.activeModalWidget()
|
||||
if (diag):
|
||||
QtCore.QTimer.singleShot(0, diag, QtCore.SLOT('accept()'))
|
||||
if diag:
|
||||
QtCore.QTimer.singleShot(0, diag, QtCore.SLOT("accept()"))
|
||||
|
||||
|
||||
class WorkbenchTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.Active = FreeCADGui.activeWorkbench()
|
||||
FreeCAD.Console.PrintLog(FreeCADGui.activeWorkbench().name())
|
||||
|
||||
|
||||
def testActivate(self):
|
||||
wbs=FreeCADGui.listWorkbenches()
|
||||
wbs = FreeCADGui.listWorkbenches()
|
||||
# this gives workbenches a possibility to detect that we're under test environment
|
||||
FreeCAD.TestEnvironment = True
|
||||
for i in wbs:
|
||||
try:
|
||||
print ("Activate workbench '{}'".format(i))
|
||||
print("Activate workbench '{}'".format(i))
|
||||
cobj = CallableCheckWarning()
|
||||
QtCore.QTimer.singleShot(500, cobj)
|
||||
success = FreeCADGui.activateWorkbench(i)
|
||||
FreeCAD.Console.PrintLog("Active: "+FreeCADGui.activeWorkbench().name()+ " Expected: "+i+"\n")
|
||||
FreeCAD.Console.PrintLog(
|
||||
"Active: " + FreeCADGui.activeWorkbench().name() + " Expected: " + i + "\n"
|
||||
)
|
||||
self.assertTrue(success, "Test on activating workbench {0} failed".format(i))
|
||||
except Exception as e:
|
||||
self.fail("Loading of workbench '{0}' failed: {1}".format(i, e))
|
||||
del FreeCAD.TestEnvironment
|
||||
|
||||
|
||||
def testHandler(self):
|
||||
import __main__
|
||||
|
||||
class UnitWorkbench(__main__.Workbench):
|
||||
MenuText = "Unittest"
|
||||
ToolTip = "Unittest"
|
||||
|
||||
def Initialize(self):
|
||||
cmds = ["Test_Test"]
|
||||
self.appendToolbar("My Unittest",cmds)
|
||||
self.appendToolbar("My Unittest", cmds)
|
||||
|
||||
def GetClassName(self):
|
||||
return "Gui::PythonWorkbench"
|
||||
|
||||
FreeCADGui.addWorkbench(UnitWorkbench())
|
||||
wbs=FreeCADGui.listWorkbenches()
|
||||
wbs = FreeCADGui.listWorkbenches()
|
||||
self.failUnless("UnitWorkbench" in wbs, "Test on adding workbench handler failed")
|
||||
FreeCADGui.activateWorkbench("UnitWorkbench")
|
||||
FreeCADGui.updateGui()
|
||||
self.failUnless(FreeCADGui.activeWorkbench().name()=="UnitWorkbench", "Test on loading workbench 'Unittest' failed")
|
||||
self.failUnless(
|
||||
FreeCADGui.activeWorkbench().name() == "UnitWorkbench",
|
||||
"Test on loading workbench 'Unittest' failed",
|
||||
)
|
||||
FreeCADGui.removeWorkbench("UnitWorkbench")
|
||||
wbs=FreeCADGui.listWorkbenches()
|
||||
wbs = FreeCADGui.listWorkbenches()
|
||||
self.failUnless(not "UnitWorkbench" in wbs, "Test on removing workbench handler failed")
|
||||
|
||||
def testInvalidType(self):
|
||||
class MyExtWorkbench(FreeCADGui.Workbench):
|
||||
def Initialize(self):
|
||||
pass
|
||||
|
||||
def GetClassName(self):
|
||||
return "App::Extension"
|
||||
|
||||
@@ -93,6 +105,7 @@ class WorkbenchTestCase(unittest.TestCase):
|
||||
FreeCADGui.activateWorkbench(self.Active.name())
|
||||
FreeCAD.Console.PrintLog(self.Active.name())
|
||||
|
||||
|
||||
class CommandTestCase(unittest.TestCase):
|
||||
def testPR6889(self):
|
||||
# Fixes a crash
|
||||
@@ -106,13 +119,16 @@ class CommandTestCase(unittest.TestCase):
|
||||
cmd = FreeCADGui.Command.get(name)
|
||||
cmd.run()
|
||||
|
||||
|
||||
class TestNavigationStyle(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.Doc = FreeCAD.newDocument("CreateTest")
|
||||
|
||||
def testInvalidStyle(self):
|
||||
FreeCADGui.getDocument(self.Doc).ActiveView.setNavigationType("App::Extension")
|
||||
self.assertNotEqual(FreeCADGui.getDocument(self.Doc).ActiveView.getNavigationType(), "App::Extension")
|
||||
self.assertNotEqual(
|
||||
FreeCADGui.getDocument(self.Doc).ActiveView.getNavigationType(), "App::Extension"
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
FreeCAD.closeDocument("CreateTest")
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import unittest
|
||||
|
||||
|
||||
def runTestsFromClass(test_case_class, verbosity=2):
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(test_case_class)
|
||||
unittest.TextTestRunner(verbosity=verbosity).run(suite)
|
||||
|
||||
|
||||
def runTestsFromModule(test_module, verbosity=2):
|
||||
suite = unittest.TestLoader().loadTestsFromModule(test_module)
|
||||
unittest.TextTestRunner(verbosity=verbosity).run(suite)
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2013 WandererFan <wandererfan@gmail.com> *
|
||||
#* *
|
||||
#* 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 *
|
||||
#* *
|
||||
#***************************************************************************/
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2013 WandererFan <wandererfan@gmail.com> *
|
||||
# * *
|
||||
# * 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 *
|
||||
# * *
|
||||
# ***************************************************************************/
|
||||
|
||||
# Tester for Draft makePathArray - shapes on a path - without subelements (see testPathArraySel.py)
|
||||
# Usage: in FC gui, select a "shape" document object (sphere, box, etc) (!!select in
|
||||
@@ -34,11 +34,11 @@ import Part
|
||||
import Draft
|
||||
|
||||
print("testPathArray started")
|
||||
items = 4 # count
|
||||
centretrans = FreeCAD.Vector(0,0,0) # no translation
|
||||
#centretrans = FreeCAD.Vector(-5,-5,0) # translation
|
||||
orient = True # align to curve
|
||||
#orient = False # don't align to curve
|
||||
items = 4 # count
|
||||
centretrans = FreeCAD.Vector(0, 0, 0) # no translation
|
||||
# centretrans = FreeCAD.Vector(-5,-5,0) # translation
|
||||
orient = True # align to curve
|
||||
# orient = False # don't align to curve
|
||||
|
||||
s = FreeCADGui.Selection.getSelection()
|
||||
print("testPathArray: Objects in selection: ", len(s))
|
||||
@@ -48,7 +48,7 @@ base = s[0]
|
||||
path = s[1]
|
||||
pathsubs = []
|
||||
|
||||
#o = Draft.makePathArray(base,path,items) # test with defaults
|
||||
o = Draft.makePathArray(base,path,items,centretrans,orient,pathsubs) # test with non-defaults
|
||||
# o = Draft.makePathArray(base,path,items) # test with defaults
|
||||
o = Draft.makePathArray(base, path, items, centretrans, orient, pathsubs) # test with non-defaults
|
||||
|
||||
print("testPathArray ended")
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2013 WandererFan <wandererfan@gmail.com> *
|
||||
#* *
|
||||
#* 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 *
|
||||
#* *
|
||||
#***************************************************************************/
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2013 WandererFan <wandererfan@gmail.com> *
|
||||
# * *
|
||||
# * 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 *
|
||||
# * *
|
||||
# ***************************************************************************/
|
||||
|
||||
# Tester for Draft makePathArray - shapes on a path - with selected subobjects
|
||||
# Usage: in FC gui, select a "shape" document object (sphere, box, etc) (!select in
|
||||
@@ -33,20 +33,20 @@ import Part
|
||||
import Draft
|
||||
|
||||
print("testPathArray started")
|
||||
items = 4 # count
|
||||
centretrans = FreeCAD.Vector(0,0,0) # translation
|
||||
#centretrans = FreeCAD.Vector(10,10,10) # translation
|
||||
orient = True # align to curve
|
||||
#orient = False # don't align to curve
|
||||
items = 4 # count
|
||||
centretrans = FreeCAD.Vector(0, 0, 0) # translation
|
||||
# centretrans = FreeCAD.Vector(10,10,10) # translation
|
||||
orient = True # align to curve
|
||||
# orient = False # don't align to curve
|
||||
|
||||
# use this to test w/ path subelements
|
||||
s = FreeCADGui.Selection.getSelectionEx()
|
||||
for o in s:
|
||||
print("Selection: ", o.ObjectName)
|
||||
for name in o.SubElementNames:
|
||||
print(" name: ", name)
|
||||
for obj in o.SubObjects:
|
||||
print(" object: ",obj)
|
||||
print("Selection: ", o.ObjectName)
|
||||
for name in o.SubElementNames:
|
||||
print(" name: ", name)
|
||||
for obj in o.SubObjects:
|
||||
print(" object: ", obj)
|
||||
|
||||
print("testPathArray: Objects in selection: ", len(s))
|
||||
base = s[0].Object
|
||||
@@ -54,7 +54,9 @@ path = s[1].Object
|
||||
pathsubs = list(s[1].SubElementNames)
|
||||
print("testPathArray: pathsubs: ", pathsubs)
|
||||
|
||||
#o = Draft.makePathArray(base,path,items) # test with defaults
|
||||
o = Draft.makePathArray(base,path,items,centretrans,orient,pathsubs) # test w/o orienting shapes
|
||||
# o = Draft.makePathArray(base,path,items) # test with defaults
|
||||
o = Draft.makePathArray(
|
||||
base, path, items, centretrans, orient, pathsubs
|
||||
) # test w/o orienting shapes
|
||||
|
||||
print("testPathArray ended")
|
||||
|
||||
@@ -35,35 +35,35 @@ print("testWire started")
|
||||
# test strings
|
||||
# if string contains funky characters, it has to be declared as Unicode or it
|
||||
# turns into the default encoding (usually utf8). FT2 doesn't do utf8.
|
||||
#String = 'Wide WMA_' # wide glyphs for tracking
|
||||
#String = 'Big'
|
||||
#String = u'ecAnO' # UCS-2 w/ only ASCII
|
||||
#String = u'ucs2uéçÄñØ' # UCS-2
|
||||
#String = 'utf8!uéçÄñØ' # UTF-8
|
||||
#String = 'abcdefghijklmnopqrstuvwxyz0123456789'
|
||||
#String = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
#String = 'Big Daddy' # white space
|
||||
#String = 'AVWAIXA.V' # kerning
|
||||
String = 'FreeCAD' # ASCII
|
||||
# String = 'Wide WMA_' # wide glyphs for tracking
|
||||
# String = 'Big'
|
||||
# String = u'ecAnO' # UCS-2 w/ only ASCII
|
||||
# String = u'ucs2uéçÄñØ' # UCS-2
|
||||
# String = 'utf8!uéçÄñØ' # UTF-8
|
||||
# String = 'abcdefghijklmnopqrstuvwxyz0123456789'
|
||||
# String = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
# String = 'Big Daddy' # white space
|
||||
# String = 'AVWAIXA.V' # kerning
|
||||
String = "FreeCAD" # ASCII
|
||||
|
||||
#FontPath = '/usr/share/fonts/truetype/msttcorefonts/'
|
||||
#FontName = 'Times_New_Roman_Italic.ttf'
|
||||
FontPath = '/usr/share/fonts/truetype/msttcorefonts/'
|
||||
FontName = 'Arial.ttf'
|
||||
#FontName = 'NOTArial.ttf' # font file not found error
|
||||
#FontPath = '/usr/share/fonts/truetype/msttcorefonts/'
|
||||
#FontName = 'ariali.ttf' # symlink to ttf
|
||||
#FontPath = '/usr/share/fonts/truetype/'
|
||||
#FontName = 'Peterbuilt.ttf' # overlapping script font
|
||||
#FontPath = '/usr/share/fonts/truetype/'
|
||||
#FontName = 'dyspepsia.ttf' # overlapping script font # :)
|
||||
# FontPath = '/usr/share/fonts/truetype/msttcorefonts/'
|
||||
# FontName = 'Times_New_Roman_Italic.ttf'
|
||||
FontPath = "/usr/share/fonts/truetype/msttcorefonts/"
|
||||
FontName = "Arial.ttf"
|
||||
# FontName = 'NOTArial.ttf' # font file not found error
|
||||
# FontPath = '/usr/share/fonts/truetype/msttcorefonts/'
|
||||
# FontName = 'ariali.ttf' # symlink to ttf
|
||||
# FontPath = '/usr/share/fonts/truetype/'
|
||||
# FontName = 'Peterbuilt.ttf' # overlapping script font
|
||||
# FontPath = '/usr/share/fonts/truetype/'
|
||||
# FontName = 'dyspepsia.ttf' # overlapping script font # :)
|
||||
|
||||
Height = 2000 # out string height FCunits
|
||||
Track = 0 # intercharacter spacing
|
||||
Height = 2000 # out string height FCunits
|
||||
Track = 0 # intercharacter spacing
|
||||
|
||||
print("testWire.py input String contains ", len(String), " characters.")
|
||||
|
||||
s = Part.makeWireString(String,FontPath,FontName,Height,Track)
|
||||
s = Part.makeWireString(String, FontPath, FontName, Height, Track)
|
||||
|
||||
print("returned from makeWireString")
|
||||
print("testWire.py output contains ", len(s), " WireChars.")
|
||||
|
||||
Reference in New Issue
Block a user