Add Draft workbench to .pre-commit-config (#24664)

* Add Draft workbench to .pre-commit-config

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
marcuspollio
2025-10-15 11:21:09 +02:00
committed by GitHub
parent 87f88bba30
commit 50e4864efb
225 changed files with 10713 additions and 9269 deletions

View File

@@ -39,7 +39,7 @@ from draftutils.messages import _msg
def draw_header():
"""Draw a header for the tests."""
_msg("")
_msg(78*"-")
_msg(78 * "-")
def import_test(module):
@@ -56,18 +56,22 @@ def import_test(module):
def no_gui(module):
"""Print a message that there is no user interface."""
_msg(" #-----------------------------------------------------#\n"
" # No GUI; cannot test for '{}'\n"
" #-----------------------------------------------------#\n"
" Automatic PASS".format(module))
_msg(
" #-----------------------------------------------------#\n"
" # No GUI; cannot test for '{}'\n"
" #-----------------------------------------------------#\n"
" Automatic PASS".format(module)
)
def no_test():
"""Print a message that the test is not currently implemented."""
_msg(" #-----------------------------------------------------#\n"
" # This test is not implemented currently\n"
" #-----------------------------------------------------#\n"
" Automatic PASS")
_msg(
" #-----------------------------------------------------#\n"
" # This test is not implemented currently\n"
" #-----------------------------------------------------#\n"
" Automatic PASS"
)
def fake_function(p1=None, p2=None, p3=None, p4=None, p5=None):
@@ -79,4 +83,5 @@ def fake_function(p1=None, p2=None, p3=None, p4=None, p5=None):
no_test()
return True
## @}

View File

@@ -78,12 +78,14 @@ def _create_frame(doc=None):
version = App.Version()
now = datetime.datetime.now().strftime("%Y/%m/%dT%H:%M:%S")
_text = ["Draft test file",
"Created: {}".format(now),
"\n",
"Version: " + ".".join(version[0:3]),
"Release: " + " ".join(version[3:5]),
"Branch: " + " ".join(version[5:])]
_text = [
"Draft test file",
"Created: {}".format(now),
"\n",
"Version: " + ".".join(version[0:3]),
"Release: " + " ".join(version[3:5]),
"Branch: " + " ".join(version[5:]),
]
record = doc.addObject("App::Annotation", "Description")
record.LabelText = _text
@@ -104,10 +106,7 @@ def _create_frame(doc=None):
frame.Shape = poly
def _create_objects(doc=None,
font_file=None,
hatch_file=None,
hatch_name=None):
def _create_objects(doc=None, font_file=None, hatch_file=None, hatch_name=None):
"""Create the objects of the test file."""
if not doc:
doc = App.activeDocument()
@@ -125,9 +124,7 @@ def _create_objects(doc=None,
# Wire
_msg(16 * "-")
_msg("Wire")
Draft.make_wire([Vector(1000, 0, 0),
Vector(1500, 250, 0),
Vector(1500, 500, 0)])
Draft.make_wire([Vector(1000, 0, 0), Vector(1500, 250, 0), Vector(1500, 500, 0)])
_set_text(["Wire"], Vector(1000, -200, 0))
# Fillet
@@ -152,9 +149,7 @@ def _create_objects(doc=None,
# Circular arc 3 points
_msg(16 * "-")
_msg("Circular arc 3 points")
Draft.make_arc_3points([Vector(4250, 0, 0),
Vector(4000, 250, 0),
Vector(4250, 500, 0)])
Draft.make_arc_3points([Vector(4250, 0, 0), Vector(4000, 250, 0), Vector(4250, 500, 0)])
_set_text(["Circular arc 3 points"], Vector(4000, -200, 0))
# Circle
@@ -188,29 +183,32 @@ def _create_objects(doc=None,
# BSpline
_msg(16 * "-")
_msg("BSpline")
Draft.make_bspline([Vector(9000, 0, 0),
Vector(9100, 200, 0),
Vector(9400, 300, 0),
Vector(9500, 500, 0)])
Draft.make_bspline(
[Vector(9000, 0, 0), Vector(9100, 200, 0), Vector(9400, 300, 0), Vector(9500, 500, 0)]
)
_set_text(["BSpline"], Vector(9000, -200, 0))
# Cubic bezier
_msg(16 * "-")
_msg("Cubic bezier")
Draft.make_bezcurve([Vector(10000, 0, 0),
Vector(10000, 500, 0),
Vector(10500, 0, 0),
Vector(10500, 500, 0)], degree=3)
Draft.make_bezcurve(
[Vector(10000, 0, 0), Vector(10000, 500, 0), Vector(10500, 0, 0), Vector(10500, 500, 0)],
degree=3,
)
_set_text(["Cubic bezier"], Vector(10000, -200, 0))
# N-degree bezier
_msg(16 * "-")
_msg("N-degree bezier")
Draft.make_bezcurve([Vector (11000, 0, 0),
Vector (11100, 400, 0),
Vector (11250, 250, 0),
Vector (11400, 100, 0),
Vector (11500, 500, 0)])
Draft.make_bezcurve(
[
Vector(11000, 0, 0),
Vector(11100, 400, 0),
Vector(11250, 250, 0),
Vector(11400, 100, 0),
Vector(11500, 500, 0),
]
)
_set_text(["N-degree bezier"], Vector(11000, -200, 0))
# Point
@@ -239,9 +237,7 @@ def _create_objects(doc=None,
_msg(16 * "-")
_msg("Shapestring")
try:
shape_string = Draft.make_shapestring("Testing",
font_file,
100)
shape_string = Draft.make_shapestring("Testing", font_file, 100)
shape_string.Placement.Base = Vector(14000, 0)
except Exception:
_wrn("Shapestring could not be created")
@@ -259,11 +255,7 @@ def _create_objects(doc=None,
rectangle.ViewObject.Visibility = False
doc.recompute()
try:
Draft.make_hatch(rectangle,
hatch_file,
hatch_name,
scale=10,
rotation=45)
Draft.make_hatch(rectangle, hatch_file, hatch_name, scale=10, rotation=45)
except Exception:
_wrn("Hatch could not be created")
_wrn("Possible cause: the hatch file may not exist")
@@ -283,9 +275,9 @@ def _create_objects(doc=None,
# Linear dimension
_msg(16 * "-")
_msg("Linear dimension")
dimension = Draft.make_linear_dimension(Vector(1500, 2000, 0),
Vector(1500, 2400, 0),
Vector(1000, 2200, 0))
dimension = Draft.make_linear_dimension(
Vector(1500, 2000, 0), Vector(1500, 2400, 0), Vector(1000, 2200, 0)
)
if App.GuiUp:
dimension.ViewObject.ArrowSizeStart = 15
dimension.ViewObject.ArrowSizeEnd = 15
@@ -296,11 +288,9 @@ def _create_objects(doc=None,
dimension.ViewObject.Decimals = 1
dimension.ViewObject.ShowUnit = False
line = Draft.make_wire([Vector(1500, 2600, 0),
Vector(1500, 3000, 0)])
line = Draft.make_wire([Vector(1500, 2600, 0), Vector(1500, 3000, 0)])
doc.recompute()
dimension = Draft.make_linear_dimension_obj(line, 1, 2,
Vector(1000, 2800, 0))
dimension = Draft.make_linear_dimension_obj(line, 1, 2, Vector(1000, 2800, 0))
if App.GuiUp:
dimension.ViewObject.ArrowSizeStart = 15
dimension.ViewObject.ArrowSizeEnd = 15
@@ -322,10 +312,7 @@ def _create_objects(doc=None,
circle.Placement.Base = Vector(2200, 2200, 0)
circle.MakeFace = False
doc.recompute()
dimension = Draft.make_radial_dimension_obj(circle,
1,
"radius",
Vector(2300, 2300, 0))
dimension = Draft.make_radial_dimension_obj(circle, 1, "radius", Vector(2300, 2300, 0))
if App.GuiUp:
dimension.ViewObject.ArrowSizeStart = 15
dimension.ViewObject.ArrowSizeEnd = 15
@@ -337,27 +324,21 @@ def _create_objects(doc=None,
circle.Placement.Base = Vector(2200, 2800, 0)
circle.MakeFace = False
doc.recompute()
dimension = Draft.make_radial_dimension_obj(circle,
1,
"diameter",
Vector(2300, 2900, 0))
dimension = Draft.make_radial_dimension_obj(circle, 1, "diameter", Vector(2300, 2900, 0))
if App.GuiUp:
dimension.ViewObject.ArrowSizeStart = 15
dimension.ViewObject.ArrowSizeEnd = 15
dimension.ViewObject.FontSize = 50
dimension.ViewObject.Decimals = 1
dimension.ViewObject.ShowUnit = False
_set_text(["Radius dimension",
"Diameter dimension"], Vector(2000, 1800, 0))
_set_text(["Radius dimension", "Diameter dimension"], Vector(2000, 1800, 0))
# Angular dimension
_msg(16 * "-")
_msg("Angular dimension")
Draft.make_line(Vector(3000, 2000, 0), Vector(3500, 2000, 0))
Draft.make_line(Vector(3000, 2000, 0), Vector(3500, 2500, 0))
dimension = Draft.make_angular_dimension(Vector(3000, 2000, 0),
[0, 45],
Vector(3250, 2250, 0))
dimension = Draft.make_angular_dimension(Vector(3000, 2000, 0), [0, 45], Vector(3250, 2250, 0))
if App.GuiUp:
dimension.ViewObject.ArrowSizeStart = 15
dimension.ViewObject.ArrowSizeEnd = 15
@@ -369,10 +350,12 @@ def _create_objects(doc=None,
_msg(16 * "-")
_msg("Label")
place = App.Placement(Vector(4250, 2250, 0), App.Rotation())
label = Draft.make_label(target_point=Vector(4000, 2000, 0),
placement=place,
custom_text="Example label",
distance=-100)
label = Draft.make_label(
target_point=Vector(4000, 2000, 0),
placement=place,
custom_text="Example label",
distance=-100,
)
label.Text = "Testing"
if App.GuiUp:
label.ViewObject.ArrowSizeStart = 15
@@ -389,14 +372,9 @@ def _create_objects(doc=None,
if App.GuiUp:
rectangle.ViewObject.Visibility = False
doc.recompute()
Draft.make_ortho_array(rectangle,
Vector(200, 0, 0),
Vector(0, 150, 0),
Vector(0, 0, 0),
3,
2,
1,
use_link=False)
Draft.make_ortho_array(
rectangle, Vector(200, 0, 0), Vector(0, 150, 0), Vector(0, 0, 0), 3, 2, 1, use_link=False
)
_set_text(["Orthogonal array"], Vector(0, 3800, 0))
# Orthogonal link array
@@ -407,46 +385,29 @@ def _create_objects(doc=None,
if App.GuiUp:
rectangle.ViewObject.Visibility = False
doc.recompute()
Draft.make_ortho_array(rectangle,
Vector(200, 0, 0),
Vector(0, 150, 0),
Vector(0, 0, 0),
3,
2,
1,
use_link=True)
Draft.make_ortho_array(
rectangle, Vector(200, 0, 0), Vector(0, 150, 0), Vector(0, 0, 0), 3, 2, 1, use_link=True
)
_set_text(["Orthogonal link array"], Vector(1000, 3800, 0))
# Polar array
_msg(16 * "-")
_msg("Polar array")
wire = Draft.make_wire([Vector(2000, 4050, 0),
Vector(2000, 4000, 0),
Vector(2100, 4000, 0)])
wire = Draft.make_wire([Vector(2000, 4050, 0), Vector(2000, 4000, 0), Vector(2100, 4000, 0)])
if App.GuiUp:
wire.ViewObject.Visibility = False
doc.recompute()
Draft.make_polar_array(wire,
4,
90,
Vector(2000, 4250, 0),
use_link=False)
Draft.make_polar_array(wire, 4, 90, Vector(2000, 4250, 0), use_link=False)
_set_text(["Polar array"], Vector(2000, 3800, 0))
# Polar link array
_msg(16 * "-")
_msg("Polar link array")
wire = Draft.make_wire([Vector(3000, 4050, 0),
Vector(3000, 4000, 0),
Vector(3050, 4000, 0)])
wire = Draft.make_wire([Vector(3000, 4050, 0), Vector(3000, 4000, 0), Vector(3050, 4000, 0)])
if App.GuiUp:
wire.ViewObject.Visibility = False
doc.recompute()
Draft.make_polar_array(wire,
4,
90,
Vector(3000, 4250, 0),
use_link=True)
Draft.make_polar_array(wire, 4, 90, Vector(3000, 4250, 0), use_link=True)
_set_text(["Polar link array"], Vector(3000, 3800, 0))
# Circular array
@@ -457,14 +418,9 @@ def _create_objects(doc=None,
if App.GuiUp:
polygon.ViewObject.Visibility = False
doc.recompute()
Draft.make_circular_array(polygon,
110,
100,
3,
1,
Vector(0, 0, 1),
Vector(4250, 4250, 0),
use_link=False)
Draft.make_circular_array(
polygon, 110, 100, 3, 1, Vector(0, 0, 1), Vector(4250, 4250, 0), use_link=False
)
_set_text(["Circular array"], Vector(4000, 3800, 0))
# Circular link array
@@ -475,14 +431,9 @@ def _create_objects(doc=None,
if App.GuiUp:
polygon.ViewObject.Visibility = False
doc.recompute()
Draft.make_circular_array(polygon,
110,
100,
3,
1,
Vector(0, 0, 1),
Vector(5250, 4250, 0),
use_link=True)
Draft.make_circular_array(
polygon, 110, 100, 3, 1, Vector(0, 0, 1), Vector(5250, 4250, 0), use_link=True
)
_set_text(["Circular link array"], Vector(5000, 3800, 0))
# Path array
@@ -492,10 +443,9 @@ def _create_objects(doc=None,
polygon.Placement.Base = Vector(6000, 4000, 0)
if App.GuiUp:
polygon.ViewObject.Visibility = False
spline = Draft.make_bspline([Vector(6000, 4000, 0),
Vector(6100, 4200, 0),
Vector(6400, 4300, 0),
Vector(6500, 4500, 0)])
spline = Draft.make_bspline(
[Vector(6000, 4000, 0), Vector(6100, 4200, 0), Vector(6400, 4300, 0), Vector(6500, 4500, 0)]
)
doc.recompute()
Draft.make_path_array(polygon, spline, 5, use_link=False)
_set_text(["Path array"], Vector(6000, 3800, 0))
@@ -507,10 +457,9 @@ def _create_objects(doc=None,
polygon.Placement.Base = Vector(7000, 4000, 0)
if App.GuiUp:
polygon.ViewObject.Visibility = False
spline = Draft.make_bspline([Vector(7000, 4000, 0),
Vector(7100, 4200, 0),
Vector(7400, 4300, 0),
Vector(7500, 4500, 0)])
spline = Draft.make_bspline(
[Vector(7000, 4000, 0), Vector(7100, 4200, 0), Vector(7400, 4300, 0), Vector(7500, 4500, 0)]
)
doc.recompute()
Draft.make_path_array(polygon, spline, 5, use_link=True)
_set_text(["Path link array"], Vector(7000, 3800, 0))
@@ -524,8 +473,7 @@ def _create_objects(doc=None,
point_2 = Draft.make_point(8030, 4250, 0)
point_3 = Draft.make_point(8470, 4250, 0)
point_4 = Draft.make_point(8470, 4470, 0)
add_list, delete_list = Draft.upgrade([point_1, point_2,
point_3, point_4])
add_list, delete_list = Draft.upgrade([point_1, point_2, point_3, point_4])
compound = add_list[0]
if App.GuiUp:
compound.ViewObject.PointSize = 5
@@ -542,8 +490,7 @@ def _create_objects(doc=None,
point_2 = Draft.make_point(9030, 4250, 0)
point_3 = Draft.make_point(9470, 4250, 0)
point_4 = Draft.make_point(9470, 4470, 0)
add_list, delete_list = Draft.upgrade([point_1, point_2,
point_3, point_4])
add_list, delete_list = Draft.upgrade([point_1, point_2, point_3, point_4])
compound = add_list[0]
if App.GuiUp:
compound.ViewObject.PointSize = 5
@@ -556,28 +503,21 @@ def _create_objects(doc=None,
# Mirror
_msg(16 * "-")
_msg("Mirror")
wire = Draft.make_wire([Vector(0, 6000, 0),
Vector(150, 6200, 0),
Vector(500, 6000, 0)])
Draft.mirror(wire,
Vector(0, 6250, 0),
Vector(500, 6250, 0))
wire = Draft.make_wire([Vector(0, 6000, 0), Vector(150, 6200, 0), Vector(500, 6000, 0)])
Draft.mirror(wire, Vector(0, 6250, 0), Vector(500, 6250, 0))
_set_text(["Mirror"], Vector(0, 5800, 0))
# Clone
_msg(16 * "-")
_msg("Clone")
wire = Draft.make_wire([Vector(1000, 6000, 0),
Vector(1150, 6200, 0),
Vector(1500, 6000, 0)])
wire = Draft.make_wire([Vector(1000, 6000, 0), Vector(1150, 6200, 0), Vector(1500, 6000, 0)])
Draft.make_clone(wire, Vector(0, 300, 0))
_set_text(["Clone"], Vector(1000, 5800, 0))
# Shape2DView
_msg(16 * "-")
_msg("Shape2DView")
place = App.Placement(Vector(2000, 6000, 0),
App.Rotation(Vector(0, 0, 1), Vector(1, 2, 3)))
place = App.Placement(Vector(2000, 6000, 0), App.Rotation(Vector(0, 0, 1), Vector(1, 2, 3)))
box = doc.addObject("Part::Box", "Box")
box.Length = 200
box.Width = 500
@@ -601,12 +541,14 @@ def _create_objects(doc=None,
# Layer
_msg(16 * "-")
_msg("Layer")
layer = Draft.make_layer("Custom layer",
line_color=(0.33, 0.0, 0.49),
shape_color=(0.56, 0.89, 0.56),
line_width=4,
draw_style="Solid",
transparency=50)
layer = Draft.make_layer(
"Custom layer",
line_color=(0.33, 0.0, 0.49),
shape_color=(0.56, 0.89, 0.56),
line_width=4,
draw_style="Solid",
transparency=50,
)
box = doc.addObject("Part::Box", "Box")
box.Length = 200
box.Width = 500
@@ -622,9 +564,11 @@ def _create_objects(doc=None,
doc.recompute()
def create_test_file(font_file=App.getResourceDir()+"Mod/TechDraw/Resources/fonts/osifont-lgpl3fe.ttf",
hatch_file=App.getResourceDir()+"Mod/TechDraw/PAT/FCPAT.pat",
hatch_name="Horizontal5"):
def create_test_file(
font_file=App.getResourceDir() + "Mod/TechDraw/Resources/fonts/osifont-lgpl3fe.ttf",
hatch_file=App.getResourceDir() + "Mod/TechDraw/PAT/FCPAT.pat",
hatch_name="Horizontal5",
):
"""Create a complete test file of Draft objects.
It draws a frame with information on the software used to create
@@ -664,6 +608,7 @@ def create_test_file(font_file=App.getResourceDir()+"Mod/TechDraw/Resources/font
return doc
## @}

View File

@@ -71,4 +71,5 @@ class DraftAirfoilDAT(test_base.DraftTestCaseDoc):
obj = aux.fake_function(out_file)
self.assertTrue(obj, "'{}' failed".format(operation))
## @}

View File

@@ -43,10 +43,16 @@ class DraftArray(test_base.DraftTestCaseDoc):
box.Label = "Box"
self.doc.recompute()
array = Draft.make_ortho_array(box, v_x=Vector(100.0, 0.0, 0.0),
v_y=Vector(0.0, 100.0, 0.0),
v_z=Vector(0.0, 0.0, 100.0),
n_x=12, n_y=1, n_z=1, use_link=True)
array = Draft.make_ortho_array(
box,
v_x=Vector(100.0, 0.0, 0.0),
v_y=Vector(0.0, 100.0, 0.0),
v_z=Vector(0.0, 0.0, 100.0),
n_x=12,
n_y=1,
n_z=1,
use_link=True,
)
Draft.autogroup(array)
array.ExpandArray = True
@@ -64,4 +70,5 @@ class DraftArray(test_base.DraftTestCaseDoc):
self.doc.recompute(None, True, True)
self.assertEqual(array.Count, array.NumberX)
## @}

View File

@@ -103,10 +103,8 @@ class DraftCreation(test_base.DraftTestCaseDoc):
start_angle = 0
end_angle = 90
_msg(" radius={}".format(radius))
_msg(" startangle={0}, endangle={1}".format(start_angle,
end_angle))
obj = Draft.make_circle(radius,
startangle=start_angle, endangle=end_angle)
_msg(" startangle={0}, endangle={1}".format(start_angle, end_angle))
obj = Draft.make_circle(radius, startangle=start_angle, endangle=end_angle)
self.assertTrue(obj, "'{}' failed".format(operation))
def test_arc_3points(self):
@@ -185,9 +183,7 @@ class DraftCreation(test_base.DraftTestCaseDoc):
line = Draft.make_line(a, b)
self.doc.recompute()
obj = Draft.make_linear_dimension_obj(line,
i1=1, i2=2,
dim_line=Vector(5, 3, 0))
obj = Draft.make_linear_dimension_obj(line, i1=1, i2=2, dim_line=Vector(5, 3, 0))
self.assertTrue(obj, "'{}' failed".format(operation))
def test_dimension_radial_obj(self):
@@ -198,18 +194,16 @@ class DraftCreation(test_base.DraftTestCaseDoc):
start_angle = 0
end_angle = 90
_msg(" radius={}".format(radius))
_msg(" startangle={0}, endangle={1}".format(start_angle,
end_angle))
circ = Draft.make_circle(radius,
startangle=start_angle, endangle=end_angle)
_msg(" startangle={0}, endangle={1}".format(start_angle, end_angle))
circ = Draft.make_circle(radius, startangle=start_angle, endangle=end_angle)
self.doc.recompute()
obj1 = Draft.make_radial_dimension_obj(circ, index=1,
mode="radius",
dim_line=Vector(1, 1, 0))
obj2 = Draft.make_radial_dimension_obj(circ, index=1,
mode="diameter",
dim_line=Vector(3, 1, 0))
obj1 = Draft.make_radial_dimension_obj(
circ, index=1, mode="radius", dim_line=Vector(1, 1, 0)
)
obj2 = Draft.make_radial_dimension_obj(
circ, index=1, mode="diameter", dim_line=Vector(3, 1, 0)
)
self.assertTrue(obj1 and obj2, "'{}' failed".format(operation))
def test_dimension_angular(self):
@@ -322,12 +316,9 @@ class DraftCreation(test_base.DraftTestCaseDoc):
target_point = Vector(0, 0, 0)
distance = -25
placement = App.Placement(Vector(50, 50, 0), App.Rotation())
_msg(" target_point={0}, "
"distance={1}".format(target_point, distance))
_msg(" target_point={0}, " "distance={1}".format(target_point, distance))
_msg(" placement={}".format(placement))
obj = Draft.make_label(target_point=target_point,
distance=distance,
placement=placement)
obj = Draft.make_label(target_point=target_point, distance=distance, placement=placement)
self.doc.recompute()
self.assertTrue(obj, "'{}' failed".format(operation))
@@ -374,9 +365,12 @@ class DraftCreation(test_base.DraftTestCaseDoc):
box = obj.Shape.BoundBox
# A rather high tolerance is required.
obj_is_ok = (box.Center.isEqual(Vector(length/2, width/2, 0), 1e-6)
and math.isclose(box.XLength, length, rel_tol=0, abs_tol=1e-6)
and math.isclose(box.YLength, width, rel_tol=0, abs_tol=1e-6))
obj_is_ok = (
box.Center.isEqual(Vector(length / 2, width / 2, 0), 1e-6)
and math.isclose(box.XLength, length, rel_tol=0, abs_tol=1e-6)
and math.isclose(box.YLength, width, rel_tol=0, abs_tol=1e-6)
)
self.assertTrue(obj_is_ok, "'{}' failed".format(operation))
## @}

View File

@@ -43,18 +43,38 @@ class TestDraftGeomUtils(test_base.DraftTestCaseNoDoc):
try:
extended = DraftGeomUtils.get_extended_wire(wire, offset_start, offset_end)
# Test that the extended wire's length is correctly changed
self.assertAlmostEqual(extended.Length, wire.Length + offset_start + offset_end,
DraftGeomUtils.precision(), "'start={0}, end={1}' failed".format(offset_start, offset_end))
self.assertAlmostEqual(
extended.Length,
wire.Length + offset_start + offset_end,
DraftGeomUtils.precision(),
"'start={0}, end={1}' failed".format(offset_start, offset_end),
)
if offset_start == 0.0:
# If offset_start is 0.0, check that the wire's start point is unchanged
self.assertAlmostEqual(extended.OrderedVertexes[0].Point.distanceToPoint(wire.OrderedVertexes[0].Point), 0.0,
DraftGeomUtils.precision(), "'start={0}, end={1}' failed".format(offset_start, offset_end))
self.assertAlmostEqual(
extended.OrderedVertexes[0].Point.distanceToPoint(
wire.OrderedVertexes[0].Point
),
0.0,
DraftGeomUtils.precision(),
"'start={0}, end={1}' failed".format(offset_start, offset_end),
)
if offset_end == 0.0:
# If offset_end is 0.0, check that the wire's end point is unchanged
self.assertAlmostEqual(extended.OrderedVertexes[-1].Point.distanceToPoint(wire.OrderedVertexes[-1].Point), 0.0,
DraftGeomUtils.precision(), "'start={0}, end={1}' failed".format(offset_start, offset_end))
self.assertAlmostEqual(
extended.OrderedVertexes[-1].Point.distanceToPoint(
wire.OrderedVertexes[-1].Point
),
0.0,
DraftGeomUtils.precision(),
"'start={0}, end={1}' failed".format(offset_start, offset_end),
)
except Exception as exc:
print ("get_extended_wire failed for 'start={0}, end={1}'".format(offset_start, offset_end))
print(
"get_extended_wire failed for 'start={0}, end={1}'".format(
offset_start, offset_end
)
)
raise exc
def test_get_extended_wire1(self):
@@ -63,10 +83,12 @@ class TestDraftGeomUtils(test_base.DraftTestCaseNoDoc):
_msg(" Test '{}'".format(operation))
# Build wires made with straight edges and various combination of Orientation: the wires 1-4 are all equivalent
points = [Vector(0.0, 0.0, 0.0),
Vector(1500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 2500.0)]
points = [
Vector(0.0, 0.0, 0.0),
Vector(1500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 2500.0),
]
edges = []
for start, end in zip(points[:-1], points[1:]):
@@ -81,10 +103,12 @@ class TestDraftGeomUtils(test_base.DraftTestCaseNoDoc):
_msg(" Test '{}'".format(operation))
# Build wires made with straight edges and various combination of Orientation: the wires 1-4 are all equivalent
points = [Vector(0.0, 0.0, 0.0),
Vector(1500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 2500.0)]
points = [
Vector(0.0, 0.0, 0.0),
Vector(1500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 2500.0),
]
edges = []
for start, end in zip(points[:-1], points[1:]):
@@ -100,10 +124,12 @@ class TestDraftGeomUtils(test_base.DraftTestCaseNoDoc):
_msg(" Test '{}'".format(operation))
# Build wires made with straight edges and various combination of Orientation: the wires 1-4 are all equivalent
points = [Vector(0.0, 0.0, 0.0),
Vector(1500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 2500.0)]
points = [
Vector(0.0, 0.0, 0.0),
Vector(1500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 2500.0),
]
edges = []
for start, end in zip(points[:-1], points[1:]):
@@ -120,10 +146,12 @@ class TestDraftGeomUtils(test_base.DraftTestCaseNoDoc):
_msg(" Test '{}'".format(operation))
# Build wires made with straight edges and various combination of Orientation: the wires 1-4 are all equivalent
points = [Vector(0.0, 0.0, 0.0),
Vector(1500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 2500.0)]
points = [
Vector(0.0, 0.0, 0.0),
Vector(1500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 0.0),
Vector(4500.0, 2000.0, 2500.0),
]
edges = []
for start, end in zip(points[:-1], points[1:]):
@@ -139,11 +167,13 @@ class TestDraftGeomUtils(test_base.DraftTestCaseNoDoc):
_msg(" Test '{}'".format(operation))
# Build wires made with arcs and various combination of Orientation: the wires 5-8 are all equivalent
points = [Vector(0.0, 0.0, 0.0),
Vector(1000.0, 1000.0, 0.0),
Vector(2000.0, 0.0, 0.0),
Vector(3000.0, 0.0, 1000.0),
Vector(4000.0, 0.0, 0.0)]
points = [
Vector(0.0, 0.0, 0.0),
Vector(1000.0, 1000.0, 0.0),
Vector(2000.0, 0.0, 0.0),
Vector(3000.0, 0.0, 1000.0),
Vector(4000.0, 0.0, 0.0),
]
edges = []
for start, mid, end in zip(points[:-2], points[1:-1], points[2:]):
@@ -158,11 +188,13 @@ class TestDraftGeomUtils(test_base.DraftTestCaseNoDoc):
_msg(" Test '{}'".format(operation))
# Build wires made with arcs and various combination of Orientation: the wires 5-8 are all equivalent
points = [Vector(0.0, 0.0, 0.0),
Vector(1000.0, 1000.0, 0.0),
Vector(2000.0, 0.0, 0.0),
Vector(3000.0, 0.0, 1000.0),
Vector(4000.0, 0.0, 0.0)]
points = [
Vector(0.0, 0.0, 0.0),
Vector(1000.0, 1000.0, 0.0),
Vector(2000.0, 0.0, 0.0),
Vector(3000.0, 0.0, 1000.0),
Vector(4000.0, 0.0, 0.0),
]
edges = []
for start, mid, end in zip(points[:-2], points[1:-1], points[2:]):
@@ -178,11 +210,13 @@ class TestDraftGeomUtils(test_base.DraftTestCaseNoDoc):
_msg(" Test '{}'".format(operation))
# Build wires made with arcs and various combination of Orientation: the wires 5-8 are all equivalent
points = [Vector(0.0, 0.0, 0.0),
Vector(1000.0, 1000.0, 0.0),
Vector(2000.0, 0.0, 0.0),
Vector(3000.0, 0.0, 1000.0),
Vector(4000.0, 0.0, 0.0)]
points = [
Vector(0.0, 0.0, 0.0),
Vector(1000.0, 1000.0, 0.0),
Vector(2000.0, 0.0, 0.0),
Vector(3000.0, 0.0, 1000.0),
Vector(4000.0, 0.0, 0.0),
]
edges = []
for start, mid, end in zip(points[:-2], points[1:-1], points[2:]):
@@ -199,11 +233,13 @@ class TestDraftGeomUtils(test_base.DraftTestCaseNoDoc):
_msg(" Test '{}'".format(operation))
# Build wires made with arcs and various combination of Orientation: the wires 5-8 are all equivalent
points = [Vector(0.0, 0.0, 0.0),
Vector(1000.0, 1000.0, 0.0),
Vector(2000.0, 0.0, 0.0),
Vector(3000.0, 0.0, 1000.0),
Vector(4000.0, 0.0, 0.0)]
points = [
Vector(0.0, 0.0, 0.0),
Vector(1000.0, 1000.0, 0.0),
Vector(2000.0, 0.0, 0.0),
Vector(3000.0, 0.0, 1000.0),
Vector(4000.0, 0.0, 0.0),
]
edges = []
for start, mid, end in zip(points[:-2], points[1:-1], points[2:]):
@@ -213,5 +249,6 @@ class TestDraftGeomUtils(test_base.DraftTestCaseNoDoc):
wire.Orientation = "Reversed"
self.check_wire(wire)
# suite = unittest.defaultTestLoader.loadTestsFromTestCase(TestDraftGeomUtils)
# unittest.TextTestRunner().run(suite)

View File

@@ -70,4 +70,5 @@ class DraftDWG(test_base.DraftTestCaseDoc):
obj = aux.fake_function(out_file)
self.assertTrue(obj, "'{}' failed".format(operation))
## @}

View File

@@ -71,4 +71,5 @@ class DraftDXF(test_base.DraftTestCaseDoc):
obj = aux.fake_function(out_file)
self.assertTrue(obj, "'{}' failed".format(operation))
## @}

View File

@@ -63,4 +63,5 @@ class DraftImport(test_base.DraftTestCaseNoDoc):
imported = aux.import_test(module)
self.assertTrue(imported, "Problem importing '{}'".format(module))
## @}

View File

@@ -63,4 +63,5 @@ class DraftGuiImport(test_base.DraftTestCaseNoDoc):
imported = aux.import_test(module)
self.assertTrue(imported, "Problem importing '{}'".format(module))
## @}

View File

@@ -56,4 +56,5 @@ class DraftImportTools(test_base.DraftTestCaseNoDoc):
imported = aux.import_test(module)
self.assertTrue(imported, "Problem importing '{}'".format(module))
## @}

View File

@@ -60,8 +60,7 @@ class DraftModification(test_base.DraftTestCaseDoc):
_msg(" c={}".format(c))
Draft.move(obj, c)
self.doc.recompute()
self.assertTrue(obj.Start.isEqual(Vector(3, 3, 0), 1e-6),
"'{}' failed".format(operation))
self.assertTrue(obj.Start.isEqual(Vector(3, 3, 0), 1e-6), "'{}' failed".format(operation))
def test_copy(self):
"""Create a line, then copy and move it."""
@@ -96,8 +95,7 @@ class DraftModification(test_base.DraftTestCaseDoc):
_msg(" angle={} degrees".format(rot))
Draft.rotate(obj, rot)
self.doc.recompute()
self.assertTrue(obj.Start.isEqual(c, 1e-6),
"'{}' failed".format(operation))
self.assertTrue(obj.Start.isEqual(c, 1e-6), "'{}' failed".format(operation))
def test_offset_open(self):
"""Create an open wire, then produce an offset copy."""
@@ -129,10 +127,7 @@ class DraftModification(test_base.DraftTestCaseDoc):
b = Vector(10, 0, 0)
c = Vector(10, 4, 0)
d = Vector(0, 4, 0)
edges = [Part.makeLine(a, b),
Part.makeLine(b, c),
Part.makeLine(c, d),
Part.makeLine(a, d)]
edges = [Part.makeLine(a, b), Part.makeLine(b, c), Part.makeLine(c, d), Part.makeLine(a, d)]
wire = Part.Wire(edges)
obj = self.doc.addObject("Part::Feature")
obj.Shape = wire
@@ -160,9 +155,9 @@ class DraftModification(test_base.DraftTestCaseDoc):
_msg(" vector={}".format(offset))
obj = Draft.offset(rect, offset, copy=True)
self.doc.recompute()
obj_is_ok = (obj.Shape.CenterOfGravity == Vector(5, 2, 0)
and obj.Length == 12
and obj.Height == 6)
obj_is_ok = (
obj.Shape.CenterOfGravity == Vector(5, 2, 0) and obj.Length == 12 and obj.Height == 6
)
self.assertTrue(obj_is_ok, "'{}' failed".format(operation))
def test_trim(self):
@@ -335,8 +330,7 @@ class DraftModification(test_base.DraftTestCaseDoc):
obj3 = Draft.downgrade(obj2[0], delete=True)
self.doc.recompute()
s3 = obj3[0][0]
_msg(" 3: Result 3 x '{0}' ({1})".format(s3.Shape.ShapeType,
s3.TypeId))
_msg(" 3: Result 3 x '{0}' ({1})".format(s3.Shape.ShapeType, s3.TypeId))
self.assertTrue(len(obj3[0]) == 3, "'{}' failed".format(operation))
# edges cannot be downgraded
@@ -376,7 +370,7 @@ class DraftModification(test_base.DraftTestCaseDoc):
prism.Polygon = 5
# Rotate the prism 45 degrees around the Y axis
prism.Placement.Rotation.Axis = Vector(0, 1, 0)
prism.Placement.Rotation.Angle = 45 * (3.14159/180)
prism.Placement.Rotation.Angle = 45 * (3.14159 / 180)
_msg(" Prism")
_msg(" n_sides={}".format(prism.Polygon))
_msg(" placement={}".format(prism.Placement))
@@ -402,14 +396,12 @@ class DraftModification(test_base.DraftTestCaseDoc):
obj = Draft.make_sketch(wire, autoconstraints=True)
self.doc.recompute()
_msg(" 1: Result '{0}' ({1})".format(obj.Shape.ShapeType,
obj.TypeId))
_msg(" 1: Result '{0}' ({1})".format(obj.Shape.ShapeType, obj.TypeId))
self.assertTrue(obj, "'{}' failed".format(operation))
obj2 = Draft.draftify(obj, delete=False)
self.doc.recompute()
_msg(" 2: Result '{0}' ({1})".format(obj2.Proxy.Type,
obj2.TypeId))
_msg(" 2: Result '{0}' ({1})".format(obj2.Proxy.Type, obj2.TypeId))
self.assertTrue(obj2, "'{}' failed".format(operation))
def test_rectangular_array(self):
@@ -433,12 +425,8 @@ class DraftModification(test_base.DraftTestCaseDoc):
_msg(" direction_x={}".format(dir_x))
_msg(" direction_y={}".format(dir_y))
_msg(" direction_z={}".format(dir_z))
_msg(" number_x={0}, number_y={1}, number_z={2}".format(number_x,
number_y,
number_z))
obj = Draft.make_ortho_array(rect,
dir_x, dir_y, dir_z,
number_x, number_y, number_z)
_msg(" number_x={0}, number_y={1}, number_z={2}".format(number_x, number_y, number_z))
obj = Draft.make_ortho_array(rect, dir_x, dir_y, dir_z, number_x, number_y, number_z)
self.assertTrue(obj, "'{}' failed".format(operation))
def test_polar_array(self):
@@ -458,8 +446,7 @@ class DraftModification(test_base.DraftTestCaseDoc):
_msg(" Array")
_msg(" number={0}, polar_angle={1}".format(number, angle))
_msg(" center={}".format(center))
obj = Draft.make_polar_array(rect,
number, angle, center)
obj = Draft.make_polar_array(rect, number, angle, center)
self.assertTrue(obj, "'{}' failed".format(operation))
def test_circular_array(self):
@@ -480,15 +467,13 @@ class DraftModification(test_base.DraftTestCaseDoc):
number = 3
symmetry = 1
_msg(" Array")
_msg(" radial_distance={0}, "
"tangential_distance={1}".format(rad_distance, tan_distance))
_msg(" radial_distance={0}, " "tangential_distance={1}".format(rad_distance, tan_distance))
_msg(" number={0}, symmetry={1}".format(number, symmetry))
_msg(" axis={}".format(axis))
_msg(" center={}".format(center))
obj = Draft.make_circular_array(rect,
rad_distance, tan_distance,
number, symmetry,
axis, center)
obj = Draft.make_circular_array(
rect, rad_distance, tan_distance, number, symmetry, axis, center
)
self.assertTrue(obj, "'{}' failed".format(operation))
def test_path_array(self):
@@ -517,8 +502,7 @@ class DraftModification(test_base.DraftTestCaseDoc):
_msg(" Path Array")
_msg(" number={}, translation={}".format(number, translation))
_msg(" subelements={}, align={}".format(subelements, align))
obj = Draft.make_path_array(poly, wire, number,
translation, subelements, align)
obj = Draft.make_path_array(poly, wire, number, translation, subelements, align)
self.assertTrue(obj, "'{}' failed".format(operation))
def test_point_array(self):
@@ -532,10 +516,12 @@ class DraftModification(test_base.DraftTestCaseDoc):
_msg(" Points")
_msg(" a={0}, b={1}".format(a, b))
_msg(" c={0}, d={1}".format(c, d))
points = [Draft.make_point(a),
Draft.make_point(b),
Draft.make_point(c),
Draft.make_point(d)]
points = [
Draft.make_point(a),
Draft.make_point(b),
Draft.make_point(c),
Draft.make_point(d),
]
_msg(" Upgrade")
add, delete = Draft.upgrade(points)
@@ -565,8 +551,7 @@ class DraftModification(test_base.DraftTestCaseDoc):
obj = Draft.make_clone(box)
_msg(" clone: '{0}' ({1})".format(obj.Proxy.Type, obj.TypeId))
self.assertTrue(obj, "'{}' failed".format(operation))
self.assertTrue(obj.hasExtension("Part::AttachExtension"),
"'{}' failed".format(operation))
self.assertTrue(obj.hasExtension("Part::AttachExtension"), "'{}' failed".format(operation))
def test_attached_clone_behavior(self):
"""Check if an attached clone behaves correctly.
@@ -599,7 +584,7 @@ class DraftModification(test_base.DraftTestCaseDoc):
prism.Polygon = 5
# Rotate the prism 45 degrees around the Y axis
prism.Placement.Rotation.Axis = Vector(0, 1, 0)
prism.Placement.Rotation.Angle = 45 * (3.14159/180)
prism.Placement.Rotation.Angle = 45 * (3.14159 / 180)
_msg(" Prism")
_msg(" n_sides={}".format(prism.Polygon))
_msg(" placement={}".format(prism.Placement))
@@ -607,8 +592,9 @@ class DraftModification(test_base.DraftTestCaseDoc):
page = self.doc.addObject("TechDraw::DrawPage")
_msg(" page={}".format(page.TypeId))
template = self.doc.addObject("TechDraw::DrawSVGTemplate")
template.Template = App.getResourceDir() \
+ "Mod/TechDraw/Templates/ISO/A3_Landscape_blank.svg"
template.Template = (
App.getResourceDir() + "Mod/TechDraw/Templates/ISO/A3_Landscape_blank.svg"
)
page.Template = template
_msg(" template={}".format(template.TypeId))
view = self.doc.addObject("TechDraw::DrawViewDraft")
@@ -659,21 +645,29 @@ class DraftModification(test_base.DraftTestCaseDoc):
_msg(" Test '{}'".format(operation))
base = Vector(3.5, 2.5, 0.0)
cen = Vector(2.0, 1.0, 0.0) # center for scaling
cen = Vector(2.0, 1.0, 0.0) # center for scaling
sca = Vector(2.0, 3.0, 1.0)
ends = [Vector(0.0, 0.0, 0.0),
Vector(4.0, 0.0, 0.0),
Vector(4.0, 3.0, 0.0),
Vector(0.0, 3.0, 0.0)]
mids = [Vector( 2.0, -0.5, 0.0),
Vector( 4.5, 1.5, 0.0),
Vector( 2.0, 3.5, 0.0),
Vector(-0.5, 1.5, 0.0)] # arc midpoints
ends = [
Vector(0.0, 0.0, 0.0),
Vector(4.0, 0.0, 0.0),
Vector(4.0, 3.0, 0.0),
Vector(0.0, 3.0, 0.0),
]
mids = [
Vector(2.0, -0.5, 0.0),
Vector(4.5, 1.5, 0.0),
Vector(2.0, 3.5, 0.0),
Vector(-0.5, 1.5, 0.0),
] # arc midpoints
shp = Part.Shape([Part.Arc(ends[0], mids[0], ends[1]),
Part.Arc(ends[1], mids[1], ends[2]),
Part.Arc(ends[2], mids[2], ends[3]),
Part.Arc(ends[3], mids[3], ends[0])])
shp = Part.Shape(
[
Part.Arc(ends[0], mids[0], ends[1]),
Part.Arc(ends[1], mids[1], ends[2]),
Part.Arc(ends[2], mids[2], ends[3]),
Part.Arc(ends[3], mids[3], ends[0]),
]
)
obj = self.doc.addObject("Part::Feature")
obj.Shape = shp
obj.Placement.Base = base
@@ -682,24 +676,30 @@ class DraftModification(test_base.DraftTestCaseDoc):
self.doc.recompute()
# check endpoints of arcs:
newEnds = [Vector( 5.0, 5.5, 0.0),
Vector(13.0, 5.5, 0.0),
Vector(13.0, 14.5, 0.0),
Vector( 5.0, 14.5, 0.0)]
newEnds = [
Vector(5.0, 5.5, 0.0),
Vector(13.0, 5.5, 0.0),
Vector(13.0, 14.5, 0.0),
Vector(5.0, 14.5, 0.0),
]
vrts = obj.Shape.Vertexes
for i in range(4):
self.assertTrue(vrts[i].Point.isEqual(newEnds[i], 1e-6),
"'{}' failed".format(operation))
self.assertTrue(
vrts[i].Point.isEqual(newEnds[i], 1e-6), "'{}' failed".format(operation)
)
# check midpoints of arcs:
newMids = [Vector( 9.0, 4.0, 0.0),
Vector(14.0, 10.0, 0.0),
Vector( 9.0, 16.0, 0.0),
Vector( 4.0, 10.0, 0.0)]
newMids = [
Vector(9.0, 4.0, 0.0),
Vector(14.0, 10.0, 0.0),
Vector(9.0, 16.0, 0.0),
Vector(4.0, 10.0, 0.0),
]
for i in range(4):
edge = obj.Shape.Edges[i]
par = (edge.LastParameter - edge.FirstParameter) / 2.0
self.assertTrue(edge.valueAt(par).isEqual(newMids[i], 1e-6),
"'{}' failed".format(operation))
self.assertTrue(
edge.valueAt(par).isEqual(newMids[i], 1e-6), "'{}' failed".format(operation)
)
def test_scale_part_feature_lines(self):
"""Create and scale a part feature (lines)."""
@@ -707,17 +707,23 @@ class DraftModification(test_base.DraftTestCaseDoc):
_msg(" Test '{}'".format(operation))
base = Vector(3.5, 2.5, 0.0)
cen = Vector(2.0, 1.0, 0.0) # center for scaling
cen = Vector(2.0, 1.0, 0.0) # center for scaling
sca = Vector(2.0, 3.0, 1.0)
pts = [Vector(0.0, 0.0, 0.0),
Vector(4.0, 0.0, 0.0),
Vector(4.0, 3.0, 0.0),
Vector(0.0, 3.0, 0.0)]
pts = [
Vector(0.0, 0.0, 0.0),
Vector(4.0, 0.0, 0.0),
Vector(4.0, 3.0, 0.0),
Vector(0.0, 3.0, 0.0),
]
shp = Part.Shape([Part.LineSegment(pts[0], pts[1]),
Part.LineSegment(pts[1], pts[2]),
Part.LineSegment(pts[2], pts[3]),
Part.LineSegment(pts[3], pts[0])])
shp = Part.Shape(
[
Part.LineSegment(pts[0], pts[1]),
Part.LineSegment(pts[1], pts[2]),
Part.LineSegment(pts[2], pts[3]),
Part.LineSegment(pts[3], pts[0]),
]
)
obj = self.doc.addObject("Part::Feature")
obj.Shape = shp
obj.Placement.Base = base
@@ -725,14 +731,15 @@ class DraftModification(test_base.DraftTestCaseDoc):
obj = Draft.scale(obj, sca, cen, False)
self.doc.recompute()
newPts = [Vector( 5.0, 5.5, 0.0),
Vector(13.0, 5.5, 0.0),
Vector(13.0, 14.5, 0.0),
Vector( 5.0, 14.5, 0.0)]
newPts = [
Vector(5.0, 5.5, 0.0),
Vector(13.0, 5.5, 0.0),
Vector(13.0, 14.5, 0.0),
Vector(5.0, 14.5, 0.0),
]
vrts = obj.Shape.Vertexes
for i in range(4):
self.assertTrue(vrts[i].Point.isEqual(newPts[i], 1e-6),
"'{}' failed".format(operation))
self.assertTrue(vrts[i].Point.isEqual(newPts[i], 1e-6), "'{}' failed".format(operation))
def test_scale_rectangle(self):
"""Create and scale a rectangle."""
@@ -740,7 +747,7 @@ class DraftModification(test_base.DraftTestCaseDoc):
_msg(" Test '{}'".format(operation))
base = Vector(3.5, 2.5, 0.0)
cen = Vector(2.0, 1.0, 0.0) # center for scaling
cen = Vector(2.0, 1.0, 0.0) # center for scaling
sca = Vector(2.0, 3.0, 1.0)
len = 4.0
hgt = 3.0
@@ -754,16 +761,9 @@ class DraftModification(test_base.DraftTestCaseDoc):
newBase = Vector(5.0, 5.5, 0.0)
newLen = 8.0
newHgt = 9.0
self.assertTrue(obj.Placement.Base.isEqual(newBase, 1e-6),
"'{}' failed".format(operation))
self.assertAlmostEqual(obj.Length,
newLen,
delta = 1e-6,
msg = "'{}' failed".format(operation))
self.assertAlmostEqual(obj.Height,
newHgt,
delta = 1e-6,
msg = "'{}' failed".format(operation))
self.assertTrue(obj.Placement.Base.isEqual(newBase, 1e-6), "'{}' failed".format(operation))
self.assertAlmostEqual(obj.Length, newLen, delta=1e-6, msg="'{}' failed".format(operation))
self.assertAlmostEqual(obj.Height, newHgt, delta=1e-6, msg="'{}' failed".format(operation))
def test_scale_spline(self):
"""Create and scale a spline."""
@@ -771,11 +771,9 @@ class DraftModification(test_base.DraftTestCaseDoc):
_msg(" Test '{}'".format(operation))
base = Vector(3.5, 2.5, 0.0)
cen = Vector(2.0, 1.0, 0.0) # center for scaling
cen = Vector(2.0, 1.0, 0.0) # center for scaling
sca = Vector(2.0, 3.0, 1.0)
pts = [Vector(0.0, 0.0, 0.0),
Vector(2.0, 3.0, 0.0),
Vector(4.0, 0.0, 0.0)]
pts = [Vector(0.0, 0.0, 0.0), Vector(2.0, 3.0, 0.0), Vector(4.0, 0.0, 0.0)]
obj = Draft.make_bspline(pts, False)
obj.Placement.Base = base
@@ -784,12 +782,11 @@ class DraftModification(test_base.DraftTestCaseDoc):
self.doc.recompute()
pla = obj.Placement
newPts = [Vector( 5.0, 5.5, 0.0),
Vector( 9.0, 14.5, 0.0),
Vector(13.0, 5.5, 0.0)]
newPts = [Vector(5.0, 5.5, 0.0), Vector(9.0, 14.5, 0.0), Vector(13.0, 5.5, 0.0)]
for i in range(3):
self.assertTrue(pla.multVec(obj.Points[i]).isEqual(newPts[i], 1e-6),
"'{}' failed".format(operation))
self.assertTrue(
pla.multVec(obj.Points[i]).isEqual(newPts[i], 1e-6), "'{}' failed".format(operation)
)
def test_scale_wire(self):
"""Create and scale a wire."""
@@ -797,12 +794,14 @@ class DraftModification(test_base.DraftTestCaseDoc):
_msg(" Test '{}'".format(operation))
base = Vector(3.5, 2.5, 0.0)
cen = Vector(2.0, 1.0, 0.0) # center for scaling
cen = Vector(2.0, 1.0, 0.0) # center for scaling
sca = Vector(2.0, 3.0, 1.0)
pts = [Vector(0.0, 0.0, 0.0),
Vector(4.0, 0.0, 0.0),
Vector(4.0, 3.0, 0.0),
Vector(0.0, 3.0, 0.0)]
pts = [
Vector(0.0, 0.0, 0.0),
Vector(4.0, 0.0, 0.0),
Vector(4.0, 3.0, 0.0),
Vector(0.0, 3.0, 0.0),
]
obj = Draft.make_wire(pts, True)
obj.Placement.Base = base
@@ -810,13 +809,15 @@ class DraftModification(test_base.DraftTestCaseDoc):
obj = Draft.scale(obj, sca, cen, False)
self.doc.recompute()
newPts = [Vector( 5.0, 5.5, 0.0),
Vector(13.0, 5.5, 0.0),
Vector(13.0, 14.5, 0.0),
Vector( 5.0, 14.5, 0.0)]
newPts = [
Vector(5.0, 5.5, 0.0),
Vector(13.0, 5.5, 0.0),
Vector(13.0, 14.5, 0.0),
Vector(5.0, 14.5, 0.0),
]
vrts = obj.Shape.Vertexes
for i in range(4):
self.assertTrue(vrts[i].Point.isEqual(newPts[i], 1e-6),
"'{}' failed".format(operation))
self.assertTrue(vrts[i].Point.isEqual(newPts[i], 1e-6), "'{}' failed".format(operation))
## @}

View File

@@ -71,4 +71,5 @@ class DraftOCA(test_base.DraftTestCaseDoc):
obj = aux.fake_function(out_file)
self.assertTrue(obj, "'{}' failed".format(operation))
## @}

View File

@@ -50,10 +50,12 @@ class DraftPivy(test_base.DraftTestCaseDoc):
def test_pivy_draw(self):
"""Use Coin (pivy.coin) to draw a cube on the active view."""
import pivy.coin as coin
cube = coin.SoCube()
_msg(" Draw cube")
Gui.getDocument(self.doc).ActiveView.getSceneGraph().addChild(cube)
_msg(" Adding cube to the active view scene")
self.assertTrue(cube, "Pivy is not working properly.")
## @}

View File

@@ -100,4 +100,5 @@ class DraftSVG(test_base.DraftTestCaseDoc):
else:
self.fail("no exception thrown")
## @}