Test: apply clang format

This commit is contained in:
wmayer
2023-09-03 18:14:40 +02:00
committed by Chris Hennes
parent 19a1204a5a
commit e48964fad5
23 changed files with 3065 additions and 2745 deletions

View File

@@ -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")