BaseTests.py
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 import FreeCAD, os, unittest, tempfile
00026
00027 class ConsoleTestCase(unittest.TestCase):
00028 def setUp(self):
00029 self.count = 0
00030
00031 def testPrint(self):
00032 FreeCAD.Console.PrintMessage(" Printing message\n")
00033 FreeCAD.Console.PrintError(" Printing error\n")
00034 FreeCAD.Console.PrintWarning(" Printing warning\n")
00035 FreeCAD.Console.PrintLog(" Printing Log\n")
00036
00037 def testSynchronPrintFromThread(self):
00038 import thread, time
00039 def adder():
00040 lock.acquire()
00041 self.count=self.count+1
00042
00043 FreeCAD.Console.PrintMessage("Call from Python thread: count="+str(self.count)+"\n")
00044 lock.release()
00045
00046 lock=thread.allocate_lock()
00047 for i in range(10):
00048 thread.start_new(adder,())
00049
00050 time.sleep(3)
00051 self.failUnless(self.count==10,"Synchronization of threads failed")
00052 FreeCAD.Console.PrintMessage(str(self.count)+"\n")
00053
00054 def testAsynchronPrintFromThread(self):
00055 import thread, time
00056 def adder():
00057 self.count=self.count+1
00058
00059 FreeCAD.Console.PrintMessage("Call from Python thread (not synchronized): count="+str(self.count)+"\n")
00060
00061 lock=thread.allocate_lock()
00062 for i in range(10):
00063 thread.start_new(adder,())
00064
00065 time.sleep(3)
00066 FreeCAD.Console.PrintMessage(str(self.count)+"\n")
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 def tearDown(self):
00095 pass
00096
00097 class ParameterTestCase(unittest.TestCase):
00098 def setUp(self):
00099 self.TestPar = FreeCAD.ParamGet("System parameter:Test")
00100
00101 def testGroup(self):
00102
00103
00104 Temp = self.TestPar.GetGroup("44")
00105 self.failUnless(self.TestPar.HasGroup("44"),"Test on created group failed")
00106
00107 self.TestPar.RemGroup("44")
00108 self.failUnless(not self.TestPar.HasGroup("44"),"Test on delete group failed")
00109 Temp =0
00110
00111
00112 def testInt(self):
00113
00114
00115
00116 self.TestPar.SetInt("44",4711)
00117 self.failUnless(self.TestPar.GetInt("44") == 4711,"In and out error at Int")
00118
00119 self.TestPar.RemInt("44")
00120 self.failUnless(self.TestPar.GetInt("44",1) == 1,"Deletion error at Int")
00121
00122
00123 def testBool(self):
00124
00125
00126 self.TestPar.SetBool("44",1)
00127 self.failUnless(self.TestPar.GetBool("44") == 1,"In and out error at Bool")
00128
00129 self.TestPar.RemBool("44")
00130 self.failUnless(self.TestPar.GetBool("44",0) == 0,"Deletion error at Bool")
00131
00132 def testFloat(self):
00133
00134
00135
00136 self.TestPar.SetFloat("44",4711.4711)
00137 self.failUnless(self.TestPar.GetFloat("44") == 4711.4711,"In and out error at Float")
00138
00139 self.TestPar.RemFloat("44")
00140 self.failUnless(self.TestPar.GetFloat("44",1.1) == 1.1,"Deletion error at Float")
00141
00142 def testString(self):
00143
00144
00145
00146 self.TestPar.SetString("44","abcdefgh")
00147 self.failUnless(self.TestPar.GetString("44") == "abcdefgh","In and out error at String")
00148
00149 self.TestPar.RemString("44")
00150 self.failUnless(self.TestPar.GetString("44","hallo") == "hallo","Deletion error at String")
00151
00152 def testNesting(self):
00153
00154
00155 for i in range(50):
00156 self.TestPar.SetFloat(`i`,4711.4711)
00157 self.TestPar.SetInt(`i`,4711)
00158 self.TestPar.SetBool(`i`,1)
00159 Temp = self.TestPar.GetGroup(`i`)
00160 for l in range(50):
00161 Temp.SetFloat(`l`,4711.4711)
00162 Temp.SetInt(`l`,4711)
00163 Temp.SetBool(`l`,1)
00164 Temp = 0
00165
00166 def testExportImport(self):
00167
00168
00169 self.TestPar.SetFloat("ExTest",4711.4711)
00170 self.TestPar.SetInt("ExTest",4711)
00171 self.TestPar.SetString("ExTest","4711")
00172 self.TestPar.SetBool("ExTest",1)
00173 Temp = self.TestPar.GetGroup("ExTest")
00174 Temp.SetFloat("ExTest",4711.4711)
00175 Temp.SetInt("ExTest",4711)
00176 Temp.SetString("ExTest","4711")
00177 Temp.SetBool("ExTest",1)
00178 TempPath = tempfile.gettempdir() + os.sep + "ExportTest.FCExport"
00179
00180 self.TestPar.Export(TempPath)
00181 Temp = self.TestPar.GetGroup("ImportTest")
00182 Temp.Import(TempPath)
00183 self.failUnless(Temp.GetFloat("ExTest") == 4711.4711,"ExportImport error")
00184 Temp = 0
00185
00186 def tearDown(self):
00187
00188 TestPar = FreeCAD.ParamGet("System parameter:Test")
00189 TestPar.Clear()