From fc9e19aafbb9323174db01e28c2d4e1858b52075 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 24 May 2022 14:17:44 +0200 Subject: [PATCH] Test: [skip ci] add unit tests for PR #6907 --- src/Gui/ApplicationPy.cpp | 2 +- src/Mod/Test/Document.py | 7 +++++++ src/Mod/Test/Workbench.py | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index 8d9c7ee88a..7d79cf13b2 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -1007,7 +1007,7 @@ PyObject* Application::sActivateWorkbenchHandler(PyObject * /*self*/, PyObject * catch (const Base::Exception& e) { std::stringstream err; err << psKey << ": " << e.what(); - PyErr_SetString(Base::PyExc_FC_GeneralError, err.str().c_str()); + PyErr_SetString(e.getPyExceptionType(), err.str().c_str()); return nullptr; } catch (const XERCES_CPP_NAMESPACE_QUALIFIER TranscodingException& e) { diff --git a/src/Mod/Test/Document.py b/src/Mod/Test/Document.py index 904aea809a..3cf2eadf28 100644 --- a/src/Mod/Test/Document.py +++ b/src/Mod/Test/Document.py @@ -222,6 +222,13 @@ class DocumentBasicCases(unittest.TestCase): with self.assertRaises(TypeError): self.Doc.findObjects(Type="App::DocumentObjectExtension") + e = FreeCAD.Base.TypeId.fromName("App::LinkExtensionPython") + self.assertIsNone(e.createInstance()) + + if FreeCAD.GuiUp: + obj = self.Doc.addObject("App::DocumentObject", viewType="App::Extension") + self.assertIsNone(obj.ViewObject) + def testMem(self): self.Doc.MemSize diff --git a/src/Mod/Test/Workbench.py b/src/Mod/Test/Workbench.py index 9b9d83a0b4..1de081600a 100755 --- a/src/Mod/Test/Workbench.py +++ b/src/Mod/Test/Workbench.py @@ -77,6 +77,18 @@ class WorkbenchTestCase(unittest.TestCase): 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" + + 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()) @@ -93,3 +105,14 @@ class CommandTestCase(unittest.TestCase): 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")