Path: Split up TestRefactoredTestPost.py; fixed lint errors.

This commit is contained in:
LarryWoestman
2022-08-02 15:40:18 -07:00
committed by LarryWoestman
parent d1d6f9d13a
commit 501b1cdebd
7 changed files with 1493 additions and 1191 deletions

View File

@@ -330,6 +330,8 @@ SET(PathTests_SRCS
PathTests/TestRefactoredLinuxCNCPost.py
PathTests/TestRefactoredMach3Mach4Post.py
PathTests/TestRefactoredTestPost.py
PathTests/TestRefactoredTestPostGCodes.py
PathTests/TestRefactoredTestPostMCodes.py
PathTests/Tools/Bit/test-path-tool-bit-bit-00.fctb
PathTests/Tools/Library/test-path-tool-bit-library-00.fctl
PathTests/Tools/Shape/test-path-tool-bit-shape-00.fcstd

View File

@@ -142,7 +142,10 @@ def init_shared_arguments(
arguments_visible["axis-modal"],
)
if arguments_visible["axis-precision"]:
help_message = f'Number of digits of precision for axis moves, default is {str(values["DEFAULT_AXIS_PRECISION"])}'
help_message = (
f"Number of digits of precision for axis moves, "
f'default is {str(values["DEFAULT_AXIS_PRECISION"])}'
)
else:
help_message = argparse.SUPPRESS
shared.add_argument(
@@ -156,7 +159,10 @@ def init_shared_arguments(
argument_defaults["bcnc"],
"--bcnc",
"--no-bcnc",
"Add Job operations as bCNC block headers. Consider suppressing comments by adding --no-comments",
(
"Add Job operations as bCNC block headers. "
"Consider suppressing comments by adding --no-comments"
),
"Suppress bCNC block header output",
arguments_visible["bcnc"],
)
@@ -170,7 +176,10 @@ def init_shared_arguments(
arguments_visible["comments"],
)
if arguments_visible["feed-precision"]:
help_message = f'Number of digits of precision for feed rate, default is {str(values["DEFAULT_FEED_PRECISION"])}'
help_message = (
f"Number of digits of precision for feed rate, "
f'default is {str(values["DEFAULT_FEED_PRECISION"])}'
)
else:
help_message = argparse.SUPPRESS
shared.add_argument(
@@ -225,12 +234,18 @@ def init_shared_arguments(
arguments_visible["output_visible_arguments"],
)
if arguments_visible["postamble"]:
help_message = f'Set commands to be issued after the last command, default is "{values["POSTAMBLE"]}"'
help_message = (
f"Set commands to be issued after the last command, "
f'default is "{values["POSTAMBLE"]}"'
)
else:
help_message = argparse.SUPPRESS
shared.add_argument("--postamble", help=help_message)
if arguments_visible["preamble"]:
help_message = f'Set commands to be issued before the first command, default is "{values["PREAMBLE"]}"'
help_message = (
f"Set commands to be issued before the first command, "
f'default is "{values["PREAMBLE"]}"'
)
else:
help_message = argparse.SUPPRESS
shared.add_argument("--preamble", help=help_message)
@@ -239,7 +254,11 @@ def init_shared_arguments(
# --axis-precision value "wins". If both --feed-precision and --precision are
# provided, the --feed-precision value "wins".
if arguments_visible["precision"]:
help_message = f'Number of digits of precision for both feed rate and axis moves, default is {str(values["DEFAULT_AXIS_PRECISION"])} for metric or {str(values["DEFAULT_INCH_AXIS_PRECISION"])} for inches'
help_message = (
f"Number of digits of precision for both feed rate and axis "
f'moves, default is {str(values["DEFAULT_AXIS_PRECISION"])} for metric or '
f'{str(values["DEFAULT_INCH_AXIS_PRECISION"])} for inches'
)
else:
help_message = argparse.SUPPRESS
shared.add_argument(
@@ -249,7 +268,10 @@ def init_shared_arguments(
help=help_message,
)
if arguments_visible["return-to"]:
help_message = "Move to the specified x,y,z coordinates at the end, e.g. --return-to=0,0,0 (default is do not move)"
help_message = (
"Move to the specified x,y,z coordinates at the end, e.g. "
"--return-to=0,0,0 (default is do not move)"
)
else:
help_message = argparse.SUPPRESS
shared.add_argument("--return-to", default="", help=help_message)
@@ -715,7 +737,7 @@ def process_shared_arguments(
if args.wait_for_spindle > 0.0:
values["SPINDLE_WAIT"] = args.wait_for_spindle
except Exception:
except (ArithmeticError, LookupError):
return (False, "")
return (True, args)

View File

@@ -182,7 +182,7 @@ global_parser: Parser = init_arguments(
#
# The TOOLTIP_ARGS value is created from the help information about the arguments.
#
TOOLTIP_ARGS = global_parser.format_help()
TOOLTIP_ARGS: str = global_parser.format_help()
#
# Create another parser just to get a list of all possible arguments
# that may be output using --output_all_arguments.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,186 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * Copyright (c) 2022 sliptonic <shopinthewoods@gmail.com> *
# * Copyright (c) 2022 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) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import FreeCAD
import Path
import PathTests.PathTestUtils as PathTestUtils
from Path.Post.scripts import refactored_test_post as postprocessor
Path.Log.setLevel(Path.Log.Level.DEBUG, Path.Log.thisModule())
Path.Log.trackModule(Path.Log.thisModule())
class TestRefactoredTestPostMCodes(PathTestUtils.PathTestBase):
"""Test the refactored_test_post.py postprocessor."""
@classmethod
def setUpClass(cls):
"""setUpClass()...
This method is called upon instantiation of this test class. Add code
and objects here that are needed for the duration of the test() methods
in this class. In other words, set up the 'global' test environment
here; use the `setUp()` method to set up a 'local' test environment.
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")
@classmethod
def tearDownClass(cls):
"""tearDownClass()...
This method is called prior to destruction of this test class. Add
code and objects here that cleanup the test environment after the
test() methods in this class have been executed. This method does
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)
# Setup and tear down methods called before and after each unit test
def setUp(self):
"""setUp()...
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")
#
# Re-initialize all of the values before doing a test.
#
postprocessor.UNITS = "G21"
postprocessor.init_values(postprocessor.global_values)
def tearDown(self):
"""tearDown()...
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")
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, "gcode.tmp", args)
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, "gcode.tmp", args)
if debug:
print(f"--------{nl}{gcode}--------{nl}")
self.assertEqual(gcode.splitlines()[2], expected)
#
# The tests are organized into groups:
#
# 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
# 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", "")
def test20010(self):
"""Test M1 command Generation."""
self.compare_third_line("M1", "M1", "")
self.compare_third_line("M01", "M01", "")
def test20020(self):
"""Test M2 command Generation."""
self.compare_third_line("M2", "M2", "")
self.compare_third_line("M02", "M02", "")
def test20030(self):
"""Test M3 command Generation."""
self.compare_third_line("M3", "M3", "")
self.compare_third_line("M03", "M03", "")
def test20040(self):
"""Test M4 command Generation."""
self.compare_third_line("M4", "M4", "")
self.compare_third_line("M04", "M04", "")
def test20050(self):
"""Test M5 command Generation."""
self.compare_third_line("M5", "M5", "")
self.compare_third_line("M05", "M05", "")
def test20060(self):
"""Test M6 command Generation."""
self.compare_third_line("M6", "M6", "")
self.compare_third_line("M06", "M06", "")
def test20070(self):
"""Test M7 command Generation."""
self.compare_third_line("M7", "M7", "")
self.compare_third_line("M07", "M07", "")
def test20080(self):
"""Test M8 command Generation."""
self.compare_third_line("M8", "M8", "")
self.compare_third_line("M08", "M08", "")
def test20090(self):
"""Test M9 command Generation."""
self.compare_third_line("M9", "M9", "")
self.compare_third_line("M09", "M09", "")
def test20300(self):
"""Test M30 command Generation."""
self.compare_third_line("M30", "M30", "")
def test20480(self):
"""Test M48 command Generation."""
self.compare_third_line("M48", "M48", "")
def test20490(self):
"""Test M49 command Generation."""
self.compare_third_line("M49", "M49", "")
def test20600(self):
"""Test M60 command Generation."""
self.compare_third_line("M60", "M60", "")

View File

@@ -72,6 +72,8 @@ from PathTests.TestRefactoredGrblPost import TestRefactoredGrblPost
from PathTests.TestRefactoredLinuxCNCPost import TestRefactoredLinuxCNCPost
from PathTests.TestRefactoredMach3Mach4Post import TestRefactoredMach3Mach4Post
from PathTests.TestRefactoredTestPost import TestRefactoredTestPost
from PathTests.TestRefactoredTestPostGCodes import TestRefactoredTestPostGCodes
from PathTests.TestRefactoredTestPostMCodes import TestRefactoredTestPostMCodes
# dummy usage to get flake8 and lgtm quiet
False if depthTestCases.__name__ else True
@@ -120,3 +122,5 @@ False if TestRefactoredGrblPost.__name__ else True
False if TestRefactoredLinuxCNCPost.__name__ else True
False if TestRefactoredMach3Mach4Post.__name__ else True
False if TestRefactoredTestPost.__name__ else True
False if TestRefactoredTestPostGCodes.__name__ else True
False if TestRefactoredTestPostMCodes.__name__ else True