24
from importlib import reload
29
import Tests.PathTestUtils as PathTestUtils
30
from Path.Post.scripts import refactored_mach3_mach4_post as postprocessor
32
Path.Log.setLevel(Path.Log.Level.DEBUG, Path.Log.thisModule())
33
Path.Log.trackModule(Path.Log.thisModule())
36
class TestRefactoredMach3Mach4Post(PathTestUtils.PathTestBase):
38
def setUpClass(cls) -> None:
40
This method is called upon instantiation of this test class. Add code
41
and objects here that are needed for the duration of the test() methods
42
in this class. In other words, set up the 'global' test environment
43
here; use the `setUp()` method to set up a 'local' test environment.
44
This method does not have access to the class `self` reference, but it
45
is able to call static methods within this same class.
49
FreeCAD.newDocument("Unnamed")
52
def tearDownClass(cls) -> None:
54
This method is called prior to destruction of this test class. Add
55
code and objects here that cleanup the test environment after the
56
test() methods in this class have been executed. This method does not
57
have access to the class `self` reference. This method is able to
58
call static methods within this same class.
61
FreeCAD.closeDocument(FreeCAD.ActiveDocument.Name)
64
def setUp(self) -> None:
66
This method is called prior to each `test()` method. Add code and
67
objects here that are needed for multiple `test()` methods.
69
self.doc = FreeCAD.ActiveDocument
70
self.con = FreeCAD.Console
71
self.docobj = FreeCAD.ActiveDocument.addObject("Path::Feature", "testpath")
76
def tearDown(self) -> None:
78
This method is called after each test() method. Add cleanup instructions here.
79
Such cleanup instructions will likely undo those in the setUp() method.
81
FreeCAD.ActiveDocument.removeObject("testpath")
83
def test000(self) -> None:
84
"""Test Output Generation.
85
Empty path. Produces only the preamble and postable.
88
self.docobj.Path = Path.Path([])
89
postables = [self.docobj]
94
args = "--no-show-editor"
95
gcode = postprocessor.export(postables, "-", args)
96
self.assertTrue(len(gcode.splitlines()) == 14)
99
expected = """(Begin preamble)
100
G17 G54 G40 G49 G80 G90
102
(Begin operation: testpath)
103
(Machine: mach3_4, mm/min)
104
(Finish operation: testpath)
111
self.docobj.Path = Path.Path([])
112
postables = [self.docobj]
114
args = "--no-header --no-show-editor"
116
gcode = postprocessor.export(postables, "-", args)
117
self.assertEqual(gcode, expected)
120
expected = """G17 G54 G40 G49 G80 G90
127
args = "--no-header --no-comments --no-show-editor"
129
gcode = postprocessor.export(postables, "-", args)
130
self.assertEqual(gcode, expected)
133
"""Test command Generation.
136
c = Path.Command("G0 X10 Y20 Z30")
138
self.docobj.Path = Path.Path([c])
139
postables = [self.docobj]
141
args = "--no-header --no-show-editor"
142
gcode = postprocessor.export(postables, "-", args)
143
result = gcode.splitlines()[5]
144
expected = "G0 X10.000 Y20.000 Z30.000"
145
self.assertEqual(result, expected)
147
args = "--no-header --precision=2 --no-show-editor"
148
gcode = postprocessor.export(postables, "-", args)
149
result = gcode.splitlines()[5]
150
expected = "G0 X10.00 Y20.00 Z30.00"
151
self.assertEqual(result, expected)
157
c = Path.Command("G0 X10 Y20 Z30")
159
self.docobj.Path = Path.Path([c])
160
postables = [self.docobj]
162
args = "--no-header --line-numbers --no-show-editor"
163
gcode = postprocessor.export(postables, "-", args)
164
result = gcode.splitlines()[5]
165
expected = "N150 G0 X10.000 Y20.000 Z30.000"
166
self.assertEqual(result, expected)
173
self.docobj.Path = Path.Path([])
174
postables = [self.docobj]
176
args = "--no-header --no-comments --preamble='G18 G55' --no-show-editor"
177
gcode = postprocessor.export(postables, "-", args)
178
result = gcode.splitlines()[0]
179
self.assertEqual(result, "G18 G55")
185
self.docobj.Path = Path.Path([])
186
postables = [self.docobj]
187
args = "--no-header --no-comments --postamble='G0 Z50\nM2' --no-show-editor"
188
gcode = postprocessor.export(postables, "-", args)
189
result = gcode.splitlines()[-2]
190
self.assertEqual(result, "G0 Z50")
191
self.assertEqual(gcode.splitlines()[-1], "M2")
198
c = Path.Command("G0 X10 Y20 Z30")
199
self.docobj.Path = Path.Path([c])
200
postables = [self.docobj]
202
args = "--no-header --inches --no-show-editor"
203
gcode = postprocessor.export(postables, "-", args)
204
self.assertEqual(gcode.splitlines()[2], "G20")
206
result = gcode.splitlines()[5]
207
expected = "G0 X0.3937 Y0.7874 Z1.1811"
208
self.assertEqual(result, expected)
210
args = "--no-header --inches --precision=2 --no-show-editor"
211
gcode = postprocessor.export(postables, "-", args)
212
result = gcode.splitlines()[5]
213
expected = "G0 X0.39 Y0.79 Z1.18"
214
self.assertEqual(result, expected)
219
Suppress the command name if the same as previous
221
c = Path.Command("G0 X10 Y20 Z30")
222
c1 = Path.Command("G0 X10 Y30 Z30")
224
self.docobj.Path = Path.Path([c, c1])
225
postables = [self.docobj]
227
args = "--no-header --modal --no-show-editor"
228
gcode = postprocessor.export(postables, "-", args)
229
result = gcode.splitlines()[6]
230
expected = "X10.000 Y30.000 Z30.000"
231
self.assertEqual(result, expected)
236
Suppress the axis coordinate if the same as previous
238
c = Path.Command("G0 X10 Y20 Z30")
239
c1 = Path.Command("G0 X10 Y30 Z30")
241
self.docobj.Path = Path.Path([c, c1])
242
postables = [self.docobj]
244
args = "--no-header --axis-modal --no-show-editor"
245
gcode = postprocessor.export(postables, "-", args)
246
result = gcode.splitlines()[6]
247
expected = "G0 Y30.000"
248
self.assertEqual(result, expected)
254
c = Path.Command("M6 T2")
255
c2 = Path.Command("M3 S3000")
256
self.docobj.Path = Path.Path([c, c2])
257
postables = [self.docobj]
259
args = "--no-header --no-show-editor"
260
gcode = postprocessor.export(postables, "-", args)
261
self.assertEqual(gcode.splitlines()[6], "M5")
262
self.assertEqual(gcode.splitlines()[7], "M6 T2")
263
self.assertEqual(gcode.splitlines()[8], "G43 H2")
264
self.assertEqual(gcode.splitlines()[9], "M3 S3000")
267
args = "--no-header --no-tlo --no-show-editor"
268
gcode = postprocessor.export(postables, "-", args)
269
self.assertEqual(gcode.splitlines()[8], "M3 S3000")
276
c = Path.Command("(comment)")
278
self.docobj.Path = Path.Path([c])
279
postables = [self.docobj]
281
args = "--no-header --no-show-editor"
282
gcode = postprocessor.export(postables, "-", args)
283
result = gcode.splitlines()[5]
284
expected = "(comment)"
285
self.assertEqual(result, expected)