2
# ***************************************************************************
3
# * Copyright (c) 2022 sliptonic <shopinthewoods@gmail.com> *
4
# * Copyright (c) 2022-2023 Larry Woestman <LarryWoestman2@gmail.com> *
6
# * This program is free software; you can redistribute it and/or modify *
7
# * it under the terms of the GNU Lesser General Public License (LGPL) *
8
# * as published by the Free Software Foundation; either version 2 of *
9
# * the License, or (at your option) any later version. *
10
# * for detail see the LICENCE text file. *
12
# * This program is distributed in the hope that it will be useful, *
13
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
# * GNU Library General Public License for more details. *
17
# * You should have received a copy of the GNU Library General Public *
18
# * License along with this program; if not, write to the Free Software *
19
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
22
# ***************************************************************************
27
import Tests.PathTestUtils as PathTestUtils
28
from Path.Post.scripts import refactored_test_post as postprocessor
31
Path.Log.setLevel(Path.Log.Level.DEBUG, Path.Log.thisModule())
32
Path.Log.trackModule(Path.Log.thisModule())
35
class TestRefactoredTestPostMCodes(PathTestUtils.PathTestBase):
36
"""Test the refactored_test_post.py postprocessor."""
42
This method is called upon instantiation of this test class. Add code
43
and objects here that are needed for the duration of the test() methods
44
in this class. In other words, set up the 'global' test environment
45
here; use the `setUp()` method to set up a 'local' test environment.
46
This method does not have access to the class `self` reference, but it
47
is able to call static methods within this same class.
49
# Open existing FreeCAD document with test geometry
50
FreeCAD.newDocument("Unnamed")
53
def tearDownClass(cls):
56
This method is called prior to destruction of this test class. Add
57
code and objects here that cleanup the test environment after the
58
test() methods in this class have been executed. This method does
59
not have access to the class `self` reference. This method is able
60
to call static methods within this same class.
62
# Close geometry document without saving
63
FreeCAD.closeDocument(FreeCAD.ActiveDocument.Name)
65
# Setup and tear down methods called before and after each unit test
70
This method is called prior to each `test()` method. Add code and
71
objects here that are needed for multiple `test()` methods.
73
self.doc = FreeCAD.ActiveDocument
74
self.con = FreeCAD.Console
75
self.docobj = FreeCAD.ActiveDocument.addObject("Path::Feature", "testpath")
77
# Re-initialize all of the values before doing a test.
79
postprocessor.UNITS = "G21"
80
postprocessor.init_values(postprocessor.global_values)
85
This method is called after each test() method. Add cleanup instructions here.
86
Such cleanup instructions will likely undo those in the setUp() method.
88
FreeCAD.ActiveDocument.removeObject("testpath")
90
def single_compare(self, path, expected, args, debug=False):
91
"""Perform a test with a single comparison."""
93
self.docobj.Path = Path.Path(path)
94
postables = [self.docobj]
95
gcode = postprocessor.export(postables, "-", args)
97
print(f"--------{nl}{gcode}--------{nl}")
98
self.assertEqual(gcode, expected)
100
def compare_third_line(self, path_string, expected, args, debug=False):
101
"""Perform a test with a single comparison to the third line of the output."""
104
self.docobj.Path = Path.Path([Path.Command(path_string)])
106
self.docobj.Path = Path.Path([])
107
postables = [self.docobj]
108
gcode = postprocessor.export(postables, "-", args)
110
print(f"--------{nl}{gcode}--------{nl}")
111
self.assertEqual(gcode.splitlines()[2], expected)
113
#############################################################################
115
# The tests are organized into groups:
117
# 00000 - 00099 tests that don't fit any other category
118
# 00100 - 09999 tests for all of the various arguments/options
119
# 10000 - 19999 tests for the various G codes at 10000 + 10 * g_code_value
120
# 20000 - 29999 tests for the various M codes at 20000 + 10 * m_code_value
122
#############################################################################
125
"""Test M0 command Generation."""
126
self.compare_third_line("M0", "M0", "")
127
self.compare_third_line("M00", "M00", "")
129
#############################################################################
132
"""Test M1 command Generation."""
133
self.compare_third_line("M1", "M1", "")
134
self.compare_third_line("M01", "M01", "")
136
#############################################################################
139
"""Test M2 command Generation."""
140
self.compare_third_line("M2", "M2", "")
141
self.compare_third_line("M02", "M02", "")
143
#############################################################################
146
"""Test M3 command Generation."""
147
self.compare_third_line("M3", "M3", "")
148
self.compare_third_line("M03", "M03", "")
150
#############################################################################
153
"""Test M4 command Generation."""
154
self.compare_third_line("M4", "M4", "")
155
self.compare_third_line("M04", "M04", "")
157
#############################################################################
160
"""Test M5 command Generation."""
161
self.compare_third_line("M5", "M5", "")
162
self.compare_third_line("M05", "M05", "")
164
#############################################################################
167
"""Test M6 command Generation."""
168
self.compare_third_line("M6", "M6", "")
169
self.compare_third_line("M06", "M06", "")
171
#############################################################################
174
"""Test M7 command Generation."""
175
self.compare_third_line("M7", "M7", "")
176
self.compare_third_line("M07", "M07", "")
178
#############################################################################
181
"""Test M8 command Generation."""
182
self.compare_third_line("M8", "M8", "")
183
self.compare_third_line("M08", "M08", "")
185
#############################################################################
188
"""Test M9 command Generation."""
189
self.compare_third_line("M9", "M9", "")
190
self.compare_third_line("M09", "M09", "")
192
#############################################################################
195
"""Test M30 command Generation."""
196
self.compare_third_line("M30", "M30", "")
198
#############################################################################
201
"""Test M48 command Generation."""
202
self.compare_third_line("M48", "M48", "")
204
#############################################################################
207
"""Test M49 command Generation."""
208
self.compare_third_line("M49", "M49", "")
210
#############################################################################
213
"""Test M60 command Generation."""
214
self.compare_third_line("M60", "M60", "")