From 7805dce66e32b4f5134d5897a6c4218154446578 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Sun, 22 Jan 2017 19:12:06 -0800 Subject: [PATCH 1/8] Fixed holding tags unit tests. --- .../PathScripts/PathDressupHoldingTags.py | 10 ++++--- .../PathTests/TestPathDressupHoldingTags.py | 28 ++++++++----------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathDressupHoldingTags.py b/src/Mod/Path/PathScripts/PathDressupHoldingTags.py index b279d33faf..857acf8c2e 100644 --- a/src/Mod/Path/PathScripts/PathDressupHoldingTags.py +++ b/src/Mod/Path/PathScripts/PathDressupHoldingTags.py @@ -52,8 +52,8 @@ LOG_MODULE = 'PathDressupHoldingTags' def debugEdge(edge, prefix, force = False): if force or PathLog.getLevel(LOG_MODULE) == PathLog.Level.DEBUG: - pf = edge.valueAt(edge.FirstParameter) - pl = edge.valueAt(edge.LastParameter) + pf = edge.valueAt(edge.FirstParameter) + pl = edge.valueAt(edge.LastParameter) if type(edge.Curve) == Part.Line or type(edge.Curve) == Part.LineSegment: print("%s %s((%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f))" % (prefix, type(edge.Curve), pf.x, pf.y, pf.z, pl.x, pl.y, pl.z)) else: @@ -221,8 +221,10 @@ class Tag: angle = -PathGeom.getAngle(self.originAt(0)) * 180 / math.pi PathLog.debug("solid.rotate(%f)" % angle) self.solid.rotate(FreeCAD.Vector(0,0,0), FreeCAD.Vector(0,0,1), angle) - PathLog.debug("solid.translate(%s)" % self.originAt(z)) - self.solid.translate(self.originAt(z - 0.01 * self.actualHeight)) + orig = self.originAt(z - 0.01 * self.actualHeight) + PathLog.debug("solid.translate(%s)" % oric) + self.solid.translate(oric) + radius = min(self.radius, radius) self.realRadius = radius if radius != 0: PathLog.debug("makeFillet(%.4f)" % radius) diff --git a/src/Mod/Path/PathTests/TestPathDressupHoldingTags.py b/src/Mod/Path/PathTests/TestPathDressupHoldingTags.py index 2d74688da6..f511124a4e 100644 --- a/src/Mod/Path/PathTests/TestPathDressupHoldingTags.py +++ b/src/Mod/Path/PathTests/TestPathDressupHoldingTags.py @@ -37,45 +37,41 @@ class TestHoldingTags(PathTestBase): """Unit tests for the HoldingTags dressup.""" def test00(self): - """Check Tag origin, serialization and de-serialization.""" + """Check Tag origin.""" tag = Tag(77, 13, 4, 5, 90, True) self.assertCoincide(tag.originAt(3), Vector(77, 13, 3)) - s = tag.toString() - tagCopy = Tag.FromString(s) - self.assertEqual(tag.x, tagCopy.x) - self.assertEqual(tag.y, tagCopy.y) - self.assertEqual(tag.height, tagCopy.height) - self.assertEqual(tag.width, tagCopy.width) - self.assertEqual(tag.enabled, tagCopy.enabled) def test01(self): """Verify solid for a 90 degree tag is a cylinder.""" - tag = Tag(100, 200, 4, 5, 90, True) + tag = Tag(100, 200, 4, 5, 90, 0, True) tag.createSolidsAt(17, 0) self.assertIsNotNone(tag.solid) - self.assertCylinderAt(tag.solid, Vector(100, 200, 17), 2, 5) + self.assertCylinderAt(tag.solid, Vector(100, 200, 17 - 5 * 0.01), 2, 5 * 1.01) def test02(self): """Verify trapezoidal tag has a cone shape with a lid.""" - tag = Tag(0, 0, 18, 5, 45, True) + tag = Tag(0, 0, 18, 5, 45, 0, True) tag.createSolidsAt(0, 0) self.assertIsNotNone(tag.solid) - self.assertConeAt(tag.solid, Vector(0,0,0), 9, 4, 5) + self.assertConeAt(tag.solid, Vector(0,0,-0.05), 9, 3.95, 5.05) def test03(self): """Verify pointy cone shape of tag with pointy end if width, angle and height match up.""" - tag = Tag(0, 0, 10, 5, 45, True) + tag = Tag(0, 0, 10, 5, 45, 0, True) tag.createSolidsAt(0, 0) self.assertIsNotNone(tag.solid) - self.assertConeAt(tag.solid, Vector(0,0,0), 5, 0, 5) + h = 5 * 1.01 + self.assertConeAt(tag.solid, Vector(0,0,-h * 0.01), 5, 0, h) def test04(self): """Verify height adjustment if tag isn't wide eough for angle.""" - tag = Tag(0, 0, 5, 17, 60, True) + tag = Tag(0, 0, 5, 17, 60, 0, True) tag.createSolidsAt(0, 0) self.assertIsNotNone(tag.solid) - self.assertConeAt(tag.solid, Vector(0,0,0), 2.5, 0, 2.5 * math.tan((60/180.0)*math.pi)) + h = 2.5 * math.tan((60/180.0)*math.pi) * 1.01 + print(h) + self.assertConeAt(tag.solid, Vector(0,0,-h * 0.01), 2.5, 0, h) From f0db6b824e3b1594c907f1fde0cca7ab7777aff8 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Sun, 22 Jan 2017 19:28:40 -0800 Subject: [PATCH 2/8] Hooked Path tests into global unit test target. --- src/Mod/Test/TestApp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Mod/Test/TestApp.py b/src/Mod/Test/TestApp.py index cbf56c7ca6..e4b5c8d440 100644 --- a/src/Mod/Test/TestApp.py +++ b/src/Mod/Test/TestApp.py @@ -72,7 +72,8 @@ def All(): "TestPartApp", "TestPartDesignApp", "TestSpreadsheet", - "TestTechDrawApp" ] + "TestTechDrawApp", + "TestPathApp" ] # gui tests of modules if (FreeCAD.GuiUp == 1): From ea7789b8b6fce74bb1b19794d12a1ac3f1a85307 Mon Sep 17 00:00:00 2001 From: ml Date: Thu, 26 Jan 2017 22:03:33 -0800 Subject: [PATCH 3/8] Fixed merge issues and re-enabled tests. --- src/Mod/Path/PathScripts/PathDressupHoldingTags.py | 12 +++++------- src/Mod/Path/TestPathApp.py | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathDressupHoldingTags.py b/src/Mod/Path/PathScripts/PathDressupHoldingTags.py index 857acf8c2e..8284cd8d2c 100644 --- a/src/Mod/Path/PathScripts/PathDressupHoldingTags.py +++ b/src/Mod/Path/PathScripts/PathDressupHoldingTags.py @@ -25,7 +25,6 @@ import FreeCAD import FreeCADGui import Draft import DraftGeomUtils -import DraftGui import Path import PathScripts.PathLog as PathLog import PathScripts.PathPreferencesPathDressup as PathPreferencesPathDressup @@ -33,7 +32,6 @@ import Part import copy import math -from DraftGui import todo from PathScripts import PathUtils from PathScripts.PathGeom import PathGeom from PathScripts.PathPreferences import PathPreferences @@ -52,8 +50,8 @@ LOG_MODULE = 'PathDressupHoldingTags' def debugEdge(edge, prefix, force = False): if force or PathLog.getLevel(LOG_MODULE) == PathLog.Level.DEBUG: - pf = edge.valueAt(edge.FirstParameter) - pl = edge.valueAt(edge.LastParameter) + pf = edge.valueAt(edge.FirstParameter) + pl = edge.valueAt(edge.LastParameter) if type(edge.Curve) == Part.Line or type(edge.Curve) == Part.LineSegment: print("%s %s((%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f))" % (prefix, type(edge.Curve), pf.x, pf.y, pf.z, pl.x, pl.y, pl.z)) else: @@ -131,7 +129,7 @@ class HoldingTagsPreferences: @classmethod def defaultRadius(cls, ifNotSet = 0.0): return PathPreferences.preferences().GetFloat(cls.DefaultHoldingTagRadius, ifNotSet) - + def __init__(self): self.form = FreeCADGui.PySideUic.loadUi(":/preferences/PathDressupHoldingTags.ui") @@ -222,8 +220,8 @@ class Tag: PathLog.debug("solid.rotate(%f)" % angle) self.solid.rotate(FreeCAD.Vector(0,0,0), FreeCAD.Vector(0,0,1), angle) orig = self.originAt(z - 0.01 * self.actualHeight) - PathLog.debug("solid.translate(%s)" % oric) - self.solid.translate(oric) + PathLog.debug("solid.translate(%s)" % orig) + self.solid.translate(orig) radius = min(self.radius, radius) self.realRadius = radius if radius != 0: diff --git a/src/Mod/Path/TestPathApp.py b/src/Mod/Path/TestPathApp.py index f5e3abf0c2..f2e9611a00 100644 --- a/src/Mod/Path/TestPathApp.py +++ b/src/Mod/Path/TestPathApp.py @@ -31,4 +31,4 @@ from PathTests.TestPathPost import PathPostTestCases from PathTests.TestPathGeom import TestPathGeom from PathTests.TestPathDepthParams import depthTestCases -#from PathTests.TestPathDressupHoldingTags import TestHoldingTags +from PathTests.TestPathDressupHoldingTags import TestHoldingTags From 831e467f9e76e4d5d047f59e7194b8d5d3d6eb35 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Fri, 27 Jan 2017 13:28:41 -0800 Subject: [PATCH 4/8] Refactored cmake file and added TestPathCore. --- src/Mod/Path/CMakeLists.txt | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Mod/Path/CMakeLists.txt b/src/Mod/Path/CMakeLists.txt index 3068df25c9..d2fda31d15 100644 --- a/src/Mod/Path/CMakeLists.txt +++ b/src/Mod/Path/CMakeLists.txt @@ -10,6 +10,7 @@ INSTALL( Init.py InitGui.py PathCommands.py + TestPathApp.py DESTINATION Mod/Path ) @@ -76,15 +77,6 @@ SET(PathScripts_SRCS PathScripts/opensbp_pre.py PathScripts/rml_post.py PathScripts/slic3r_pre.py - PathTests/PathTestUtils.py - PathTests/TestPathDepthParams.py - PathTests/TestPathDressupHoldingTags.py - PathTests/TestPathGeom.py - PathTests/TestPathLog.py - PathTests/TestPathPost.py - PathTests/__init__.py - PathTests/test_linuxcnc_00.ngc - TestPathApp.py ) SET(PathScripts_NC_SRCS @@ -95,9 +87,23 @@ SET(PathScripts_NC_SRCS PathScripts/nc/iso_codes.py ) +SET(PathTests_SRCS + PathTests/PathTestUtils.py + PathTests/TestPathCore.py + PathTests/TestPathDepthParams.py + PathTests/TestPathDressupHoldingTags.py + PathTests/TestPathGeom.py + PathTests/TestPathLog.py + PathTests/TestPathPost.py + PathTests/__init__.py + PathTests/test_linuxcnc_00.ngc + TestPathApp.py +) + SET(all_files ${PathScripts_SRCS} ${PathScripts_NC_SRCS} + ${PathTests_SRCS} ) ADD_CUSTOM_TARGET(PathScripts ALL @@ -120,3 +126,10 @@ INSTALL( Mod/Path/PathScripts/nc ) +INSTALL( + FILES + ${PathTests_SRCS} + DESTINATION + Mod/Path/PathTests +) + From e1a22b796ed3a6444dbdcf67729daa949b2e4c9f Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Fri, 27 Jan 2017 21:44:08 -0800 Subject: [PATCH 5/8] Fixed unit tests for the case where LineOld is not set to false. --- src/Mod/Path/PathTests/PathTestUtils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Mod/Path/PathTests/PathTestUtils.py b/src/Mod/Path/PathTests/PathTestUtils.py index 518eeb90cb..6cfb35f982 100644 --- a/src/Mod/Path/PathTests/PathTestUtils.py +++ b/src/Mod/Path/PathTests/PathTestUtils.py @@ -45,7 +45,8 @@ class PathTestBase(unittest.TestCase): def assertLine(self, edge, pt1, pt2): """Verify that edge is a line from pt1 to pt2.""" - self.assertIs(type(edge.Curve), Part.Line) + # Depending on the setting of LineOld .... + self.assertTrue(type(edge.Curve) is Part.Line or type(edge.Curve) is Part.LineSegment) self.assertCoincide(edge.valueAt(edge.FirstParameter), pt1) self.assertCoincide(edge.valueAt(edge.LastParameter), pt2) From 013043b18c9ee63a70abbbee8022c76fec17dcc5 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Fri, 27 Jan 2017 22:39:53 -0800 Subject: [PATCH 6/8] Refactored cmake file once again - exposing root exception. --- src/Mod/Path/CMakeLists.txt | 12 ++++++++++-- src/Mod/Test/TestApp.py | 34 +++++++++++++++++----------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/Mod/Path/CMakeLists.txt b/src/Mod/Path/CMakeLists.txt index d2fda31d15..42b9dd98fb 100644 --- a/src/Mod/Path/CMakeLists.txt +++ b/src/Mod/Path/CMakeLists.txt @@ -97,20 +97,28 @@ SET(PathTests_SRCS PathTests/TestPathPost.py PathTests/__init__.py PathTests/test_linuxcnc_00.ngc - TestPathApp.py ) SET(all_files ${PathScripts_SRCS} ${PathScripts_NC_SRCS} - ${PathTests_SRCS} ) ADD_CUSTOM_TARGET(PathScripts ALL SOURCES ${all_files} ) +SET(test_files + TestPathApp.py + ${PathTests_SRCS} +) + +ADD_CUSTOM_TARGET(PathTests ALL + SOURCES ${test_files} +) + fc_copy_sources(PathScripts "${CMAKE_BINARY_DIR}/Mod/Path" ${all_files}) +fc_copy_sources(PathTests "${CMAKE_BINARY_DIR}/Mod/Path" ${test_files}) INSTALL( FILES diff --git a/src/Mod/Test/TestApp.py b/src/Mod/Test/TestApp.py index e4b5c8d440..e3dc7440d9 100644 --- a/src/Mod/Test/TestApp.py +++ b/src/Mod/Test/TestApp.py @@ -34,24 +34,24 @@ import unittest def tryLoadingTest(testName): "Loads and returns testName, or a failing TestCase if unsuccessful." - try: - return unittest.defaultTestLoader.loadTestsFromName(testName) +# try: + return unittest.defaultTestLoader.loadTestsFromName(testName) - except ImportError: - class LoadFailed(unittest.TestCase): - def __init__(self, testName): - # setattr() first, because TestCase ctor checks for methodName. - setattr(self, "failed_to_load_" + testName, self._runTest) - super(LoadFailed, self).__init__("failed_to_load_" + testName) - self.testName = testName - - def __name__(self): - return "Loading " + self.testName - - def _runTest(self): - self.fail("Couldn't load " + self.testName) - - return LoadFailed(testName) +# except ImportError: +# class LoadFailed(unittest.TestCase): +# def __init__(self, testName): +# # setattr() first, because TestCase ctor checks for methodName. +# setattr(self, "failed_to_load_" + testName, self._runTest) +# super(LoadFailed, self).__init__("failed_to_load_" + testName) +# self.testName = testName +# +# def __name__(self): +# return "Loading " + self.testName +# +# def _runTest(self): +# self.fail("Couldn't load " + self.testName) +# +# return LoadFailed(testName) def All(): # Base system tests From c9c7d19a829d32a968159a03bff4e3e67d2d1971 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Fri, 27 Jan 2017 23:01:45 -0800 Subject: [PATCH 7/8] Import pivy only if gui is up. --- src/Mod/Path/PathScripts/PathDressupHoldingTags.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathDressupHoldingTags.py b/src/Mod/Path/PathScripts/PathDressupHoldingTags.py index 8284cd8d2c..cdb598fec0 100644 --- a/src/Mod/Path/PathScripts/PathDressupHoldingTags.py +++ b/src/Mod/Path/PathScripts/PathDressupHoldingTags.py @@ -35,8 +35,7 @@ import math from PathScripts import PathUtils from PathScripts.PathGeom import PathGeom from PathScripts.PathPreferences import PathPreferences -from PySide import QtCore, QtGui -from pivy import coin +from PySide import QtCore """Holding Tags Dressup object and FreeCAD command""" @@ -48,6 +47,10 @@ def translate(text, context = "PathDressup_HoldingTags", disambig=None): LOG_MODULE = 'PathDressupHoldingTags' #PathLog.setLevel(PathLog.Level.DEBUG, LOG_MODULE) +if FreeCAD.GuiUp: + from pivy import coin + from PySide import QtCore + def debugEdge(edge, prefix, force = False): if force or PathLog.getLevel(LOG_MODULE) == PathLog.Level.DEBUG: pf = edge.valueAt(edge.FirstParameter) From d4da536d4c4623bf5c795c8b82cbd438bf490f11 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Fri, 27 Jan 2017 23:22:18 -0800 Subject: [PATCH 8/8] Restored exception masking - although i'm not sure it's a good thing. --- src/Mod/Test/TestApp.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Mod/Test/TestApp.py b/src/Mod/Test/TestApp.py index e3dc7440d9..e4b5c8d440 100644 --- a/src/Mod/Test/TestApp.py +++ b/src/Mod/Test/TestApp.py @@ -34,24 +34,24 @@ import unittest def tryLoadingTest(testName): "Loads and returns testName, or a failing TestCase if unsuccessful." -# try: - return unittest.defaultTestLoader.loadTestsFromName(testName) + try: + return unittest.defaultTestLoader.loadTestsFromName(testName) -# except ImportError: -# class LoadFailed(unittest.TestCase): -# def __init__(self, testName): -# # setattr() first, because TestCase ctor checks for methodName. -# setattr(self, "failed_to_load_" + testName, self._runTest) -# super(LoadFailed, self).__init__("failed_to_load_" + testName) -# self.testName = testName -# -# def __name__(self): -# return "Loading " + self.testName -# -# def _runTest(self): -# self.fail("Couldn't load " + self.testName) -# -# return LoadFailed(testName) + except ImportError: + class LoadFailed(unittest.TestCase): + def __init__(self, testName): + # setattr() first, because TestCase ctor checks for methodName. + setattr(self, "failed_to_load_" + testName, self._runTest) + super(LoadFailed, self).__init__("failed_to_load_" + testName) + self.testName = testName + + def __name__(self): + return "Loading " + self.testName + + def _runTest(self): + self.fail("Couldn't load " + self.testName) + + return LoadFailed(testName) def All(): # Base system tests