Skip to content

Commit 34114c6

Browse files
Massimiliano Pippimasci
Massimiliano Pippi
authored andcommitted
use fixture
1 parent 9003eb8 commit 34114c6

File tree

1 file changed

+8
-49
lines changed

1 file changed

+8
-49
lines changed

Diff for: test/test_compile.py

+8-49
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def test_compile_with_sketch_with_symlink_selfloop(run_command, data_dir):
159159

160160

161161
@pytest.mark.skipif(running_on_ci(), reason="VMs have no serial ports")
162-
def test_compile_and_compile_combo(run_command, data_dir):
162+
def test_compile_and_compile_combo(run_command, data_dir, detected_boards):
163163
# Init the environment explicitly
164164
result = run_command("core update-index")
165165
assert result.ok
@@ -176,58 +176,17 @@ def test_compile_and_compile_combo(run_command, data_dir):
176176
assert result.ok
177177
assert "Sketch created in: {}".format(sketch_path) in result.stdout
178178

179-
#
180-
# Build a list of detected boards to test, if any.
181-
#
182-
result = run_command("board list --format json")
183-
assert result.ok
184-
185-
#
186-
# The `board list --format json` returns a JSON that looks like to the following:
187-
#
188-
# [
189-
# {
190-
# "address": "/dev/cu.usbmodem14201",
191-
# "protocol": "serial",
192-
# "protocol_label": "Serial Port (USB)",
193-
# "boards": [
194-
# {
195-
# "name": "Arduino NANO 33 IoT",
196-
# "FQBN": "arduino:samd:nano_33_iot"
197-
# }
198-
# ]
199-
# }
200-
# ]
201-
202-
detected_boards = []
203-
204-
ports = json.loads(result.stdout)
205-
assert isinstance(ports, list)
206-
for port in ports:
207-
boards = port.get("boards")
208-
if boards is None:
209-
continue
210-
assert isinstance(boards, list)
211-
for board in boards:
212-
detected_boards.append(
213-
dict(address=port.get("address"), fqbn=board.get("FQBN"))
214-
)
215-
216-
assert len(detected_boards) >= 1, "There are no boards available for testing"
217-
218179
# Build sketch for each detected board
219180
for board in detected_boards:
220-
log_file_name = "{fqbn}-compile.log".format(
221-
fqbn=board.get("fqbn").replace(":", "-")
222-
)
181+
log_file_name = "{fqbn}-compile.log".format(fqbn=board.fqbn.replace(":", "-"))
223182
log_file_path = os.path.join(data_dir, log_file_name)
224183
command_log_flags = "--log-format json --log-file {} --log-level trace".format(
225184
log_file_path
226185
)
227186
result = run_command(
228187
"compile -b {fqbn} --upload -p {address} {sketch_path} {log_flags}".format(
229-
fqbn=board.get("fqbn"),
230-
address=board.get("address"),
188+
fqbn=board.fqbn,
189+
address=board.address,
231190
sketch_path=sketch_path,
232191
log_flags=command_log_flags,
233192
)
@@ -238,16 +197,16 @@ def test_compile_and_compile_combo(run_command, data_dir):
238197
json_log_lines = log_json.readlines()
239198
expected_trace_sequence = [
240199
"Compile {sketch} for {fqbn} started".format(
241-
sketch=sketch_path, fqbn=board.get("fqbn")
200+
sketch=sketch_path, fqbn=board.fqbn
242201
),
243202
"Compile {sketch} for {fqbn} successful".format(
244-
sketch=sketch_name, fqbn=board.get("fqbn")
203+
sketch=sketch_name, fqbn=board.fqbn
245204
),
246205
"Upload {sketch} on {fqbn} started".format(
247-
sketch=sketch_path, fqbn=board.get("fqbn")
206+
sketch=sketch_path, fqbn=board.fqbn
248207
),
249208
"Upload {sketch} on {fqbn} successful".format(
250-
sketch=sketch_name, fqbn=board.get("fqbn")
209+
sketch=sketch_name, fqbn=board.fqbn
251210
),
252211
]
253212
assert is_message_sequence_in_json_log_traces(

0 commit comments

Comments
 (0)