forked from kageurufu/preprocess_cancellation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_preprocessor.py
199 lines (139 loc) · 8.16 KB
/
test_preprocessor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import pathlib
import re
import subprocess
import sys
from preprocess_cancellation import preprocess_cura, preprocess_ideamaker, preprocess_m486, preprocess_slicer
gcode_path = pathlib.Path("./GCode")
def collect_definitions(lines):
definitions = set()
for line in lines:
if line.startswith("EXCLUDE_OBJECT_DEFINE"):
definitions.add(line)
# Add just the `EXCLUDE_OBJECT_DEFINE NAME=...` as well, for quick checking without caring about coordinates
definitions.add(re.sub(r"^(EXCLUDE_OBJECT_DEFINE).*(NAME=\S+).*$", r"\1 \2", line))
return definitions
def test_cli_without():
"""
Ensure the preprocesor does not crash
"""
try:
command = [
sys.executable,
"./preprocess_cancellation.py",
"--disable-shapely",
"-o",
".testing",
*gcode_path.glob("*.gcode"),
]
with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc:
proc.wait()
assert proc.returncode == 0
finally:
for testing_file in gcode_path.glob("*.testing.gcode"):
testing_file.unlink()
def test_m486():
with (gcode_path / "m486.gcode").open("r") as f:
results = "".join(list(preprocess_m486(f))).split("\n")
definitions = collect_definitions(results)
assert "EXCLUDE_OBJECT_DEFINE NAME=0" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=1" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=2" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=3" in definitions
assert results.count(f"EXCLUDE_OBJECT_START NAME=0") == 25
assert results.count(f"EXCLUDE_OBJECT_END NAME=0") == 25
assert results.count(f"EXCLUDE_OBJECT_START NAME=1") == 25
assert results.count(f"EXCLUDE_OBJECT_END NAME=1") == 25
assert results.count(f"EXCLUDE_OBJECT_START NAME=2") == 25
assert results.count(f"EXCLUDE_OBJECT_END NAME=2") == 25
assert results.count(f"EXCLUDE_OBJECT_START NAME=3") == 25
assert results.count(f"EXCLUDE_OBJECT_END NAME=3") == 25
def test_superslicer():
with (gcode_path / "superslicer.gcode").open("r") as f:
results = "".join(list(preprocess_slicer(f))).split("\n")
definitions = collect_definitions(results)
assert "EXCLUDE_OBJECT_DEFINE NAME=cube_1_id_0_copy_0" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=cube_1_id_0_copy_1" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=union_3_id_2_copy_0" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=cylinder_2_id_1_copy_0" in definitions
def test_superslicer():
with (gcode_path / "superslicer.gcode").open("r") as f:
results = "".join(list(preprocess_slicer(f))).split("\n")
definitions = collect_definitions(results)
assert "EXCLUDE_OBJECT_DEFINE NAME=cube_1_id_0_copy_0" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=cube_1_id_0_copy_1" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=union_3_id_2_copy_0" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=cylinder_2_id_1_copy_0" in definitions
def test_prusaslicer():
with (gcode_path / "prusaslicer.gcode").open("r") as f:
results = "".join(list(preprocess_slicer(f))).split("\n")
definitions = collect_definitions(results)
assert "EXCLUDE_OBJECT_DEFINE NAME=cylinder_2_id_1_copy_0" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=cube_1_id_0_copy_0" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=cube_1_id_0_copy_1" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=union_3_id_2_copy_0" in definitions
assert results.count(f"EXCLUDE_OBJECT_START NAME=cylinder_2_id_1_copy_0") == 25
assert results.count(f"EXCLUDE_OBJECT_END NAME=cylinder_2_id_1_copy_0") == 25
assert results.count(f"EXCLUDE_OBJECT_START NAME=cube_1_id_0_copy_0") == 25
assert results.count(f"EXCLUDE_OBJECT_END NAME=cube_1_id_0_copy_0") == 25
assert results.count(f"EXCLUDE_OBJECT_START NAME=cube_1_id_0_copy_1") == 25
assert results.count(f"EXCLUDE_OBJECT_END NAME=cube_1_id_0_copy_1") == 25
assert results.count(f"EXCLUDE_OBJECT_START NAME=union_3_id_2_copy_0") == 25
assert results.count(f"EXCLUDE_OBJECT_END NAME=union_3_id_2_copy_0") == 25
def test_slic3r():
with (gcode_path / "slic3r.gcode").open("r") as f:
results = "".join(list(preprocess_slicer(f))).split("\n")
definitions = collect_definitions(results)
assert "EXCLUDE_OBJECT_DEFINE NAME=cube_1_stl_id_0_copy_0" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=cube_1_stl_id_0_copy_1" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=cylinder_2_stl_id_1_copy_0" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=union_3_stl_id_2_copy_0" in definitions
assert results.count(f"EXCLUDE_OBJECT_START NAME=cube_1_stl_id_0_copy_0") == 16
assert results.count(f"EXCLUDE_OBJECT_END NAME=cube_1_stl_id_0_copy_0") == 16
assert results.count(f"EXCLUDE_OBJECT_START NAME=cube_1_stl_id_0_copy_1") == 16
assert results.count(f"EXCLUDE_OBJECT_END NAME=cube_1_stl_id_0_copy_1") == 16
assert results.count(f"EXCLUDE_OBJECT_START NAME=cylinder_2_stl_id_1_copy_0") == 16
assert results.count(f"EXCLUDE_OBJECT_END NAME=cylinder_2_stl_id_1_copy_0") == 16
assert results.count(f"EXCLUDE_OBJECT_START NAME=union_3_stl_id_2_copy_0") == 16
assert results.count(f"EXCLUDE_OBJECT_END NAME=union_3_stl_id_2_copy_0") == 16
def test_cura():
with (gcode_path / "cura.gcode").open("r") as f:
results = "".join(list(preprocess_cura(f))).split("\n")
definitions = collect_definitions(results)
assert "EXCLUDE_OBJECT_DEFINE NAME=cylinder_2_stl" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=cube_1_stl" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=union_3_stl" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=cube_1_stl_1" in definitions
assert results.count(f"EXCLUDE_OBJECT_START NAME=cylinder_2_stl") == 25
assert results.count(f"EXCLUDE_OBJECT_END NAME=cylinder_2_stl") == 25
assert results.count(f"EXCLUDE_OBJECT_START NAME=cube_1_stl") == 25
assert results.count(f"EXCLUDE_OBJECT_END NAME=cube_1_stl") == 25
assert results.count(f"EXCLUDE_OBJECT_START NAME=union_3_stl") == 25
assert results.count(f"EXCLUDE_OBJECT_END NAME=union_3_stl") == 25
assert results.count(f"EXCLUDE_OBJECT_START NAME=cube_1_stl_1") == 25
assert results.count(f"EXCLUDE_OBJECT_END NAME=cube_1_stl_1") == 25
def test_ideamaker():
with (gcode_path / "ideamaker.gcode").open("r") as f:
results = "".join(list(preprocess_ideamaker(f))).split("\n")
definitions = collect_definitions(results)
assert "EXCLUDE_OBJECT_DEFINE NAME=test_bed_part1_3mf" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=test_bed_part2_3mf" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=test_bed_part0_3mf" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=test_bed_part0_1_3mf" in definitions
assert results.count("EXCLUDE_OBJECT_START NAME=test_bed_part1_3mf") == 32
assert results.count("EXCLUDE_OBJECT_END NAME=test_bed_part1_3mf") == 32
assert results.count("EXCLUDE_OBJECT_START NAME=test_bed_part2_3mf") == 32
assert results.count("EXCLUDE_OBJECT_END NAME=test_bed_part2_3mf") == 32
assert results.count("EXCLUDE_OBJECT_START NAME=test_bed_part0_3mf") == 33
assert results.count("EXCLUDE_OBJECT_END NAME=test_bed_part0_3mf") == 33
assert results.count("EXCLUDE_OBJECT_START NAME=test_bed_part0_1_3mf") == 33
assert results.count("EXCLUDE_OBJECT_END NAME=test_bed_part0_1_3mf") == 33
def test_issue_1_prusaslicer_point_collection():
with (gcode_path / "prusaslicer-issue1.gcode").open("r") as f:
results = "".join(list(preprocess_slicer(f))).split("\n")
definitions = collect_definitions(results)
assert "EXCLUDE_OBJECT_DEFINE NAME=Shape_Cylinder_id_1_copy_0" in definitions
assert "EXCLUDE_OBJECT_DEFINE NAME=Shape_Box_id_0_copy_0" in definitions
assert results.count(f"EXCLUDE_OBJECT_START NAME=Shape_Cylinder_id_1_copy_0") == 125
assert results.count(f"EXCLUDE_OBJECT_END NAME=Shape_Cylinder_id_1_copy_0") == 125
assert results.count(f"EXCLUDE_OBJECT_START NAME=Shape_Box_id_0_copy_0") == 125
assert results.count(f"EXCLUDE_OBJECT_END NAME=Shape_Box_id_0_copy_0") == 125