2121from .common import running_on_ci
2222
2323
24- def test_compile_without_fqbn (run_command ):
24+ def test_compile_without_fqbn (run_command , core_update_index , core_install ):
2525 # Init the environment explicitly
26- result = run_command ("core update-index" )
27- assert result .ok
26+ core_update_index ()
2827
2928 # Install Arduino AVR Boards
30- result = run_command ("core install arduino:avr@1.8.3" )
31- assert result .ok
29+ core_install ("arduino:avr@1.8.3" )
3230
3331 # Build sketch without FQBN
3432 result = run_command ("compile" )
3533 assert result .failed
3634
3735
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 ):
3937 # Init the environment explicitly
40- result = run_command ("core update-index" )
41- assert result .ok
38+ core_update_index ()
4239
4340 # Download latest AVR
44- result = run_command ("core install arduino:avr" )
45- assert result .ok
41+ core_install ("arduino:avr" )
4642
4743 sketch_name = "CompileIntegrationTest"
4844 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):
6561
6662 # let's test from the logs if the hex file produced by successful compile is moved to our sketch folder
6763 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
7467
7568 # Test the --output-dir flag with absolute path
7669 target = os .path .join (data_dir , "test_dir" )
@@ -87,14 +80,12 @@ def test_compile_with_simple_sketch(run_command, data_dir, working_dir):
8780 running_on_ci () and platform .system () == "Windows" ,
8881 reason = "Test disabled on Github Actions Win VM until tmpdir inconsistent behavior bug is fixed" ,
8982)
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 ):
9184 # Init the environment explicitly
92- result = run_command ("core update-index" )
93- assert result .ok
85+ core_update_index ()
9486
9587 # Install Arduino AVR Boards
96- result = run_command ("core install arduino:avr@1.8.3" )
97- assert result .ok
88+ core_install ("arduino:avr@1.8.3" )
9889
9990 # Create a test sketch
10091 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):
109100 assert os .path .exists (target ) and os .path .isdir (target )
110101
111102
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 ):
113104 # Init the environment explicitly
114- result = run_command ("core update-index" )
115- assert result .ok
105+ core_update_index ()
116106
117107 # Install Arduino AVR Boards
118- result = run_command ("core install arduino:avr@1.8.3" )
119- assert result .ok
108+ core_install ("arduino:avr@1.8.3" )
120109
121110 sketch_name = "CompileIntegrationTestSymlinkSelfLoop"
122111 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):
162151
163152
164153@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 ):
166155 # Init the environment explicitly
167- result = run_command ("core update-index" )
168- assert result .ok
156+ core_update_index ()
169157
170158 # Install required core(s)
171- result = run_command ("core install arduino:avr@1.8.3" )
172- result = run_command ("core install arduino:samd@1.8.7" )
173- assert result .ok
159+ core_install ("arduino:avr@1.8.3" )
160+ core_install ("arduino:samd@1.8.6" )
174161
175162 # Create a test sketch
176163 sketch_name = "CompileAndUploadIntegrationTest"
@@ -196,41 +183,35 @@ def run_test(s):
196183
197184 # check from the logs if the bin file were uploaded on the current board
198185 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
207191
208192 run_test (sketch_path )
209193 run_test (sketch_main_file )
210194
211195
212- def is_message_sequence_in_json_log_traces ( message_sequence , log_json_lines ):
196+ def parse_json_traces ( log_json_lines ):
213197 trace_entries = []
214198 for entry in log_json_lines :
215199 entry = json .loads (entry )
216200 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
220203
221204
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 ):
223206 """
224207 Compile should ignore folders named `RCS`, `.git` and the likes, but
225208 it should be ok for a sketch to be named like RCS.ino
226209 """
227210 # Init the environment explicitly
228- result = run_command ("core update-index" )
229- assert result .ok
211+ core_update_index ()
230212
231213 # Install Arduino AVR Boards
232- result = run_command ("core install arduino:avr@1.8.3" )
233- assert result .ok
214+ core_install ("arduino:avr@1.8.3" )
234215
235216 sketch_name = "RCS"
236217 sketch_path = os .path .join (data_dir , sketch_name )
0 commit comments