21
21
from .common import running_on_ci
22
22
23
23
24
- def test_compile_without_fqbn (run_command ):
24
+ def test_compile_without_fqbn (run_command , core_update_index , core_install ):
25
25
# Init the environment explicitly
26
- result = run_command ("core update-index" )
27
- assert result .ok
26
+ core_update_index ()
28
27
29
28
# Install Arduino AVR Boards
30
- result = run_command (
"core install arduino:[email protected] " )
31
- assert result .ok
29
+ core_install (
"arduino:[email protected] " )
32
30
33
31
# Build sketch without FQBN
34
32
result = run_command ("compile" )
35
33
assert result .failed
36
34
37
35
38
- def test_compile_with_simple_sketch (run_command , data_dir , working_dir ):
36
+ def test_compile_with_simple_sketch (run_command , data_dir , working_dir , core_update_index , core_install ):
39
37
# Init the environment explicitly
40
- result = run_command ("core update-index" )
41
- assert result .ok
38
+ core_update_index ()
42
39
43
40
# Download latest AVR
44
- result = run_command ("core install arduino:avr" )
45
- assert result .ok
41
+ core_install ("arduino:avr" )
46
42
47
43
sketch_name = "CompileIntegrationTest"
48
44
sketch_path = os .path .join (data_dir , sketch_name )
@@ -65,12 +61,9 @@ def test_compile_with_simple_sketch(run_command, data_dir, working_dir):
65
61
66
62
# let's test from the logs if the hex file produced by successful compile is moved to our sketch folder
67
63
log_json = open (log_file_path , "r" )
68
- json_log_lines = log_json .readlines ()
69
- expected_trace_sequence = [
70
- "Compile {sketch} for {fqbn} started" .format (sketch = sketch_path , fqbn = fqbn ),
71
- "Compile {sketch} for {fqbn} successful" .format (sketch = sketch_name , fqbn = fqbn ),
72
- ]
73
- assert is_message_sequence_in_json_log_traces (expected_trace_sequence , json_log_lines )
64
+ traces = parse_json_traces (log_json .readlines ())
65
+ assert f"Compile { sketch_path } for { fqbn } started" in traces
66
+ assert f"Compile { sketch_name } for { fqbn } successful" in traces
74
67
75
68
# Test the --output-dir flag with absolute path
76
69
target = os .path .join (data_dir , "test_dir" )
@@ -87,14 +80,12 @@ def test_compile_with_simple_sketch(run_command, data_dir, working_dir):
87
80
running_on_ci () and platform .system () == "Windows" ,
88
81
reason = "Test disabled on Github Actions Win VM until tmpdir inconsistent behavior bug is fixed" ,
89
82
)
90
- def test_output_flag_default_path (run_command , data_dir , working_dir ):
83
+ def test_output_flag_default_path (run_command , data_dir , working_dir , core_update_index , core_install ):
91
84
# Init the environment explicitly
92
- result = run_command ("core update-index" )
93
- assert result .ok
85
+ core_update_index ()
94
86
95
87
# Install Arduino AVR Boards
96
- result = run_command (
"core install arduino:[email protected] " )
97
- assert result .ok
88
+ core_install (
"arduino:[email protected] " )
98
89
99
90
# Create a test sketch
100
91
sketch_path = os .path .join (data_dir , "test_output_flag_default_path" )
@@ -109,14 +100,12 @@ def test_output_flag_default_path(run_command, data_dir, working_dir):
109
100
assert os .path .exists (target ) and os .path .isdir (target )
110
101
111
102
112
- def test_compile_with_sketch_with_symlink_selfloop (run_command , data_dir ):
103
+ def test_compile_with_sketch_with_symlink_selfloop (run_command , data_dir , core_update_index , core_install ):
113
104
# Init the environment explicitly
114
- result = run_command ("core update-index" )
115
- assert result .ok
105
+ core_update_index ()
116
106
117
107
# Install Arduino AVR Boards
118
- result = run_command (
"core install arduino:[email protected] " )
119
- assert result .ok
108
+ core_install (
"arduino:[email protected] " )
120
109
121
110
sketch_name = "CompileIntegrationTestSymlinkSelfLoop"
122
111
sketch_path = os .path .join (data_dir , sketch_name )
@@ -162,15 +151,13 @@ def test_compile_with_sketch_with_symlink_selfloop(run_command, data_dir):
162
151
163
152
164
153
@pytest .mark .skipif (running_on_ci (), reason = "VMs have no serial ports" )
165
- def test_compile_and_upload_combo (run_command , data_dir , detected_boards ):
154
+ def test_compile_and_upload_combo (run_command , data_dir , detected_boards , core_update_index , core_install ):
166
155
# Init the environment explicitly
167
- result = run_command ("core update-index" )
168
- assert result .ok
156
+ core_update_index ()
169
157
170
158
# Install required core(s)
171
- result = run_command (
"core install arduino:[email protected] " )
172
- result = run_command (
"core install arduino:[email protected] " )
173
- assert result .ok
159
+ core_install (
"arduino:[email protected] " )
160
+ core_install (
"arduino:[email protected] " )
174
161
175
162
# Create a test sketch
176
163
sketch_name = "CompileAndUploadIntegrationTest"
@@ -196,41 +183,35 @@ def run_test(s):
196
183
197
184
# check from the logs if the bin file were uploaded on the current board
198
185
log_json = open (log_file_path , "r" )
199
- json_log_lines = log_json .readlines ()
200
- expected_trace_sequence = [
201
- "Compile {sketch} for {fqbn} started" .format (sketch = sketch_path , fqbn = board .fqbn ),
202
- "Compile {sketch} for {fqbn} successful" .format (sketch = sketch_name , fqbn = board .fqbn ),
203
- "Upload {sketch} on {fqbn} started" .format (sketch = sketch_path , fqbn = board .fqbn ),
204
- "Upload {sketch} on {fqbn} successful" .format (sketch = sketch_name , fqbn = board .fqbn ),
205
- ]
206
- assert is_message_sequence_in_json_log_traces (expected_trace_sequence , json_log_lines )
186
+ traces = parse_json_traces (log_json .readlines ())
187
+ assert f"Compile { sketch_path } for { board .fqbn } started" in traces
188
+ assert f"Compile { sketch_name } for { board .fqbn } successful" in traces
189
+ assert f"Upload { sketch_path } on { board .fqbn } started" in traces
190
+ assert "Upload successful" in traces
207
191
208
192
run_test (sketch_path )
209
193
run_test (sketch_main_file )
210
194
211
195
212
- def is_message_sequence_in_json_log_traces ( message_sequence , log_json_lines ):
196
+ def parse_json_traces ( log_json_lines ):
213
197
trace_entries = []
214
198
for entry in log_json_lines :
215
199
entry = json .loads (entry )
216
200
if entry .get ("level" ) == "trace" :
217
- if entry .get ("msg" ) in message_sequence :
218
- trace_entries .append (entry .get ("msg" ))
219
- return message_sequence == trace_entries
201
+ trace_entries .append (entry .get ("msg" ))
202
+ return trace_entries
220
203
221
204
222
- def test_compile_blacklisted_sketchname (run_command , data_dir ):
205
+ def test_compile_blacklisted_sketchname (run_command , data_dir , core_update_index , core_install ):
223
206
"""
224
207
Compile should ignore folders named `RCS`, `.git` and the likes, but
225
208
it should be ok for a sketch to be named like RCS.ino
226
209
"""
227
210
# Init the environment explicitly
228
- result = run_command ("core update-index" )
229
- assert result .ok
211
+ core_update_index ()
230
212
231
213
# Install Arduino AVR Boards
232
- result = run_command (
"core install arduino:[email protected] " )
233
- assert result .ok
214
+ core_install (
"arduino:[email protected] " )
234
215
235
216
sketch_name = "RCS"
236
217
sketch_path = os .path .join (data_dir , sketch_name )
0 commit comments