Skip to content

Commit 15e2452

Browse files
[skip changelog] Fix Windows integration tests (#1432)
* [skip changelog] Fix Windows integration tests * Update test/test_sketch.py Co-authored-by: per1234 <[email protected]> Co-authored-by: per1234 <[email protected]>
1 parent dedb99b commit 15e2452

16 files changed

+886
-759
lines changed

Diff for: test/conftest.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,16 @@ def run_command(pytestconfig, data_dir, downloads_dir, working_dir):
124124
}
125125
(Path(data_dir) / "packages").mkdir(exist_ok=True)
126126

127-
def _run(cmd_string, custom_working_dir=None, custom_env=None):
127+
def _run(cmd: list, custom_working_dir=None, custom_env=None):
128+
if cmd is None:
129+
cmd = []
130+
quoted_cmd = [f'"{t}"' for t in cmd]
128131

129132
if not custom_working_dir:
130133
custom_working_dir = working_dir
131134
if not custom_env:
132135
custom_env = env
133-
cli_full_line = '"{}" {}'.format(cli_path, cmd_string)
136+
cli_full_line = '"{}" {}'.format(cli_path, " ".join(quoted_cmd))
134137
run_context = Context()
135138
# It might happen that we need to change directories between drives on Windows,
136139
# in that case the "/d" flag must be used otherwise directory wouldn't change
@@ -157,7 +160,8 @@ def daemon_runner(pytestconfig, data_dir, downloads_dir, working_dir):
157160
http://docs.pyinvoke.org/en/1.4/api/runners.html#invoke.runners.Local
158161
http://docs.pyinvoke.org/en/1.4/api/runners.html
159162
"""
160-
cli_full_line = str(Path(pytestconfig.rootdir).parent / "arduino-cli daemon")
163+
cli_path = Path(pytestconfig.rootdir).parent / "arduino-cli"
164+
cli_full_line = f'"{cli_path}" daemon'
161165
env = {
162166
"ARDUINO_DATA_DIR": data_dir,
163167
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
@@ -197,8 +201,8 @@ def detected_boards(run_command):
197201
198202
:returns a list `Board` objects.
199203
"""
200-
assert run_command("core update-index")
201-
result = run_command("board list --format json")
204+
assert run_command(["core", "update-index"])
205+
result = run_command(["board", "list", "--format", "json"])
202206
assert result.ok
203207

204208
detected_boards = []
@@ -240,7 +244,7 @@ def _waiter(seconds=10):
240244
# available after a test upload and subsequent tests might consequently fail.
241245
time_end = time.time() + seconds
242246
while time.time() < time_end:
243-
result = run_command("board list --format json")
247+
result = run_command(["board", "list", "--format", "json"])
244248
ports = json.loads(result.stdout)
245249
if len([p.get("boards", []) for p in ports]) > 0:
246250
break

Diff for: test/test_board.py

+40-40
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@
394394

395395
@pytest.mark.skipif(running_on_ci(), reason="VMs have no serial ports")
396396
def test_board_list(run_command):
397-
run_command("core update-index")
398-
result = run_command("board list --format json")
397+
run_command(["core", "update-index"])
398+
result = run_command(["board", "list", "--format", "json"])
399399
assert result.ok
400400
# check is a valid json and contains a list of ports
401401
ports = json.loads(result.stdout)
@@ -406,9 +406,9 @@ def test_board_list(run_command):
406406

407407

408408
def test_board_listall(run_command):
409-
assert run_command("update")
410-
assert run_command("core install arduino:[email protected]")
411-
res = run_command("board listall --format json")
409+
assert run_command(["update"])
410+
assert run_command(["core", "install", "arduino:[email protected]"])
411+
res = run_command(["board", "listall", "--format", "json"])
412412
assert res.ok
413413
data = json.loads(res.stdout)
414414
boards = {b["fqbn"]: b for b in data["boards"]}
@@ -431,14 +431,14 @@ def test_board_listall(run_command):
431431

432432

433433
def test_board_listall_with_manually_installed_platform(run_command, data_dir):
434-
assert run_command("update")
434+
assert run_command(["update"])
435435

436436
# Manually installs a core in sketchbooks hardware folder
437437
git_url = "https://github.com/arduino/ArduinoCore-samd.git"
438438
repo_dir = Path(data_dir, "hardware", "arduino-beta-development", "samd")
439439
assert Repo.clone_from(git_url, repo_dir, multi_options=["-b 1.8.11"])
440440

441-
res = run_command("board listall --format json")
441+
res = run_command(["board", "listall", "--format", "json"])
442442
assert res.ok
443443
data = json.loads(res.stdout)
444444
boards = {b["fqbn"]: b for b in data["boards"]}
@@ -461,21 +461,21 @@ def test_board_listall_with_manually_installed_platform(run_command, data_dir):
461461

462462

463463
def test_board_details(run_command):
464-
run_command("core update-index")
464+
run_command(["core", "update-index"])
465465
# Download samd core pinned to 1.8.6
466-
run_command("core install arduino:[email protected]")
466+
run_command(["core", "install", "arduino:[email protected]"])
467467

468468
# Test board listall with and without showing hidden elements
469-
result = run_command("board listall MIPS --format json")
469+
result = run_command(["board", "listall", "MIPS", "--format", "json"])
470470
assert result.ok
471471
assert result.stdout == "{}\n"
472472

473-
result = run_command("board listall MIPS -a --format json")
473+
result = run_command(["board", "listall", "MIPS", "-a", "--format", "json"])
474474
assert result.ok
475475
result = json.loads(result.stdout)
476476
assert result["boards"][0]["name"] == "Arduino Tian (MIPS Console port)"
477477

478-
result = run_command("board details -b arduino:samd:nano_33_iot --format json")
478+
result = run_command(["board", "details", "-b", "arduino:samd:nano_33_iot", "--format", "json"])
479479
assert result.ok
480480
# Sort everything before compare
481481
result = json.loads(result.stdout)
@@ -494,20 +494,20 @@ def test_board_details(run_command):
494494
assert programmer in result["programmers"]
495495

496496
# Download samd core pinned to 1.8.8
497-
run_command("core install arduino:[email protected]")
497+
run_command(["core", "install", "arduino:[email protected]"])
498498

499-
result = run_command("board details -b arduino:samd:nano_33_iot --format json")
499+
result = run_command(["board", "details", "-b", "arduino:samd:nano_33_iot", "--format", "json"])
500500
assert result.ok
501501
result = json.loads(result.stdout)
502502
assert result["debugging_supported"] is True
503503

504504

505505
# old `arduino-cli board details` did not need -b <fqbn> flag to work
506506
def test_board_details_old(run_command):
507-
run_command("core update-index")
507+
run_command(["core", "update-index"])
508508
# Download samd core pinned to 1.8.6
509-
run_command("core install arduino:[email protected]")
510-
result = run_command("board details arduino:samd:nano_33_iot --format json")
509+
run_command(["core", "install", "arduino:[email protected]"])
510+
result = run_command(["board", "details", "arduino:samd:nano_33_iot", "--format", "json"])
511511
assert result.ok
512512
# Sort everything before compare
513513
result = json.loads(result.stdout)
@@ -527,20 +527,20 @@ def test_board_details_old(run_command):
527527

528528

529529
def test_board_details_no_flags(run_command):
530-
run_command("core update-index")
530+
run_command(["core", "update-index"])
531531
# Download samd core pinned to 1.8.6
532-
run_command("core install arduino:[email protected]")
533-
result = run_command("board details")
532+
run_command(["core", "install", "arduino:[email protected]"])
533+
result = run_command(["board", "details"])
534534
assert not result.ok
535535
assert "Error getting board details: Invalid FQBN:" in result.stderr
536536
assert result.stdout == ""
537537

538538

539539
def test_board_details_list_programmers_without_flag(run_command):
540-
run_command("core update-index")
540+
run_command(["core", "update-index"])
541541
# Download samd core pinned to 1.8.6
542-
run_command("core install arduino:[email protected]")
543-
result = run_command("board details -b arduino:samd:nano_33_iot")
542+
run_command(["core", "install", "arduino:[email protected]"])
543+
result = run_command(["board", "details", "-b", "arduino:samd:nano_33_iot"])
544544
assert result.ok
545545
lines = [l.strip().split() for l in result.stdout.splitlines()]
546546
assert ["Programmers:", "Id", "Name"] in lines
@@ -550,10 +550,10 @@ def test_board_details_list_programmers_without_flag(run_command):
550550

551551

552552
def test_board_details_list_programmers_flag(run_command):
553-
run_command("core update-index")
553+
run_command(["core", "update-index"])
554554
# Download samd core pinned to 1.8.6
555-
run_command("core install arduino:[email protected]")
556-
result = run_command("board details -b arduino:samd:nano_33_iot --list-programmers")
555+
run_command(["core", "install", "arduino:[email protected]"])
556+
result = run_command(["board", "details", "-b", "arduino:samd:nano_33_iot", "--list-programmers"])
557557
assert result.ok
558558

559559
lines = [l.strip() for l in result.stdout.splitlines()]
@@ -564,9 +564,9 @@ def test_board_details_list_programmers_flag(run_command):
564564

565565

566566
def test_board_search(run_command, data_dir):
567-
assert run_command("update")
567+
assert run_command(["update"])
568568

569-
res = run_command("board search --format json")
569+
res = run_command(["board", "search", "--format", "json"])
570570
assert res.ok
571571
data = json.loads(res.stdout)
572572
# Verifies boards are returned
@@ -581,7 +581,7 @@ def test_board_search(run_command, data_dir):
581581
assert "Arduino Portenta H7" in names
582582

583583
# Search in non installed boards
584-
res = run_command("board search --format json nano 33")
584+
res = run_command(["board", "search", "--format", "json", "nano", "33"])
585585
assert res.ok
586586
data = json.loads(res.stdout)
587587
# Verifies boards are returned
@@ -593,9 +593,9 @@ def test_board_search(run_command, data_dir):
593593
assert "Arduino Nano 33 IoT" in names
594594

595595
# Install a platform from index
596-
assert run_command("core install arduino:[email protected]")
596+
assert run_command(["core", "install", "arduino:[email protected]"])
597597

598-
res = run_command("board search --format json")
598+
res = run_command(["board", "search", "--format", "json"])
599599
assert res.ok
600600
data = json.loads(res.stdout)
601601
assert len(data) > 0
@@ -607,7 +607,7 @@ def test_board_search(run_command, data_dir):
607607
assert "arduino:avr:yun" in installed_boards
608608
assert "Arduino Yún" == installed_boards["arduino:avr:yun"]["name"]
609609

610-
res = run_command("board search --format json arduino yun")
610+
res = run_command(["board", "search", "--format", "json", "arduino", "yun"])
611611
assert res.ok
612612
data = json.loads(res.stdout)
613613
assert len(data) > 0
@@ -620,7 +620,7 @@ def test_board_search(run_command, data_dir):
620620
repo_dir = Path(data_dir, "hardware", "arduino-beta-development", "samd")
621621
assert Repo.clone_from(git_url, repo_dir, multi_options=["-b 1.8.11"])
622622

623-
res = run_command("board search --format json")
623+
res = run_command(["board", "search", "--format", "json"])
624624
assert res.ok
625625
data = json.loads(res.stdout)
626626
assert len(data) > 0
@@ -641,7 +641,7 @@ def test_board_search(run_command, data_dir):
641641
assert "Arduino NANO 33 IoT" == installed_boards["arduino-beta-development:samd:nano_33_iot"]["name"]
642642
assert "arduino-beta-development:samd:arduino_zero_native" in installed_boards
643643

644-
res = run_command("board search --format json mkr1000")
644+
res = run_command(["board", "search", "--format", "json", "mkr1000"])
645645
assert res.ok
646646
data = json.loads(res.stdout)
647647
assert len(data) > 0
@@ -652,25 +652,25 @@ def test_board_search(run_command, data_dir):
652652

653653

654654
def test_board_attach_without_sketch_json(run_command, data_dir):
655-
run_command("update")
655+
run_command(["update"])
656656

657657
sketch_name = "BoardAttachWithoutSketchJson"
658658
sketch_path = Path(data_dir, sketch_name)
659659
fqbn = "arduino:avr:uno"
660660

661661
# Create a test sketch
662-
assert run_command(f"sketch new {sketch_path}")
662+
assert run_command(["sketch", "new", sketch_path])
663663

664-
assert run_command(f"board attach {fqbn} {sketch_path}")
664+
assert run_command(["board", "attach", fqbn, sketch_path])
665665

666666

667667
def test_board_search_with_outdated_core(run_command):
668-
assert run_command("update")
668+
assert run_command(["update"])
669669

670670
# Install an old core version
671-
assert run_command("core install arduino:[email protected]")
671+
assert run_command(["core", "install", "arduino:[email protected]"])
672672

673-
res = run_command("board search arduino:samd:mkrwifi1010 --format json")
673+
res = run_command(["board", "search", "arduino:samd:mkrwifi1010", "--format", "json"])
674674

675675
data = json.loads(res.stdout)
676676
assert len(data) == 1

Diff for: test/test_cache.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ def test_cache_clean(run_command, data_dir):
2020
Clean the cache under arduino caching file directory which is
2121
"<Arduino configure file path>/staging"
2222
"""
23-
result = run_command("cache clean")
23+
result = run_command(["cache", "clean"])
2424
assert result.ok
2525

2626
# Generate /staging directory
27-
result = run_command("lib list")
27+
result = run_command(["lib", "list"])
2828
assert result.ok
2929

30-
result = run_command("cache clean")
30+
result = run_command(["cache", "clean"])
3131
assert result.ok
3232

3333
assert not os.path.isdir(os.path.join(data_dir, "staging"))

0 commit comments

Comments
 (0)