Coverage for tests/integration/test_gcodelexer.py: 98%
58 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-20 05:56 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-20 05:56 +0000
1import unittest
2from tatlin.lib.model.gcode.parser import GcodeLexer
5class GcodeLexerTest(unittest.TestCase):
6 def setUp(self):
7 self.lexer = GcodeLexer()
9 def compare_output(self, line, expected):
10 self.assertEqual(self.lexer.scan_line(line), expected)
12 def test_empty(self):
13 line = ""
14 expected = ("", {}, "")
15 self.compare_output(line, expected)
17 def test_whitespace(self):
18 line = "\t "
19 expected = ("", {}, "")
20 self.compare_output(line, expected)
22 def test_comments(self):
23 comment1 = "; M107 ; turn fan off"
24 expected = ("", {}, comment1)
25 self.compare_output(comment1, expected)
27 comment2 = "(**** begin homing ****)"
28 expected = ("", {}, comment2)
29 self.compare_output(comment2, expected)
31 comment3 = comment2 + comment1
32 expected = ("", {}, comment3)
33 self.compare_output(comment3, expected)
35 def test_no_args_no_comment(self):
36 line = "G21"
37 expected = (line, {}, "")
38 self.compare_output(line, expected)
40 def test_no_args(self):
41 line = "G21 ; set units to millimeters"
42 expected = ("G21", {}, "; set units to millimeters")
43 self.compare_output(line, expected)
45 def test_int_arg(self):
46 line = "G92 E0 ; reset extrusion distance"
47 expected = ("G92", {"E": 0}, "; reset extrusion distance")
48 self.compare_output(line, expected)
50 def test_multiple_args(self):
51 line = "G1 X81.430 Y77.020 E1.08502 ; skirt"
52 expected = ("G1", {"X": 81.43, "Y": 77.02, "E": 1.08502}, "; skirt")
53 self.compare_output(line, expected)
55 def test_slic3r_file(self):
56 fname = "tests/fixtures/gcode/slic3r.gcode"
57 with open(fname, "r") as f:
58 self.lexer.load(f)
59 result = list(self.lexer.scan())
61 def test_skeinforge_file(self):
62 fname = "tests/fixtures/gcode/top.gcode"
63 with open(fname, "r") as f:
64 self.lexer.load(f)
65 result = list(self.lexer.scan())
67 def test_string_input(self):
68 s = """
69 M108 S255 (set extruder speed to maximum)
70 M104 S205 T0 (set extruder temperature)
71 M109 S105 T0 (set heated-build-platform temperature)
72 """
73 self.lexer.load(s)
74 result = list(self.lexer.scan())
75 self.assertEqual(len(result), 3)
78if __name__ == "__main__":
79 unittest.main()