Skip to content

Commit 8b76e2e

Browse files
committed
Added test for different cases of sketch path
case 1: /path/to/sketch case 2: /path/to/sketch/sketch.ino in the case 2 a compile+upload combo gives the following error: Error during Upload: cannot open sketch: stat /tmp/pytest-of-megabug/pytest-35/ArduinoTest1/CompileAndUploadIntegrationTest/CompileAndUploadIntegrationTest.ino/CompileAndUploadIntegrationTest.ino.arduino.samd.mkr1000.bin: not a directory
1 parent b62c339 commit 8b76e2e

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

test/test_compile.py

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def test_compile_with_sketch_with_symlink_selfloop(run_command, data_dir):
180180

181181

182182
@pytest.mark.skipif(running_on_ci(), reason="VMs have no serial ports")
183-
def test_compile_and_compile_combo(run_command, data_dir, detected_boards):
183+
def test_compile_and_upload_combo(run_command, data_dir, detected_boards):
184184
# Init the environment explicitly
185185
result = run_command("core update-index")
186186
assert result.ok
@@ -193,6 +193,7 @@ def test_compile_and_compile_combo(run_command, data_dir, detected_boards):
193193
# Create a test sketch
194194
sketch_name = "CompileAndUploadIntegrationTest"
195195
sketch_path = os.path.join(data_dir, sketch_name)
196+
sketch_main_file = os.path.join(sketch_path, sketch_name+".ino")
196197
result = run_command("sketch new {}".format(sketch_path))
197198
assert result.ok
198199
assert "Sketch created in: {}".format(sketch_path) in result.stdout
@@ -204,35 +205,41 @@ def test_compile_and_compile_combo(run_command, data_dir, detected_boards):
204205
command_log_flags = "--log-format json --log-file {} --log-level trace".format(
205206
log_file_path
206207
)
207-
result = run_command(
208-
"compile -b {fqbn} --upload -p {address} {sketch_path} {log_flags}".format(
209-
fqbn=board.fqbn,
210-
address=board.address,
211-
sketch_path=sketch_path,
212-
log_flags=command_log_flags,
208+
209+
def run_test(s):
210+
result = run_command(
211+
"compile -b {fqbn} --upload -p {address} {sketch_path} {log_flags}".format(
212+
fqbn=board.fqbn,
213+
address=board.address,
214+
sketch_path=s,
215+
log_flags=command_log_flags,
216+
)
213217
)
214-
)
215-
assert result.ok
216-
# check from the logs if the bin file were uploaded on the current board
217-
log_json = open(log_file_path, "r")
218-
json_log_lines = log_json.readlines()
219-
expected_trace_sequence = [
220-
"Compile {sketch} for {fqbn} started".format(
221-
sketch=sketch_path, fqbn=board.fqbn
222-
),
223-
"Compile {sketch} for {fqbn} successful".format(
224-
sketch=sketch_name, fqbn=board.fqbn
225-
),
226-
"Upload {sketch} on {fqbn} started".format(
227-
sketch=sketch_path, fqbn=board.fqbn
228-
),
229-
"Upload {sketch} on {fqbn} successful".format(
230-
sketch=sketch_name, fqbn=board.fqbn
231-
),
232-
]
233-
assert is_message_sequence_in_json_log_traces(
234-
expected_trace_sequence, json_log_lines
235-
)
218+
assert result.ok
219+
220+
# check from the logs if the bin file were uploaded on the current board
221+
log_json = open(log_file_path, "r")
222+
json_log_lines = log_json.readlines()
223+
expected_trace_sequence = [
224+
"Compile {sketch} for {fqbn} started".format(
225+
sketch=sketch_path, fqbn=board.fqbn
226+
),
227+
"Compile {sketch} for {fqbn} successful".format(
228+
sketch=sketch_name, fqbn=board.fqbn
229+
),
230+
"Upload {sketch} on {fqbn} started".format(
231+
sketch=sketch_path, fqbn=board.fqbn
232+
),
233+
"Upload {sketch} on {fqbn} successful".format(
234+
sketch=sketch_name, fqbn=board.fqbn
235+
),
236+
]
237+
assert is_message_sequence_in_json_log_traces(
238+
expected_trace_sequence, json_log_lines
239+
)
240+
241+
run_test(sketch_path)
242+
run_test(sketch_main_file)
236243

237244

238245
def is_message_sequence_in_json_log_traces(message_sequence, log_json_lines):

0 commit comments

Comments
 (0)