24
from importlib import reload
29
import Tests.PathTestUtils as PathTestUtils
30
from Path.Post.scripts import refactored_grbl_post as postprocessor
33
Path.Log.setLevel(Path.Log.Level.DEBUG, Path.Log.thisModule())
34
Path.Log.trackModule(Path.Log.thisModule())
37
class TestRefactoredGrblPost(PathTestUtils.PathTestBase):
41
This method is called upon instantiation of this test class. Add code
42
and objects here that are needed for the duration of the test() methods
43
in this class. In other words, set up the 'global' test environment
44
here; use the `setUp()` method to set up a 'local' test environment.
45
This method does not have access to the class `self` reference, but it
46
is able to call static methods within this same class.
50
FreeCAD.newDocument("Unnamed")
53
def tearDownClass(cls):
55
This method is called prior to destruction of this test class. Add
56
code and objects here that cleanup the test environment after the
57
test() methods in this class have been executed. This method does not
58
have access to the class `self` reference. This method
59
is able to call static methods within this same class.
62
FreeCAD.closeDocument(FreeCAD.ActiveDocument.Name)
67
This method is called prior to each `test()` method. Add code and
68
objects here that are needed for multiple `test()` methods.
70
self.doc = FreeCAD.ActiveDocument
71
self.con = FreeCAD.Console
72
self.docobj = FreeCAD.ActiveDocument.addObject("Path::Feature", "testpath")
79
This method is called after each test() method. Add cleanup instructions here.
80
Such cleanup instructions will likely undo those in the setUp() method.
82
FreeCAD.ActiveDocument.removeObject("testpath")
85
"""Test Output Generation.
86
Empty path. Produces only the preamble and postable.
89
self.docobj.Path = Path.Path([])
90
postables = [self.docobj]
95
args = "--no-show-editor"
96
gcode = postprocessor.export(postables, "-", args)
97
self.assertTrue(len(gcode.splitlines()) == 14)
100
expected = """(Begin preamble)
103
(Begin operation: testpath)
105
(Finish operation: testpath)
112
self.docobj.Path = Path.Path([])
113
postables = [self.docobj]
115
args = "--no-header --no-show-editor"
117
gcode = postprocessor.export(postables, "-", args)
118
self.assertEqual(gcode, expected)
121
expected = """G17 G90
128
args = "--no-header --no-comments --no-show-editor"
130
gcode = postprocessor.export(postables, "-", args)
131
self.assertEqual(gcode, expected)
134
"""Test command Generation.
137
c = Path.Command("G0 X10 Y20 Z30")
139
self.docobj.Path = Path.Path([c])
140
postables = [self.docobj]
142
args = "--no-header --no-show-editor"
143
gcode = postprocessor.export(postables, "-", args)
144
result = gcode.splitlines()[5]
145
expected = "G0 X10.000 Y20.000 Z30.000"
146
self.assertEqual(result, expected)
148
args = "--no-header --precision=2 --no-show-editor"
149
gcode = postprocessor.export(postables, "-", args)
150
result = gcode.splitlines()[5]
151
expected = "G0 X10.00 Y20.00 Z30.00"
152
self.assertEqual(result, expected)
158
c = Path.Command("G0 X10 Y20 Z30")
160
self.docobj.Path = Path.Path([c])
161
postables = [self.docobj]
163
args = "--no-header --line-numbers --no-show-editor"
164
gcode = postprocessor.export(postables, "-", args)
165
result = gcode.splitlines()[5]
166
expected = "N150 G0 X10.000 Y20.000 Z30.000"
167
self.assertEqual(result, expected)
174
self.docobj.Path = Path.Path([])
175
postables = [self.docobj]
177
args = "--no-header --no-comments --preamble='G18 G55' --no-show-editor"
178
gcode = postprocessor.export(postables, "-", args)
179
result = gcode.splitlines()[0]
180
self.assertEqual(result, "G18 G55")
186
self.docobj.Path = Path.Path([])
187
postables = [self.docobj]
188
args = "--no-header --no-comments --postamble='G0 Z50\nM2' --no-show-editor"
189
gcode = postprocessor.export(postables, "-", args)
190
result = gcode.splitlines()[-2]
191
self.assertEqual(result, "G0 Z50")
192
self.assertEqual(gcode.splitlines()[-1], "M2")
199
c = Path.Command("G0 X10 Y20 Z30")
200
self.docobj.Path = Path.Path([c])
201
postables = [self.docobj]
203
args = "--no-header --inches --no-show-editor"
204
gcode = postprocessor.export(postables, "-", args)
205
self.assertEqual(gcode.splitlines()[2], "G20")
207
result = gcode.splitlines()[5]
208
expected = "G0 X0.3937 Y0.7874 Z1.1811"
209
self.assertEqual(result, expected)
211
args = "--no-header --inches --precision=2 --no-show-editor"
212
gcode = postprocessor.export(postables, "-", args)
213
result = gcode.splitlines()[5]
214
expected = "G0 X0.39 Y0.79 Z1.18"
215
self.assertEqual(result, expected)
220
Suppress the command name if the same as previous
222
c = Path.Command("G0 X10 Y20 Z30")
223
c1 = Path.Command("G0 X10 Y30 Z30")
225
self.docobj.Path = Path.Path([c, c1])
226
postables = [self.docobj]
228
args = "--no-header --modal --no-show-editor"
229
gcode = postprocessor.export(postables, "-", args)
230
result = gcode.splitlines()[6]
231
expected = "X10.000 Y30.000 Z30.000"
232
self.assertEqual(result, expected)
237
Suppress the axis coordinate if the same as previous
239
c = Path.Command("G0 X10 Y20 Z30")
240
c1 = Path.Command("G0 X10 Y30 Z30")
242
self.docobj.Path = Path.Path([c, c1])
243
postables = [self.docobj]
245
args = "--no-header --axis-modal --no-show-editor"
246
gcode = postprocessor.export(postables, "-", args)
247
result = gcode.splitlines()[6]
248
expected = "G0 Y30.000"
249
self.assertEqual(result, expected)
255
c = Path.Command("M6 T2")
256
c2 = Path.Command("M3 S3000")
257
self.docobj.Path = Path.Path([c, c2])
258
postables = [self.docobj]
260
args = "--no-header --no-show-editor"
261
gcode = postprocessor.export(postables, "-", args)
262
self.assertEqual(gcode.splitlines()[6], "( M6 T2 )")
263
self.assertEqual(gcode.splitlines()[7], "M3 S3000")
266
args = "--no-header --no-tlo --no-show-editor"
267
gcode = postprocessor.export(postables, "-", args)
268
self.assertEqual(gcode.splitlines()[7], "M3 S3000")
275
c = Path.Command("(comment)")
277
self.docobj.Path = Path.Path([c])
278
postables = [self.docobj]
280
args = "--no-header --no-show-editor"
281
gcode = postprocessor.export(postables, "-", args)
282
result = gcode.splitlines()[5]
283
expected = "(comment)"
284
self.assertEqual(result, expected)