| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | import FreeCAD, FreeCADGui, os, unittest
|
| | 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()"))
|
| |
|
| |
|
| | class WorkbenchTestCase(unittest.TestCase):
|
| | def setUp(self):
|
| | self.Active = FreeCADGui.activeWorkbench()
|
| | FreeCAD.Console.PrintLog(FreeCADGui.activeWorkbench().name())
|
| |
|
| | def testActivate(self):
|
| | wbs = FreeCADGui.listWorkbenches()
|
| |
|
| | FreeCAD.TestEnvironment = True
|
| | for i in wbs:
|
| | try:
|
| | print("Activate workbench '{}'".format(i))
|
| | cobj = CallableCheckWarning()
|
| | QtCore.QTimer.singleShot(500, cobj)
|
| | if FreeCADGui.activeWorkbench().name() != i:
|
| | success = FreeCADGui.activateWorkbench(i)
|
| | else:
|
| |
|
| | success = True
|
| | 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)
|
| |
|
| | def GetClassName(self):
|
| | return "Gui::PythonWorkbench"
|
| |
|
| | FreeCADGui.addWorkbench(UnitWorkbench())
|
| | wbs = FreeCADGui.listWorkbenches()
|
| | self.assertTrue("UnitWorkbench" in wbs, "Test on adding workbench handler failed")
|
| | FreeCADGui.activateWorkbench("UnitWorkbench")
|
| | FreeCADGui.updateGui()
|
| | self.assertTrue(
|
| | FreeCADGui.activeWorkbench().name() == "UnitWorkbench",
|
| | "Test on loading workbench 'Unittest' failed",
|
| | )
|
| | FreeCADGui.removeWorkbench("UnitWorkbench")
|
| | wbs = FreeCADGui.listWorkbenches()
|
| | self.assertTrue(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"
|
| |
|
| | FreeCADGui.addWorkbench(MyExtWorkbench())
|
| | with self.assertRaises(TypeError):
|
| | FreeCADGui.activateWorkbench("MyExtWorkbench")
|
| | FreeCADGui.removeWorkbench("MyExtWorkbench")
|
| |
|
| | def tearDown(self):
|
| | FreeCADGui.activateWorkbench(self.Active.name())
|
| | FreeCAD.Console.PrintLog(self.Active.name())
|
| |
|
| |
|
| | class CommandTestCase(unittest.TestCase):
|
| | def testPR6889(self):
|
| |
|
| | TempPath = tempfile.gettempdir()
|
| | macroName = TempPath + os.sep + "testmacro.py"
|
| | macroFile = open(macroName, "w")
|
| | macroFile.write("print ('Hello, World!')")
|
| | macroFile.close()
|
| |
|
| | name = FreeCADGui.Command.createCustomCommand(macroName)
|
| | 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"
|
| | )
|
| |
|
| | def tearDown(self):
|
| | FreeCAD.closeDocument("CreateTest")
|
| |
|