diff --git a/src/Mod/Draft/CMakeLists.txt b/src/Mod/Draft/CMakeLists.txt index 37658b24c4..12857548f5 100644 --- a/src/Mod/Draft/CMakeLists.txt +++ b/src/Mod/Draft/CMakeLists.txt @@ -17,6 +17,7 @@ SET(Draft_SRCS_base WorkingPlane.py getSVG.py TestDraft.py + TestDraftGui.py ) SET(Draft_import diff --git a/src/Mod/Draft/InitGui.py b/src/Mod/Draft/InitGui.py index 252268ee01..1141e911dd 100644 --- a/src/Mod/Draft/InitGui.py +++ b/src/Mod/Draft/InitGui.py @@ -174,3 +174,5 @@ FreeCADGui.addPreferencePage(":/ui/preferences-dxf.ui", QT_TRANSLATE_NOOP("Draft FreeCADGui.addPreferencePage(":/ui/preferences-dwg.ui", QT_TRANSLATE_NOOP("Draft", "Import-Export")) FreeCADGui.addPreferencePage(":/ui/preferences-svg.ui", QT_TRANSLATE_NOOP("Draft", "Import-Export")) FreeCADGui.addPreferencePage(":/ui/preferences-oca.ui", QT_TRANSLATE_NOOP("Draft", "Import-Export")) + +FreeCAD.__unit_test__ += ["TestDraftGui"] diff --git a/src/Mod/Draft/TestDraft.py b/src/Mod/Draft/TestDraft.py index 092d436d45..d585a9fa75 100644 --- a/src/Mod/Draft/TestDraft.py +++ b/src/Mod/Draft/TestDraft.py @@ -21,7 +21,7 @@ # * USA * # * * # *************************************************************************** -"""Unit tests for the Draft workbench. +"""Unit tests for the Draft workbench, non-GUI only. From the terminal, run the following: FreeCAD -t TestDraft @@ -29,6 +29,8 @@ FreeCAD -t TestDraft From within FreeCAD, run the following: import Test, TestDraft Test.runTestsFromModule(TestDraft) + +For the GUI-only tests see TestDraftGui. """ # =========================================================================== @@ -94,20 +96,17 @@ Test.runTestsFromModule(TestDraft) # Import tests from drafttests.test_import import DraftImport as DraftTest01 -from drafttests.test_import_gui import DraftGuiImport as DraftTest02 -from drafttests.test_import_tools import DraftImportTools as DraftTest03 -from drafttests.test_pivy import DraftPivy as DraftTest04 # Objects tests -from drafttests.test_creation import DraftCreation as DraftTest05 -from drafttests.test_modification import DraftModification as DraftTest06 +from drafttests.test_creation import DraftCreation as DraftTest02 +from drafttests.test_modification import DraftModification as DraftTest03 # Handling of file formats tests -from drafttests.test_svg import DraftSVG as DraftTest07 -from drafttests.test_dxf import DraftDXF as DraftTest08 -from drafttests.test_dwg import DraftDWG as DraftTest09 -from drafttests.test_oca import DraftOCA as DraftTest10 -from drafttests.test_airfoildat import DraftAirfoilDAT as DraftTest11 +from drafttests.test_svg import DraftSVG as DraftTest04 +from drafttests.test_dxf import DraftDXF as DraftTest05 +from drafttests.test_dwg import DraftDWG as DraftTest06 +from drafttests.test_oca import DraftOCA as DraftTest07 +from drafttests.test_airfoildat import DraftAirfoilDAT as DraftTest08 # Use the modules so that code checkers don't complain (flake8) True if DraftTest01 else False @@ -118,6 +117,3 @@ True if DraftTest05 else False True if DraftTest06 else False True if DraftTest07 else False True if DraftTest08 else False -True if DraftTest09 else False -True if DraftTest10 else False -True if DraftTest11 else False diff --git a/src/Mod/Draft/TestDraftGui.py b/src/Mod/Draft/TestDraftGui.py new file mode 100644 index 0000000000..268a0502e2 --- /dev/null +++ b/src/Mod/Draft/TestDraftGui.py @@ -0,0 +1,105 @@ +# *************************************************************************** +# * Copyright (c) 2013 Yorik van Havre * +# * Copyright (c) 2020 Eliud Cabrera Castillo * +# * * +# * 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 * +# * * +# *************************************************************************** +"""Unit tests for the Draft workbench, GUI only. + +From the terminal, run the following: +FreeCAD -t TestDraftGui + +From within FreeCAD, run the following: +import Test, TestDraftGui +Test.runTestsFromModule(TestDraftGui) + +For the non-GUI tests see TestDraft. +""" + +# =========================================================================== +# The unit tests can be run from the operating system terminal, or from +# within FreeCAD itself. +# +# The tests can be run using the full 'FreeCAD' executable +# or the console only 'FreeCADCmd' executable. In the latter case +# some functions cannot be tested as the view providers (visual properties) +# are not available. +# +# =========================================================================== +# In the following, first the command to run the test from the operating +# system terminal is listed, followed by the commands to run the test +# from the Python console within FreeCAD. +# +# =========================================================================== +# Run all Draft tests +# ---- +# FreeCAD -t TestDraft +# +# >>> import Test, TestDraft +# >>> Test.runTestsFromModule(TestDraft) +# +# =========================================================================== +# Run tests from a specific module (all classes within this module) +# ---- +# FreeCAD -t drafttests.test_creation +# +# >>> import Test, drafttests.test_creation +# >>> Test.runTestsFromModule(drafttests.test_creation) +# +# =========================================================================== +# Run tests from a specific class within a module +# ---- +# FreeCAD -t drafttests.test_creation.DraftCreation +# +# >>> import Test, drafttests.test_creation +# >>> Test.runTestsFromClass(drafttests.test_creation.DraftCreation) +# +# =========================================================================== +# Run a specific unit test from a class within a module +# ---- +# FreeCAD -t drafttests.test_creation.DraftCreation.test_line +# +# >>> import unittest +# >>> one_test = "drafttests.test_creation.DraftCreation.test_line" +# >>> all_tests = unittest.TestLoader().loadTestsFromName(one_test) +# >>> unittest.TextTestRunner().run(all_tests) + +# =========================================================================== +# When the full test is run +# FreeCAD -t TestDraft +# +# all classes that are found in this file are run. +# +# We import the classes from submodules. These classes contain +# the actual unit tests. +# +# The classes will be run in alphabetical order. So, to force +# a particular order of testing we import them with a name +# that follows a defined alphanumeric sequence. + +# Import tests +from drafttests.test_import_gui import DraftGuiImport as DraftTestGui01 +from drafttests.test_import_tools import DraftImportTools as DraftTestGui02 +from drafttests.test_pivy import DraftPivy as DraftTestGui03 + +# Use the modules so that code checkers don't complain (flake8) +True if DraftTestGui01 else False +True if DraftTestGui02 else False +True if DraftTestGui03 else False diff --git a/src/Mod/Draft/drafttests/test_import_gui.py b/src/Mod/Draft/drafttests/test_import_gui.py index decec80ac7..5576f60826 100644 --- a/src/Mod/Draft/drafttests/test_import_gui.py +++ b/src/Mod/Draft/drafttests/test_import_gui.py @@ -24,7 +24,6 @@ """Unit test for the Draft Workbench, GUI import tests.""" import unittest -import FreeCAD as App import drafttests.auxiliary as aux @@ -39,39 +38,23 @@ class DraftGuiImport(unittest.TestCase): def test_import_gui_draftgui(self): """Import Draft TaskView GUI tools.""" module = "DraftGui" - if not App.GuiUp: - aux._no_gui(module) - self.assertTrue(True) - return imported = aux._import_test(module) self.assertTrue(imported, "Problem importing '{}'".format(module)) def test_import_gui_draft_snap(self): """Import Draft snapping.""" module = "draftguitools.gui_snapper" - if not App.GuiUp: - aux._no_gui(module) - self.assertTrue(True) - return imported = aux._import_test(module) self.assertTrue(imported, "Problem importing '{}'".format(module)) def test_import_gui_draft_tools(self): """Import Draft graphical commands.""" module = "DraftTools" - if not App.GuiUp: - aux._no_gui(module) - self.assertTrue(True) - return imported = aux._import_test(module) self.assertTrue(imported, "Problem importing '{}'".format(module)) def test_import_gui_draft_trackers(self): """Import Draft tracker utilities.""" module = "draftguitools.gui_trackers" - if not App.GuiUp: - aux._no_gui(module) - self.assertTrue(True) - return imported = aux._import_test(module) self.assertTrue(imported, "Problem importing '{}'".format(module)) diff --git a/src/Mod/Draft/drafttests/test_import_tools.py b/src/Mod/Draft/drafttests/test_import_tools.py index 1232da5ef0..5827f7a75b 100644 --- a/src/Mod/Draft/drafttests/test_import_tools.py +++ b/src/Mod/Draft/drafttests/test_import_tools.py @@ -24,7 +24,6 @@ """Unit test for the Draft Workbench, tools import tests.""" import unittest -import FreeCAD as App import drafttests.auxiliary as aux @@ -39,49 +38,29 @@ class DraftImportTools(unittest.TestCase): def test_import_gui_draftedit(self): """Import Draft Edit.""" module = "draftguitools.gui_edit" - if not App.GuiUp: - aux._no_gui(module) - self.assertTrue(True) - return imported = aux._import_test(module) self.assertTrue(imported, "Problem importing '{}'".format(module)) def test_import_gui_draftfillet(self): """Import Draft Fillet.""" module = "DraftFillet" - if not App.GuiUp: - aux._no_gui(module) - self.assertTrue(True) - return imported = aux._import_test(module) self.assertTrue(imported, "Problem importing '{}'".format(module)) def test_import_gui_draftlayer(self): """Import Draft Layer.""" module = "DraftLayer" - if not App.GuiUp: - aux._no_gui(module) - self.assertTrue(True) - return imported = aux._import_test(module) self.assertTrue(imported, "Problem importing '{}'".format(module)) def test_import_gui_draftplane(self): """Import Draft SelectPlane.""" module = "draftguitools.gui_selectplane" - if not App.GuiUp: - aux._no_gui(module) - self.assertTrue(True) - return imported = aux._import_test(module) self.assertTrue(imported, "Problem importing '{}'".format(module)) def test_import_gui_workingplane(self): """Import Draft WorkingPlane.""" module = "WorkingPlane" - if not App.GuiUp: - aux._no_gui(module) - self.assertTrue(True) - return imported = aux._import_test(module) self.assertTrue(imported, "Problem importing '{}'".format(module)) diff --git a/src/Mod/Draft/drafttests/test_pivy.py b/src/Mod/Draft/drafttests/test_pivy.py index 41d28908b5..c099b91d9a 100644 --- a/src/Mod/Draft/drafttests/test_pivy.py +++ b/src/Mod/Draft/drafttests/test_pivy.py @@ -25,6 +25,7 @@ import unittest import FreeCAD as App +import FreeCADGui as Gui import drafttests.auxiliary as aux from draftutils.messages import _msg @@ -52,22 +53,11 @@ class DraftPivy(unittest.TestCase): def test_pivy_import(self): """Import Coin (Pivy).""" module = "pivy.coin" - if not App.GuiUp: - aux._no_gui(module) - self.assertTrue(True) - return imported = aux._import_test(module) self.assertTrue(imported, "Problem importing '{}'".format(module)) def test_pivy_draw(self): """Use Coin (pivy.coin) to draw a cube on the active view.""" - module = "pivy.coin" - if not App.GuiUp: - aux._no_gui(module) - self.assertTrue(True) - return - - import FreeCADGui as Gui import pivy.coin as coin cube = coin.SoCube() _msg(" Draw cube")