Draft: cleanup of unit tests code

This commit is contained in:
vocx-fc
2020-02-04 22:29:02 -06:00
committed by Yorik van Havre
parent efd5367d94
commit 422d5f9d1f
12 changed files with 96 additions and 125 deletions

View File

@@ -1,5 +1,3 @@
"""Auxiliary functions for the unit tests of the Draft Workbench.
"""
# ***************************************************************************
# * Copyright (c) 2013 Yorik van Havre <yorik@uncreated.net> *
# * Copyright (c) 2019 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
@@ -23,38 +21,32 @@
# * USA *
# * *
# ***************************************************************************
"""Auxiliary functions for the unit tests of the Draft Workbench."""
import FreeCAD as App
def _msg(text, end="\n"):
App.Console.PrintMessage(text + end)
def _wrn(text, end="\n"):
App.Console.PrintWarning(text + end)
def _log(text, end="\n"):
App.Console.PrintLog(text + end)
import traceback
from draftutils.messages import _msg
def _draw_header():
"""Draw a header for the tests."""
_msg("")
_msg(78*"-")
def _import_test(module):
"""Try importing a module."""
_msg(" Try importing '{}'".format(module))
try:
imported = __import__("{}".format(module))
except ImportError as exc:
imported = False
_msg(" {}".format(exc))
_msg(traceback.format_exc())
return imported
def _no_gui(module):
"""Print a message that there is no user interface."""
_msg(" #-----------------------------------------------------#\n"
" # No GUI; cannot test for '{}'\n"
" #-----------------------------------------------------#\n"
@@ -62,6 +54,7 @@ def _no_gui(module):
def _no_test():
"""Print a message that the test is not currently implemented."""
_msg(" #-----------------------------------------------------#\n"
" # This test is not implemented currently\n"
" #-----------------------------------------------------#\n"
@@ -69,6 +62,7 @@ def _no_test():
def _fake_function(p1=None, p2=None, p3=None, p4=None, p5=None):
"""Print a message for a test that doesn't actually exist."""
_msg(" Arguments to placeholder function")
_msg(" p1={0}; p2={1}".format(p1, p2))
_msg(" p3={0}; p4={1}".format(p3, p4))

View File

@@ -1,5 +1,3 @@
"""Unit test for the Draft module, Airfoil DAT import and export tests.
"""
# ***************************************************************************
# * Copyright (c) 2013 Yorik van Havre <yorik@uncreated.net> *
# * Copyright (c) 2019 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
@@ -23,14 +21,14 @@
# * USA *
# * *
# ***************************************************************************
"""Unit test for the Draft Workbench, Airfoil DAT import and export tests."""
import os
import unittest
import FreeCAD as App
import Draft
from .auxiliary import _msg
from .auxiliary import _draw_header
from .auxiliary import _fake_function
import drafttests.auxiliary as aux
from draftutils.messages import _msg
class DraftAirfoilDAT(unittest.TestCase):
@@ -42,7 +40,7 @@ class DraftAirfoilDAT(unittest.TestCase):
This is executed before every test, so we create a document
to hold the objects.
"""
_draw_header()
aux._draw_header()
self.doc_name = self.__class__.__name__
if App.ActiveDocument:
if App.ActiveDocument.Name != self.doc_name:
@@ -64,7 +62,7 @@ class DraftAirfoilDAT(unittest.TestCase):
_msg(" file={}".format(in_file))
_msg(" exists={}".format(os.path.exists(in_file)))
Draft.import_AirfoilDAT = _fake_function
Draft.import_AirfoilDAT = aux._fake_function
obj = Draft.import_AirfoilDAT(in_file)
self.assertTrue(obj, "'{}' failed".format(operation))
@@ -78,7 +76,7 @@ class DraftAirfoilDAT(unittest.TestCase):
_msg(" file={}".format(out_file))
_msg(" exists={}".format(os.path.exists(out_file)))
Draft.export_importAirfoilDAT = _fake_function
Draft.export_importAirfoilDAT = aux._fake_function
obj = Draft.export_importAirfoilDAT(out_file)
self.assertTrue(obj, "'{}' failed".format(operation))

View File

@@ -1,5 +1,3 @@
"""Unit test for the Draft module, object creation tests.
"""
# ***************************************************************************
# * Copyright (c) 2013 Yorik van Havre <yorik@uncreated.net> *
# * Copyright (c) 2019 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
@@ -23,15 +21,14 @@
# * USA *
# * *
# ***************************************************************************
"""Unit test for the Draft Workbench, object creation tests."""
import unittest
import FreeCAD as App
import Draft
import drafttests.auxiliary as aux
from FreeCAD import Vector
from .auxiliary import _msg
from .auxiliary import _draw_header
from .auxiliary import _no_gui
from .auxiliary import _fake_function
from draftutils.messages import _msg
class DraftCreation(unittest.TestCase):
@@ -43,7 +40,7 @@ class DraftCreation(unittest.TestCase):
This is executed before every test, so we create a document
to hold the objects.
"""
_draw_header()
aux._draw_header()
self.doc_name = self.__class__.__name__
if App.ActiveDocument:
if App.ActiveDocument.Name != self.doc_name:
@@ -91,7 +88,7 @@ class DraftCreation(unittest.TestCase):
App.ActiveDocument.recompute()
if not App.GuiUp:
_no_gui("DraftFillet")
aux._no_gui("DraftFillet")
self.assertTrue(True)
return
@@ -200,7 +197,7 @@ class DraftCreation(unittest.TestCase):
c = Vector(0, 5, 0)
_msg(" a={0}, b={1}".format(a, b))
_msg(" c={}".format(c))
Draft.make_dimension_radial = _fake_function
Draft.make_dimension_radial = aux._fake_function
obj = Draft.make_dimension_radial(a, b, c)
self.assertTrue(obj, "'{}' failed".format(operation))
@@ -231,9 +228,10 @@ class DraftCreation(unittest.TestCase):
_msg(" Test '{}'".format(operation))
_msg(" In order to test this, a font file is needed.")
text = "Testing Shapestring "
font = None # TODO: get a font file here
# TODO: find a reliable way to always get a font file here
font = None
_msg(" text='{0}', font='{1}'".format(text, font))
Draft.makeShapeString = _fake_function
Draft.makeShapeString = aux._fake_function
obj = Draft.makeShapeString("Text", font)
# Draft.makeShapeString("Text", FontFile="")
self.assertTrue(obj, "'{}' failed".format(operation))

View File

@@ -1,5 +1,3 @@
"""Unit test for the Draft module, DWG import and export tests.
"""
# ***************************************************************************
# * Copyright (c) 2013 Yorik van Havre <yorik@uncreated.net> *
# * Copyright (c) 2019 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
@@ -23,14 +21,14 @@
# * USA *
# * *
# ***************************************************************************
"""Unit test for the Draft Workbench, DWG import and export tests."""
import os
import unittest
import FreeCAD as App
import Draft
from .auxiliary import _msg
from .auxiliary import _draw_header
from .auxiliary import _fake_function
import drafttests.auxiliary as aux
from draftutils.messages import _msg
class DraftDWG(unittest.TestCase):
@@ -42,7 +40,7 @@ class DraftDWG(unittest.TestCase):
This is executed before every test, so we create a document
to hold the objects.
"""
_draw_header()
aux._draw_header()
self.doc_name = self.__class__.__name__
if App.ActiveDocument:
if App.ActiveDocument.Name != self.doc_name:
@@ -64,7 +62,7 @@ class DraftDWG(unittest.TestCase):
_msg(" file={}".format(in_file))
_msg(" exists={}".format(os.path.exists(in_file)))
Draft.import_DWG = _fake_function
Draft.import_DWG = aux._fake_function
obj = Draft.import_DWG(in_file)
self.assertTrue(obj, "'{}' failed".format(operation))
@@ -78,7 +76,7 @@ class DraftDWG(unittest.TestCase):
_msg(" file={}".format(out_file))
_msg(" exists={}".format(os.path.exists(out_file)))
Draft.export_DWG = _fake_function
Draft.export_DWG = aux._fake_function
obj = Draft.export_DWG(out_file)
self.assertTrue(obj, "'{}' failed".format(operation))

View File

@@ -1,5 +1,3 @@
"""Unit test for the Draft module, DXF import and export tests.
"""
# ***************************************************************************
# * Copyright (c) 2013 Yorik van Havre <yorik@uncreated.net> *
# * Copyright (c) 2019 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
@@ -23,14 +21,14 @@
# * USA *
# * *
# ***************************************************************************
"""Unit test for the Draft Workbench, DXF import and export tests."""
import os
import unittest
import FreeCAD as App
import Draft
from .auxiliary import _msg
from .auxiliary import _draw_header
from .auxiliary import _fake_function
import drafttests.auxiliary as aux
from draftutils.messages import _msg
class DraftDXF(unittest.TestCase):
@@ -42,7 +40,7 @@ class DraftDXF(unittest.TestCase):
This is executed before every test, so we create a document
to hold the objects.
"""
_draw_header()
aux._draw_header()
self.doc_name = self.__class__.__name__
if App.ActiveDocument:
if App.ActiveDocument.Name != self.doc_name:
@@ -64,7 +62,7 @@ class DraftDXF(unittest.TestCase):
_msg(" file={}".format(in_file))
_msg(" exists={}".format(os.path.exists(in_file)))
Draft.import_DXF = _fake_function
Draft.import_DXF = aux._fake_function
obj = Draft.import_DXF(in_file)
self.assertTrue(obj, "'{}' failed".format(operation))
@@ -78,7 +76,7 @@ class DraftDXF(unittest.TestCase):
_msg(" file={}".format(out_file))
_msg(" exists={}".format(os.path.exists(out_file)))
Draft.export_DXF = _fake_function
Draft.export_DXF = aux._fake_function
obj = Draft.export_DXF(out_file)
self.assertTrue(obj, "'{}' failed".format(operation))

View File

@@ -1,5 +1,3 @@
"""Unit test for the Draft module, import tests.
"""
# ***************************************************************************
# * Copyright (c) 2013 Yorik van Havre <yorik@uncreated.net> *
# * Copyright (c) 2019 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
@@ -23,39 +21,40 @@
# * USA *
# * *
# ***************************************************************************
"""Unit test for the Draft Workbench, import tests."""
import unittest
from .auxiliary import _draw_header
from .auxiliary import _import_test
import drafttests.auxiliary as aux
class DraftImport(unittest.TestCase):
"""Import the Draft modules."""
# No document is needed to test 'import Draft' or other modules
# thus 'setUp' just draws a line, and 'tearDown' isn't defined.
def setUp(self):
_draw_header()
aux._draw_header()
def test_import_draft(self):
"""Import the Draft module."""
module = "Draft"
imported = _import_test(module)
imported = aux._import_test(module)
self.assertTrue(imported, "Problem importing '{}'".format(module))
def test_import_draft_geomutils(self):
"""Import Draft geometrical utilities."""
module = "DraftGeomUtils"
imported = _import_test(module)
imported = aux._import_test(module)
self.assertTrue(imported, "Problem importing '{}'".format(module))
def test_import_draft_vecutils(self):
"""Import Draft vector utilities."""
module = "DraftVecUtils"
imported = _import_test(module)
imported = aux._import_test(module)
self.assertTrue(imported, "Problem importing '{}'".format(module))
def test_import_draft_svg(self):
"""Import Draft SVG utilities."""
module = "getSVG"
imported = _import_test(module)
imported = aux._import_test(module)
self.assertTrue(imported, "Problem importing '{}'".format(module))

View File

@@ -1,5 +1,3 @@
"""Unit test for the Draft module, GUI import tests.
"""
# ***************************************************************************
# * Copyright (c) 2013 Yorik van Havre <yorik@uncreated.net> *
# * Copyright (c) 2019 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
@@ -23,57 +21,57 @@
# * USA *
# * *
# ***************************************************************************
"""Unit test for the Draft Workbench, GUI import tests."""
import unittest
import FreeCAD as App
from .auxiliary import _draw_header
from .auxiliary import _no_gui
from .auxiliary import _import_test
import drafttests.auxiliary as aux
class DraftGuiImport(unittest.TestCase):
"""Import the Draft graphical modules."""
# No document is needed to test 'import DraftGui' or other modules
# thus 'setUp' just draws a line, and 'tearDown' isn't defined.
def setUp(self):
_draw_header()
aux._draw_header()
def test_import_gui_draftgui(self):
"""Import Draft TaskView GUI tools."""
module = "DraftGui"
if not App.GuiUp:
_no_gui(module)
aux._no_gui(module)
self.assertTrue(True)
return
imported = _import_test(module)
imported = aux._import_test(module)
self.assertTrue(imported, "Problem importing '{}'".format(module))
def test_import_gui_draft_snap(self):
"""Import Draft snapping."""
module = "DraftSnap"
if not App.GuiUp:
_no_gui(module)
aux._no_gui(module)
self.assertTrue(True)
return
imported = _import_test(module)
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:
_no_gui(module)
aux._no_gui(module)
self.assertTrue(True)
return
imported = _import_test(module)
imported = aux._import_test(module)
self.assertTrue(imported, "Problem importing '{}'".format(module))
def test_import_gui_draft_trackers(self):
"""Import Draft tracker utilities."""
module = "DraftTrackers"
if not App.GuiUp:
_no_gui(module)
aux._no_gui(module)
self.assertTrue(True)
return
imported = _import_test(module)
imported = aux._import_test(module)
self.assertTrue(imported, "Problem importing '{}'".format(module))

View File

@@ -1,5 +1,3 @@
"""Unit test for the Draft module, tools import tests.
"""
# ***************************************************************************
# * Copyright (c) 2013 Yorik van Havre <yorik@uncreated.net> *
# * Copyright (c) 2019 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
@@ -23,67 +21,67 @@
# * USA *
# * *
# ***************************************************************************
"""Unit test for the Draft Workbench, tools import tests."""
import unittest
import FreeCAD as App
from .auxiliary import _draw_header
from .auxiliary import _no_gui
from .auxiliary import _import_test
import drafttests.auxiliary as aux
class DraftImportTools(unittest.TestCase):
"""Test for each individual module that defines a tool."""
# No document is needed to test 'import' of other modules
# thus 'setUp' just draws a line, and 'tearDown' isn't defined.
def setUp(self):
_draw_header()
aux._draw_header()
def test_import_gui_draftedit(self):
"""Import Draft Edit."""
module = "DraftEdit"
if not App.GuiUp:
_no_gui(module)
aux._no_gui(module)
self.assertTrue(True)
return
imported = _import_test(module)
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:
_no_gui(module)
aux._no_gui(module)
self.assertTrue(True)
return
imported = _import_test(module)
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:
_no_gui(module)
aux._no_gui(module)
self.assertTrue(True)
return
imported = _import_test(module)
imported = aux._import_test(module)
self.assertTrue(imported, "Problem importing '{}'".format(module))
def test_import_gui_draftplane(self):
"""Import Draft SelectPlane."""
module = "DraftSelectPlane"
if not App.GuiUp:
_no_gui(module)
aux._no_gui(module)
self.assertTrue(True)
return
imported = _import_test(module)
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:
_no_gui(module)
aux._no_gui(module)
self.assertTrue(True)
return
imported = _import_test(module)
imported = aux._import_test(module)
self.assertTrue(imported, "Problem importing '{}'".format(module))

View File

@@ -1,5 +1,3 @@
"""Unit test for the Draft module, object modification tests.
"""
# ***************************************************************************
# * Copyright (c) 2013 Yorik van Havre <yorik@uncreated.net> *
# * Copyright (c) 2019 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
@@ -23,15 +21,14 @@
# * USA *
# * *
# ***************************************************************************
"""Unit test for the Draft Workbench, object modification tests."""
import unittest
import FreeCAD as App
import Draft
import drafttests.auxiliary as aux
from FreeCAD import Vector
from .auxiliary import _msg
from .auxiliary import _wrn
from .auxiliary import _draw_header
from .auxiliary import _fake_function
from draftutils.messages import _msg, _wrn
class DraftModification(unittest.TestCase):
@@ -43,7 +40,7 @@ class DraftModification(unittest.TestCase):
This is executed before every test, so we create a document
to hold the objects.
"""
_draw_header()
aux._draw_header()
self.doc_name = self.__class__.__name__
if App.ActiveDocument:
if App.ActiveDocument.Name != self.doc_name:
@@ -160,7 +157,7 @@ class DraftModification(unittest.TestCase):
line2 = Draft.makeLine(c, d)
App.ActiveDocument.recompute()
Draft.trim_objects = _fake_function
Draft.trim_objects = aux._fake_function
obj = Draft.trim_objects(line, line2)
self.assertTrue(obj, "'{}' failed".format(operation))
@@ -181,7 +178,7 @@ class DraftModification(unittest.TestCase):
line2 = Draft.makeLine(c, d)
App.ActiveDocument.recompute()
Draft.extrude = _fake_function
Draft.extrude = aux._fake_function
obj = Draft.extrude(line, line2)
self.assertTrue(obj, "'{}' failed".format(operation))
@@ -577,7 +574,7 @@ class DraftModification(unittest.TestCase):
line = Draft.makeLine(a, b)
direction = Vector(4, 1, 0)
Draft.stretch = _fake_function
Draft.stretch = aux._fake_function
obj = Draft.stretch(line, direction)
self.assertTrue(obj, "'{}' failed".format(operation))

View File

@@ -1,5 +1,3 @@
"""Unit test for the Draft module, OCA import and export tests.
"""
# ***************************************************************************
# * Copyright (c) 2013 Yorik van Havre <yorik@uncreated.net> *
# * Copyright (c) 2019 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
@@ -23,14 +21,14 @@
# * USA *
# * *
# ***************************************************************************
"""Unit test for the Draft Workbench, OCA import and export tests."""
import os
import unittest
import FreeCAD as App
import Draft
from .auxiliary import _msg
from .auxiliary import _draw_header
from .auxiliary import _fake_function
import drafttests.auxiliary as aux
from draftutils.messages import _msg
class DraftOCA(unittest.TestCase):
@@ -42,7 +40,7 @@ class DraftOCA(unittest.TestCase):
This is executed before every test, so we create a document
to hold the objects.
"""
_draw_header()
aux._draw_header()
self.doc_name = self.__class__.__name__
if App.ActiveDocument:
if App.ActiveDocument.Name != self.doc_name:
@@ -64,7 +62,7 @@ class DraftOCA(unittest.TestCase):
_msg(" file={}".format(in_file))
_msg(" exists={}".format(os.path.exists(in_file)))
Draft.import_OCA = _fake_function
Draft.import_OCA = aux._fake_function
obj = Draft.import_OCA(in_file)
self.assertTrue(obj, "'{}' failed".format(operation))
@@ -78,7 +76,7 @@ class DraftOCA(unittest.TestCase):
_msg(" file={}".format(out_file))
_msg(" exists={}".format(os.path.exists(out_file)))
Draft.export_OCA = _fake_function
Draft.export_OCA = aux._fake_function
obj = Draft.export_OCA(out_file)
self.assertTrue(obj, "'{}' failed".format(operation))

View File

@@ -1,5 +1,3 @@
"""Unit test for the Draft module, Pivy (Coin) tests.
"""
# ***************************************************************************
# * Copyright (c) 2013 Yorik van Havre <yorik@uncreated.net> *
# * Copyright (c) 2019 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
@@ -23,14 +21,13 @@
# * USA *
# * *
# ***************************************************************************
"""Unit test for the Draft Workbench, Coin (Pivy) tests."""
import unittest
import FreeCAD as App
import FreeCADGui as Gui
from .auxiliary import _msg
from .auxiliary import _draw_header
from .auxiliary import _no_gui
from .auxiliary import _import_test
import drafttests.auxiliary as aux
from draftutils.messages import _msg
class DraftPivy(unittest.TestCase):
@@ -42,7 +39,7 @@ class DraftPivy(unittest.TestCase):
This is executed before every test, so we create a document
to hold the objects.
"""
_draw_header()
aux._draw_header()
self.doc_name = self.__class__.__name__
if App.ActiveDocument:
if App.ActiveDocument.Name != self.doc_name:
@@ -54,16 +51,16 @@ class DraftPivy(unittest.TestCase):
_msg(" Temporary document '{}'".format(self.doc_name))
def test_pivy_import(self):
"""Import Pivy Coin."""
"""Import Coin (Pivy)."""
module = "pivy.coin"
imported = _import_test(module)
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:
_no_gui(module)
aux._no_gui(module)
self.assertTrue(True)
return

View File

@@ -1,5 +1,3 @@
"""Unit test for the Draft module, SVG import and export tests.
"""
# ***************************************************************************
# * Copyright (c) 2013 Yorik van Havre <yorik@uncreated.net> *
# * Copyright (c) 2019 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
@@ -23,14 +21,14 @@
# * USA *
# * *
# ***************************************************************************
"""Unit test for the Draft Workbench, SVG import and export tests."""
import os
import unittest
import FreeCAD as App
import Draft
from .auxiliary import _msg
from .auxiliary import _draw_header
from .auxiliary import _fake_function
import drafttests.auxiliary as aux
from draftutils.messages import _msg
class DraftSVG(unittest.TestCase):
@@ -42,7 +40,7 @@ class DraftSVG(unittest.TestCase):
This is executed before every test, so we create a document
to hold the objects.
"""
_draw_header()
aux._draw_header()
self.doc_name = self.__class__.__name__
if App.ActiveDocument:
if App.ActiveDocument.Name != self.doc_name:
@@ -64,7 +62,7 @@ class DraftSVG(unittest.TestCase):
_msg(" file={}".format(in_file))
_msg(" exists={}".format(os.path.exists(in_file)))
Draft.import_SVG = _fake_function
Draft.import_SVG = aux._fake_function
obj = Draft.import_SVG(in_file)
self.assertTrue(obj, "'{}' failed".format(operation))
@@ -78,7 +76,7 @@ class DraftSVG(unittest.TestCase):
_msg(" file={}".format(out_file))
_msg(" exists={}".format(os.path.exists(out_file)))
Draft.export_SVG = _fake_function
Draft.export_SVG = aux._fake_function
obj = Draft.export_SVG(out_file)
self.assertTrue(obj, "'{}' failed".format(operation))