Skip to content

[skip changelog] Fix Windows integration tests #1432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ def run_command(pytestconfig, data_dir, downloads_dir, working_dir):
}
(Path(data_dir) / "packages").mkdir(exist_ok=True)

def _run(cmd_string, custom_working_dir=None, custom_env=None):
def _run(cmd: list, custom_working_dir=None, custom_env=None):
if cmd is None:
cmd = []
quoted_cmd = [f'"{t}"' for t in cmd]

if not custom_working_dir:
custom_working_dir = working_dir
if not custom_env:
custom_env = env
cli_full_line = '"{}" {}'.format(cli_path, cmd_string)
cli_full_line = '"{}" {}'.format(cli_path, " ".join(quoted_cmd))
run_context = Context()
# It might happen that we need to change directories between drives on Windows,
# in that case the "/d" flag must be used otherwise directory wouldn't change
Expand All @@ -157,7 +160,8 @@ def daemon_runner(pytestconfig, data_dir, downloads_dir, working_dir):
http://docs.pyinvoke.org/en/1.4/api/runners.html#invoke.runners.Local
http://docs.pyinvoke.org/en/1.4/api/runners.html
"""
cli_full_line = str(Path(pytestconfig.rootdir).parent / "arduino-cli daemon")
cli_path = Path(pytestconfig.rootdir).parent / "arduino-cli"
cli_full_line = f'"{cli_path}" daemon'
env = {
"ARDUINO_DATA_DIR": data_dir,
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
Expand Down Expand Up @@ -197,8 +201,8 @@ def detected_boards(run_command):

:returns a list `Board` objects.
"""
assert run_command("core update-index")
result = run_command("board list --format json")
assert run_command(["core", "update-index"])
result = run_command(["board", "list", "--format", "json"])
assert result.ok

detected_boards = []
Expand Down Expand Up @@ -240,7 +244,7 @@ def _waiter(seconds=10):
# available after a test upload and subsequent tests might consequently fail.
time_end = time.time() + seconds
while time.time() < time_end:
result = run_command("board list --format json")
result = run_command(["board", "list", "--format", "json"])
ports = json.loads(result.stdout)
if len([p.get("boards", []) for p in ports]) > 0:
break
Expand Down
80 changes: 40 additions & 40 deletions test/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@

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


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


def test_board_listall_with_manually_installed_platform(run_command, data_dir):
assert run_command("update")
assert run_command(["update"])

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

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


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

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

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

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

# Download samd core pinned to 1.8.8
run_command("core install arduino:[email protected]")
run_command(["core", "install", "arduino:[email protected]"])

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


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


def test_board_details_no_flags(run_command):
run_command("core update-index")
run_command(["core", "update-index"])
# Download samd core pinned to 1.8.6
run_command("core install arduino:[email protected]")
result = run_command("board details")
run_command(["core", "install", "arduino:[email protected]"])
result = run_command(["board", "details"])
assert not result.ok
assert "Error getting board details: Invalid FQBN:" in result.stderr
assert result.stdout == ""


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


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

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


def test_board_search(run_command, data_dir):
assert run_command("update")
assert run_command(["update"])

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

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

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

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

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

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

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


def test_board_attach_without_sketch_json(run_command, data_dir):
run_command("update")
run_command(["update"])

sketch_name = "BoardAttachWithoutSketchJson"
sketch_path = Path(data_dir, sketch_name)
fqbn = "arduino:avr:uno"

# Create a test sketch
assert run_command(f"sketch new {sketch_path}")
assert run_command(["sketch", "new", sketch_path])

assert run_command(f"board attach {fqbn} {sketch_path}")
assert run_command(["board", "attach", fqbn, sketch_path])


def test_board_search_with_outdated_core(run_command):
assert run_command("update")
assert run_command(["update"])

# Install an old core version
assert run_command("core install arduino:[email protected]")
assert run_command(["core", "install", "arduino:[email protected]"])

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

data = json.loads(res.stdout)
assert len(data) == 1
Expand Down
6 changes: 3 additions & 3 deletions test/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ def test_cache_clean(run_command, data_dir):
Clean the cache under arduino caching file directory which is
"<Arduino configure file path>/staging"
"""
result = run_command("cache clean")
result = run_command(["cache", "clean"])
assert result.ok

# Generate /staging directory
result = run_command("lib list")
result = run_command(["lib", "list"])
assert result.ok

result = run_command("cache clean")
result = run_command(["cache", "clean"])
assert result.ok

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