Core: GuiDocument testGetTreeRootObject

This commit is contained in:
PaddleStroke
2024-06-11 16:57:05 +02:00
parent fb32579498
commit d291fd3e16
3 changed files with 65 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ SET(Test_SRCS
Init.py
BaseTests.py
Document.py
GuiDocument.py
Metadata.py
StringHasher.py
Menu.py

View File

@@ -0,0 +1,57 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
"""**************************************************************************
* *
* Copyright (c) 2024 Ondsel <development@ondsel.com> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
***************************************************************************/"""
import FreeCAD, FreeCADGui, unittest
# ---------------------------------------------------------------------------
# define the functions to test the FreeCAD Gui Document code
# ---------------------------------------------------------------------------
class TestGuiDocument(unittest.TestCase):
def setUp(self):
# Create a new document
self.doc = FreeCAD.newDocument("TestDoc")
def tearDown(self):
# Close the document
FreeCAD.closeDocument("TestDoc")
def testGetTreeRootObject(self):
# Create objects at the root level
group1 = self.doc.addObject("App::DocumentObjectGroup", "Group1")
group2 = self.doc.addObject("App::DocumentObjectGroup", "Group2")
obj1 = self.doc.addObject("App::FeaturePython", "RootObject1")
part1 = self.doc.addObject("App::Part", "Part1")
# Create App::Parts and groups with objects in them
part1_obj = part1.newObject("App::FeaturePython", "Part1_Object")
group3 = group2.newObject("App::DocumentObjectGroup", "Group1")
group1_obj = group3.newObject("App::FeaturePython", "Group1_Object")
# Fetch the root objects using getTreeRootObjects
root_objects = FreeCADGui.getDocument("TestDoc").TreeRootObjects
# Check if the new function returns the correct root objects
expected_root_objects = [group1, group2, obj1, part1]
self.assertEqual(set(root_objects), set(expected_root_objects))

View File

@@ -92,4 +92,10 @@ class TestWorkbench(Workbench):
Gui.addWorkbench(TestWorkbench())
# Base system tests
FreeCAD.__unit_test__ += ["Workbench", "Menu", "Menu.MenuDeleteCases", "Menu.MenuCreateCases"]
FreeCAD.__unit_test__ += [
"Workbench",
"Menu",
"Menu.MenuDeleteCases",
"Menu.MenuCreateCases",
"GuiDocument",
]