2
# ***************************************************************************
3
# * Copyright (c) 2006 Werner Mayer <werner.wm.mayer@gmx.de> *
5
# * This file is part of the FreeCAD CAx development system. *
7
# * This program is free software; you can redistribute it and/or modify *
8
# * it under the terms of the GNU Lesser General Public License (LGPL) *
9
# * as published by the Free Software Foundation; either version 2 of *
10
# * the License, or (at your option) any later version. *
11
# * for detail see the LICENCE text file. *
13
# * FreeCAD is distributed in the hope that it will be useful, *
14
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
# * GNU Library General Public License for more details. *
18
# * You should have received a copy of the GNU Library General Public *
19
# * License along with FreeCAD; if not, write to the Free Software *
20
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
23
# ***************************************************************************/
25
# Workbench test module
27
import FreeCAD, FreeCADGui, os, unittest
30
from PySide import QtWidgets, QtCore
31
from PySide.QtWidgets import QApplication
34
class CallableCheckWarning:
36
diag = QApplication.activeModalWidget()
38
QtCore.QTimer.singleShot(0, diag, QtCore.SLOT("accept()"))
41
class WorkbenchTestCase(unittest.TestCase):
43
self.Active = FreeCADGui.activeWorkbench()
44
FreeCAD.Console.PrintLog(FreeCADGui.activeWorkbench().name())
46
def testActivate(self):
47
wbs = FreeCADGui.listWorkbenches()
48
# this gives workbenches a possibility to detect that we're under test environment
49
FreeCAD.TestEnvironment = True
52
print("Activate workbench '{}'".format(i))
53
cobj = CallableCheckWarning()
54
QtCore.QTimer.singleShot(500, cobj)
55
if FreeCADGui.activeWorkbench().name() != i:
56
success = FreeCADGui.activateWorkbench(i)
58
# Cannot test activation of an already-active workbench
60
FreeCAD.Console.PrintLog(
61
"Active: " + FreeCADGui.activeWorkbench().name() + " Expected: " + i + "\n"
63
self.assertTrue(success, "Test on activating workbench {0} failed".format(i))
64
except Exception as e:
65
self.fail("Loading of workbench '{0}' failed: {1}".format(i, e))
66
del FreeCAD.TestEnvironment
68
def testHandler(self):
71
class UnitWorkbench(__main__.Workbench):
77
self.appendToolbar("My Unittest", cmds)
79
def GetClassName(self):
80
return "Gui::PythonWorkbench"
82
FreeCADGui.addWorkbench(UnitWorkbench())
83
wbs = FreeCADGui.listWorkbenches()
84
self.assertTrue("UnitWorkbench" in wbs, "Test on adding workbench handler failed")
85
FreeCADGui.activateWorkbench("UnitWorkbench")
86
FreeCADGui.updateGui()
88
FreeCADGui.activeWorkbench().name() == "UnitWorkbench",
89
"Test on loading workbench 'Unittest' failed",
91
FreeCADGui.removeWorkbench("UnitWorkbench")
92
wbs = FreeCADGui.listWorkbenches()
93
self.assertTrue(not "UnitWorkbench" in wbs, "Test on removing workbench handler failed")
95
def testInvalidType(self):
96
class MyExtWorkbench(FreeCADGui.Workbench):
100
def GetClassName(self):
101
return "App::Extension"
103
FreeCADGui.addWorkbench(MyExtWorkbench())
104
with self.assertRaises(TypeError):
105
FreeCADGui.activateWorkbench("MyExtWorkbench")
106
FreeCADGui.removeWorkbench("MyExtWorkbench")
109
FreeCADGui.activateWorkbench(self.Active.name())
110
FreeCAD.Console.PrintLog(self.Active.name())
113
class CommandTestCase(unittest.TestCase):
114
def testPR6889(self):
116
TempPath = tempfile.gettempdir()
117
macroName = TempPath + os.sep + "testmacro.py"
118
macroFile = open(macroName, "w")
119
macroFile.write("print ('Hello, World!')")
122
name = FreeCADGui.Command.createCustomCommand(macroName)
123
cmd = FreeCADGui.Command.get(name)
127
class TestNavigationStyle(unittest.TestCase):
129
self.Doc = FreeCAD.newDocument("CreateTest")
131
def testInvalidStyle(self):
132
FreeCADGui.getDocument(self.Doc).ActiveView.setNavigationType("App::Extension")
134
FreeCADGui.getDocument(self.Doc).ActiveView.getNavigationType(), "App::Extension"
138
FreeCAD.closeDocument("CreateTest")