Merge pull request #467 from mlampert/path-unit-test-fixes

Path: Path unit test fixes issue #2870
This commit is contained in:
wwmayer
2017-01-28 22:15:51 +01:00
committed by GitHub
6 changed files with 57 additions and 35 deletions

View File

@@ -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,6 +87,18 @@ 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
)
SET(all_files
${PathScripts_SRCS}
${PathScripts_NC_SRCS}
@@ -104,7 +108,17 @@ 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
@@ -120,3 +134,10 @@ INSTALL(
Mod/Path/PathScripts/nc
)
INSTALL(
FILES
${PathTests_SRCS}
DESTINATION
Mod/Path/PathTests
)

View File

@@ -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,12 +32,10 @@ import Part
import copy
import math
from DraftGui import todo
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"""
@@ -50,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)
@@ -131,7 +132,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")
@@ -221,8 +222,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)" % orig)
self.solid.translate(orig)
radius = min(self.radius, radius)
self.realRadius = radius
if radius != 0:
PathLog.debug("makeFillet(%.4f)" % radius)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -72,7 +72,8 @@ def All():
"TestPartApp",
"TestPartDesignApp",
"TestSpreadsheet",
"TestTechDrawApp" ]
"TestTechDrawApp",
"TestPathApp" ]
# gui tests of modules
if (FreeCAD.GuiUp == 1):