CAM: converted the refactored* postprocessors to the new (more object-oriented) API (#19006)
* CAM: converted the refactored* postprocessors to the new API
with corresponding tests
* [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:
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2022 sliptonic <shopinthewoods@gmail.com> *
|
||||
# * Copyright (c) 2022-2023 Larry Woestman <LarryWoestman2@gmail.com> *
|
||||
# * Copyright (c) 2022-2025 Larry Woestman <LarryWoestman2@gmail.com> *
|
||||
# * *
|
||||
# * This program is free software; you can redistribute it and/or modify *
|
||||
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
@@ -25,7 +25,7 @@ import FreeCAD
|
||||
|
||||
import Path
|
||||
import CAMTests.PathTestUtils as PathTestUtils
|
||||
from Path.Post.scripts import refactored_test_post as postprocessor
|
||||
from Path.Post.Processor import PostProcessorFactory
|
||||
|
||||
|
||||
Path.Log.setLevel(Path.Log.Level.DEBUG, Path.Log.thisModule())
|
||||
@@ -46,8 +46,16 @@ class TestRefactoredTestPostMCodes(PathTestUtils.PathTestBase):
|
||||
This method does not have access to the class `self` reference, but it
|
||||
is able to call static methods within this same class.
|
||||
"""
|
||||
# Open existing FreeCAD document with test geometry
|
||||
FreeCAD.newDocument("Unnamed")
|
||||
FreeCAD.ConfigSet("SuppressRecomputeRequiredDialog", "True")
|
||||
cls.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/CAMTests/boxtest.fcstd")
|
||||
cls.job = cls.doc.getObject("Job")
|
||||
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_test")
|
||||
# locate the operation named "Profile"
|
||||
for op in cls.job.Operations.Group:
|
||||
if op.Label == "Profile":
|
||||
# remember the "Profile" operation
|
||||
cls.profile_op = op
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
@@ -59,8 +67,8 @@ class TestRefactoredTestPostMCodes(PathTestUtils.PathTestBase):
|
||||
not have access to the class `self` reference. This method is able
|
||||
to call static methods within this same class.
|
||||
"""
|
||||
# Close geometry document without saving
|
||||
FreeCAD.closeDocument(FreeCAD.ActiveDocument.Name)
|
||||
FreeCAD.closeDocument(cls.doc.Name)
|
||||
FreeCAD.ConfigSet("SuppressRecomputeRequiredDialog", "")
|
||||
|
||||
# Setup and tear down methods called before and after each unit test
|
||||
|
||||
@@ -70,14 +78,12 @@ class TestRefactoredTestPostMCodes(PathTestUtils.PathTestBase):
|
||||
This method is called prior to each `test()` method. Add code and
|
||||
objects here that are needed for multiple `test()` methods.
|
||||
"""
|
||||
self.doc = FreeCAD.ActiveDocument
|
||||
self.con = FreeCAD.Console
|
||||
self.docobj = FreeCAD.ActiveDocument.addObject("Path::Feature", "testpath")
|
||||
# allow a full length "diff" if an error occurs
|
||||
self.maxDiff = None
|
||||
#
|
||||
# Re-initialize all of the values before doing a test.
|
||||
# reinitialize the postprocessor data structures between tests
|
||||
#
|
||||
postprocessor.UNITS = "G21"
|
||||
postprocessor.init_values(postprocessor.global_values)
|
||||
self.post.reinitialize()
|
||||
|
||||
def tearDown(self):
|
||||
"""tearDown()...
|
||||
@@ -85,30 +91,20 @@ class TestRefactoredTestPostMCodes(PathTestUtils.PathTestBase):
|
||||
This method is called after each test() method. Add cleanup instructions here.
|
||||
Such cleanup instructions will likely undo those in the setUp() method.
|
||||
"""
|
||||
FreeCAD.ActiveDocument.removeObject("testpath")
|
||||
pass
|
||||
|
||||
def single_compare(self, path, expected, args, debug=False):
|
||||
"""Perform a test with a single comparison."""
|
||||
nl = "\n"
|
||||
self.docobj.Path = Path.Path(path)
|
||||
postables = [self.docobj]
|
||||
gcode = postprocessor.export(postables, "-", args)
|
||||
self.job.PostProcessorArgs = args
|
||||
# replace the original path (that came with the job and operation) with our path
|
||||
self.profile_op.Path = Path.Path(path)
|
||||
# the gcode is in the first section for this particular job and operation
|
||||
gcode = self.post.export()[0][1]
|
||||
if debug:
|
||||
print(f"--------{nl}{gcode}--------{nl}")
|
||||
self.assertEqual(gcode, expected)
|
||||
|
||||
def compare_third_line(self, path_string, expected, args, debug=False):
|
||||
"""Perform a test with a single comparison to the third line of the output."""
|
||||
nl = "\n"
|
||||
if path_string:
|
||||
self.docobj.Path = Path.Path([Path.Command(path_string)])
|
||||
else:
|
||||
self.docobj.Path = Path.Path([])
|
||||
postables = [self.docobj]
|
||||
gcode = postprocessor.export(postables, "-", args)
|
||||
if debug:
|
||||
print(f"--------{nl}{gcode}--------{nl}")
|
||||
self.assertEqual(gcode.splitlines()[2], expected)
|
||||
# there are 4 lines of "other stuff" before the line we are interested in
|
||||
self.assertEqual(gcode.splitlines()[4], expected)
|
||||
|
||||
#############################################################################
|
||||
#
|
||||
@@ -116,99 +112,100 @@ class TestRefactoredTestPostMCodes(PathTestUtils.PathTestBase):
|
||||
#
|
||||
# 00000 - 00099 tests that don't fit any other category
|
||||
# 00100 - 09999 tests for all of the various arguments/options
|
||||
# 10000 - 19999 tests for the various G codes at 10000 + 10 * g_code_value
|
||||
# 10000 - 18999 tests for the various G codes at 10000 + 10 * g_code_value
|
||||
# 19000 - 19999 tests for the A, B, and C axis outputs
|
||||
# 20000 - 29999 tests for the various M codes at 20000 + 10 * m_code_value
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
def test20000(self):
|
||||
"""Test M0 command Generation."""
|
||||
self.compare_third_line("M0", "M0", "")
|
||||
self.compare_third_line("M00", "M00", "")
|
||||
self.single_compare("M0", "M0", "")
|
||||
self.single_compare("M00", "M00", "")
|
||||
|
||||
#############################################################################
|
||||
|
||||
def test20010(self):
|
||||
"""Test M1 command Generation."""
|
||||
self.compare_third_line("M1", "M1", "")
|
||||
self.compare_third_line("M01", "M01", "")
|
||||
self.single_compare("M1", "M1", "")
|
||||
self.single_compare("M01", "M01", "")
|
||||
|
||||
#############################################################################
|
||||
|
||||
def test20020(self):
|
||||
"""Test M2 command Generation."""
|
||||
self.compare_third_line("M2", "M2", "")
|
||||
self.compare_third_line("M02", "M02", "")
|
||||
self.single_compare("M2", "M2", "")
|
||||
self.single_compare("M02", "M02", "")
|
||||
|
||||
#############################################################################
|
||||
|
||||
def test20030(self):
|
||||
"""Test M3 command Generation."""
|
||||
self.compare_third_line("M3", "M3", "")
|
||||
self.compare_third_line("M03", "M03", "")
|
||||
self.single_compare("M3", "M3", "")
|
||||
self.single_compare("M03", "M03", "")
|
||||
|
||||
#############################################################################
|
||||
|
||||
def test20040(self):
|
||||
"""Test M4 command Generation."""
|
||||
self.compare_third_line("M4", "M4", "")
|
||||
self.compare_third_line("M04", "M04", "")
|
||||
self.single_compare("M4", "M4", "")
|
||||
self.single_compare("M04", "M04", "")
|
||||
|
||||
#############################################################################
|
||||
|
||||
def test20050(self):
|
||||
"""Test M5 command Generation."""
|
||||
self.compare_third_line("M5", "M5", "")
|
||||
self.compare_third_line("M05", "M05", "")
|
||||
self.single_compare("M5", "M5", "")
|
||||
self.single_compare("M05", "M05", "")
|
||||
|
||||
#############################################################################
|
||||
|
||||
def test20060(self):
|
||||
"""Test M6 command Generation."""
|
||||
self.compare_third_line("M6", "M6", "")
|
||||
self.compare_third_line("M06", "M06", "")
|
||||
self.single_compare("M6", "M6", "")
|
||||
self.single_compare("M06", "M06", "")
|
||||
|
||||
#############################################################################
|
||||
|
||||
def test20070(self):
|
||||
"""Test M7 command Generation."""
|
||||
self.compare_third_line("M7", "M7", "")
|
||||
self.compare_third_line("M07", "M07", "")
|
||||
self.single_compare("M7", "M7", "")
|
||||
self.single_compare("M07", "M07", "")
|
||||
|
||||
#############################################################################
|
||||
|
||||
def test20080(self):
|
||||
"""Test M8 command Generation."""
|
||||
self.compare_third_line("M8", "M8", "")
|
||||
self.compare_third_line("M08", "M08", "")
|
||||
self.single_compare("M8", "M8", "")
|
||||
self.single_compare("M08", "M08", "")
|
||||
|
||||
#############################################################################
|
||||
|
||||
def test20090(self):
|
||||
"""Test M9 command Generation."""
|
||||
self.compare_third_line("M9", "M9", "")
|
||||
self.compare_third_line("M09", "M09", "")
|
||||
self.single_compare("M9", "M9", "")
|
||||
self.single_compare("M09", "M09", "")
|
||||
|
||||
#############################################################################
|
||||
|
||||
def test20300(self):
|
||||
"""Test M30 command Generation."""
|
||||
self.compare_third_line("M30", "M30", "")
|
||||
self.single_compare("M30", "M30", "")
|
||||
|
||||
#############################################################################
|
||||
|
||||
def test20480(self):
|
||||
"""Test M48 command Generation."""
|
||||
self.compare_third_line("M48", "M48", "")
|
||||
self.single_compare("M48", "M48", "")
|
||||
|
||||
#############################################################################
|
||||
|
||||
def test20490(self):
|
||||
"""Test M49 command Generation."""
|
||||
self.compare_third_line("M49", "M49", "")
|
||||
self.single_compare("M49", "M49", "")
|
||||
|
||||
#############################################################################
|
||||
|
||||
def test20600(self):
|
||||
"""Test M60 command Generation."""
|
||||
self.compare_third_line("M60", "M60", "")
|
||||
self.single_compare("M60", "M60", "")
|
||||
|
||||
Reference in New Issue
Block a user