Skip to content

Commit 7e0f61e

Browse files
committed
add multi line test
1 parent 99ad01c commit 7e0f61e

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

main.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
1+
import argparse
2+
import os
13
from gcodeparser import GcodeParser
24

5+
36
if __name__ == '__main__':
4-
with open('3DBenchy.gcode', 'r') as f:
7+
parser = argparse.ArgumentParser(
8+
prog='GcodeParser',
9+
description='Converts a gcode file into an array of Python objects representing each command',
10+
)
11+
12+
parser.add_argument(
13+
'input_file',
14+
help='Path to the gcode file to be parsed',
15+
)
16+
17+
parser.add_argument(
18+
'-o',
19+
'--output_file',
20+
help='Path to the output file where the parsed gcode will be saved. Defaults to stdout.',
21+
default='-',
22+
)
23+
24+
args = parser.parse_args()
25+
26+
with open(os.path.expanduser(args.input_file), 'r') as f:
527
gcode = f.read()
628
parsed_gcode = GcodeParser(gcode)
29+
if args.output_file == '-':
30+
for line in parsed_gcode.lines:
31+
print(line)
32+
else:
33+
with open(os.path.expanduser(args.output_file), 'w') as f:
34+
for line in parsed_gcode.lines:
35+
f.write(str(line) + '\n')
736
pass

test/test_get_lines.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,25 @@ def test_multi_line():
129129
assert get_lines('G91\nG1 X-10 Y20 ; inline comment\nG1 Z0.5\nT1\nM350 T100') == lines
130130
assert get_lines('G91G1 X-10 Y20;inline comment\nG1 Z0.5\nT1M350 T100') == lines
131131
assert get_lines(' \tG91\n\tG1\t X-10 Y20 \t ;\t inline comment\nG1 Z0.5\nT1\nM350 T100') == lines
132-
assert get_lines('G91\nG1 X-10 Y20 ; inline comment\n; comment to be excluded\nG1 Z0.5\nT1\nM350 T100', include_comments=False) == lines
132+
assert get_lines('G91\nG1 X-10 Y20 ; inline comment\n; comment to be excluded\nG1 Z0.5\nT1\nM350 T100',
133+
include_comments=False) == lines
134+
assert get_lines('G91 G1 X-10 Y20 ; inline comment\n; comment to be excluded\nG1 Z0.5\nT1\nM350 T100',
135+
include_comments=False) == lines
136+
137+
138+
def test_multi_line2():
139+
""" We want to ignore things that look like gcode in the comments
140+
"""
141+
lines = [
142+
GcodeLine(
143+
command=('G', 91),
144+
params={},
145+
comment='',
146+
),
147+
GcodeLine(
148+
command=('G', 1),
149+
params={'X': 100},
150+
comment='comment G90'
151+
)
152+
]
153+
assert get_lines('G91 G1 X100 ; comment G90') == lines

0 commit comments

Comments
 (0)