Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[skip changelog] Fix tests on Windows
  • Loading branch information
silvanocerza committed Sep 3, 2020
commit 5dbeb05189ad557a511108de13af51df61994c2e
3 changes: 2 additions & 1 deletion commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net/url"
"os"
"path"
"path/filepath"
"strings"

"github.com/arduino/arduino-cli/arduino/builder"
Expand Down Expand Up @@ -779,7 +780,7 @@ func ArchiveSketch(ctx context.Context, req *rpc.ArchiveSketchReq) (*rpc.Archive
}

// Skips build folder
if strings.HasPrefix(filePath.String(), sketchName+"/build") {
if strings.HasPrefix(filePath.String(), sketchName+string(filepath.Separator)+"build") {
continue
}
}
Expand Down
32 changes: 25 additions & 7 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import platform
import signal
from pathlib import Path

import pytest
import simplejson as json
Expand Down Expand Up @@ -84,20 +85,29 @@ def run_command(pytestconfig, data_dir, downloads_dir, working_dir):
Useful reference:
http://docs.pyinvoke.org/en/1.4/api/runners.html#invoke.runners.Result
"""
cli_path = os.path.join(str(pytestconfig.rootdir), "..", "arduino-cli")

cli_path = Path(pytestconfig.rootdir).parent / "arduino-cli"
env = {
"ARDUINO_DATA_DIR": data_dir,
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
"ARDUINO_SKETCHBOOK_DIR": data_dir,
}
os.makedirs(os.path.join(data_dir, "packages"))
(Path(data_dir) / "packages").mkdir()

def _run(cmd_string, custom_working_dir=None):
if not custom_working_dir:
custom_working_dir = working_dir
cli_full_line = "{} {}".format(cli_path, cmd_string)
cli_full_line = '"{}" {}'.format(cli_path, cmd_string)
run_context = Context()
with run_context.cd(custom_working_dir):
# 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
cd_command = "cd"
if platform.system() == "Windows":
cd_command += " /d"
# Context.cd() is not used since it doesn't work correctly on Windows.
# It escapes spaces in the path using "\ " but it doesn't always work,
# wrapping the path in quotation marks is the safest approach
with run_context.prefix(f'{cd_command} "{custom_working_dir}"'):
return run_context.run(cli_full_line, echo=False, hide=True, warn=True, env=env)

return _run
Expand All @@ -114,15 +124,23 @@ 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 = os.path.join(str(pytestconfig.rootdir), "..", "arduino-cli daemon")
cli_full_line = str(Path(pytestconfig.rootdir).parent / "arduino-cli daemon")
env = {
"ARDUINO_DATA_DIR": data_dir,
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
"ARDUINO_SKETCHBOOK_DIR": data_dir,
}
os.makedirs(os.path.join(data_dir, "packages"))
(Path(data_dir) / "packages").mkdir()
run_context = Context()
run_context.cd(working_dir)
# 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
cd_command = "cd"
if platform.system() == "Windows":
cd_command += " /d"
# Context.cd() is not used since it doesn't work correctly on Windows.
# It escapes spaces in the path using "\ " but it doesn't always work,
# wrapping the path in quotation marks is the safest approach
run_context.prefix(f'{cd_command} "{working_dir}"')
# Local Class is the implementation of a Runner abstract class
runner = Local(run_context)
runner.run(cli_full_line, echo=False, hide=True, warn=True, env=env, asynchronous=True)
Expand Down
56 changes: 30 additions & 26 deletions test/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def test_archive_dot_arg_absolute_zip_path(run_command, copy_sketch, working_dir
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive . {archives_folder}", copy_sketch)
result = run_command(f'archive . "{archives_folder}"', copy_sketch)
print(result.stderr)
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/sketch_simple.zip")
Expand Down Expand Up @@ -165,7 +166,7 @@ def test_archive_dot_arg_absolute_zip_path_and_name_without_extension(run_comman
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive . {archives_folder}/my_custom_sketch", copy_sketch)
result = run_command(f'archive . "{archives_folder}/my_custom_sketch"', copy_sketch)
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/my_custom_sketch.zip")
Expand Down Expand Up @@ -193,7 +194,7 @@ def test_archive_dot_arg_custom_zip_path_and_name_with_extension(run_command, co
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive . {archives_folder}/my_custom_sketch.zip", copy_sketch)
result = run_command(f'archive . "{archives_folder}/my_custom_sketch.zip"', copy_sketch)
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/my_custom_sketch.zip")
Expand Down Expand Up @@ -241,7 +242,7 @@ def test_archive_relative_sketch_path(run_command, copy_sketch, working_dir):


def test_archive_absolute_sketch_path(run_command, copy_sketch, working_dir):
result = run_command(f"archive {working_dir}/sketch_simple", copy_sketch)
result = run_command(f'archive "{working_dir}/sketch_simple"', copy_sketch)
assert result.ok

archive = zipfile.ZipFile(f"{working_dir}/sketch_simple.zip")
Expand Down Expand Up @@ -297,7 +298,7 @@ def test_archive_relative_sketch_path_with_absolute_zip_path(run_command, copy_s
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive ./sketch_simple {archives_folder}")
result = run_command(f'archive ./sketch_simple "{archives_folder}"')
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/sketch_simple.zip")
Expand Down Expand Up @@ -387,7 +388,7 @@ def test_archive_relative_sketch_path_with_absolute_zip_path_and_name_without_ex
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive ./sketch_simple {archives_folder}/my_custom_sketch")
result = run_command(f'archive ./sketch_simple "{archives_folder}/my_custom_sketch"')
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/my_custom_sketch.zip")
Expand Down Expand Up @@ -417,7 +418,7 @@ def test_archive_relative_sketch_path_with_absolute_zip_path_and_name_with_exten
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive ./sketch_simple {archives_folder}/my_custom_sketch.zip")
result = run_command(f'archive ./sketch_simple "{archives_folder}/my_custom_sketch.zip"')
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/my_custom_sketch.zip")
Expand Down Expand Up @@ -445,7 +446,7 @@ def test_archive_absolute_sketch_path_with_relative_zip_path(run_command, copy_s
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive {working_dir}/sketch_simple ./my_archives")
result = run_command(f'archive "{working_dir}/sketch_simple" ./my_archives')
assert result.ok

archive = zipfile.ZipFile(f"{working_dir}/my_archives/sketch_simple.zip")
Expand Down Expand Up @@ -473,7 +474,7 @@ def test_archive_absolute_sketch_path_with_absolute_zip_path(run_command, copy_s
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive {working_dir}/sketch_simple {archives_folder}", copy_sketch)
result = run_command(f'archive "{working_dir}/sketch_simple" "{archives_folder}"', copy_sketch)
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/sketch_simple.zip")
Expand Down Expand Up @@ -503,7 +504,7 @@ def test_archive_absolute_sketch_path_with_relative_zip_path_and_name_without_ex
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive {working_dir}/sketch_simple ./my_archives/my_custom_sketch")
result = run_command(f'archive "{working_dir}/sketch_simple" ./my_archives/my_custom_sketch')
assert result.ok

archive = zipfile.ZipFile(f"{working_dir}/my_archives/my_custom_sketch.zip")
Expand Down Expand Up @@ -533,7 +534,7 @@ def test_archive_absolute_sketch_path_with_relative_zip_path_and_name_with_exten
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive {working_dir}/sketch_simple ./my_archives/my_custom_sketch.zip")
result = run_command(f'archive "{working_dir}/sketch_simple" ./my_archives/my_custom_sketch.zip')
assert result.ok

archive = zipfile.ZipFile(f"{working_dir}/my_archives/my_custom_sketch.zip")
Expand Down Expand Up @@ -563,7 +564,7 @@ def test_archive_absolute_sketch_path_with_absolute_zip_path_and_name_without_ex
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive {working_dir}/sketch_simple {archives_folder}/my_custom_sketch", copy_sketch)
result = run_command(f'archive "{working_dir}/sketch_simple" "{archives_folder}/my_custom_sketch"', copy_sketch)
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/my_custom_sketch.zip")
Expand Down Expand Up @@ -593,7 +594,7 @@ def test_archive_absolute_sketch_path_with_absolute_zip_path_and_name_with_exten
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive {working_dir}/sketch_simple {archives_folder}/my_custom_sketch.zip", copy_sketch)
result = run_command(f'archive "{working_dir}/sketch_simple" "{archives_folder}/my_custom_sketch.zip"', copy_sketch)
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/my_custom_sketch.zip")
Expand Down Expand Up @@ -697,7 +698,7 @@ def test_archive_dot_arg_absolute_zip_path_with_include_build_dir_flag(run_comma
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive . {archives_folder} --include-build-dir", copy_sketch)
result = run_command(f'archive . "{archives_folder}" --include-build-dir', copy_sketch)
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/sketch_simple.zip")
Expand Down Expand Up @@ -757,7 +758,7 @@ def test_archive_dot_arg_absolute_zip_path_and_name_without_extension_with_inclu
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive . {archives_folder}/my_custom_sketch --include-build-dir", copy_sketch)
result = run_command(f'archive . "{archives_folder}/my_custom_sketch" --include-build-dir', copy_sketch)
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/my_custom_sketch.zip")
Expand Down Expand Up @@ -787,7 +788,7 @@ def test_archive_dot_arg_custom_zip_path_and_name_with_extension_with_include_bu
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive . {archives_folder}/my_custom_sketch.zip --include-build-dir", copy_sketch)
result = run_command(f'archive . "{archives_folder}/my_custom_sketch.zip" --include-build-dir', copy_sketch)
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/my_custom_sketch.zip")
Expand Down Expand Up @@ -835,7 +836,7 @@ def test_archive_relative_sketch_path_with_include_build_dir_flag(run_command, c


def test_archive_absolute_sketch_path_with_include_build_dir_flag(run_command, copy_sketch, working_dir):
result = run_command(f"archive {working_dir}/sketch_simple --include-build-dir", copy_sketch)
result = run_command(f'archive "{working_dir}/sketch_simple" --include-build-dir', copy_sketch)
assert result.ok

archive = zipfile.ZipFile(f"{working_dir}/sketch_simple.zip")
Expand Down Expand Up @@ -895,7 +896,7 @@ def test_archive_relative_sketch_path_with_absolute_zip_path_with_include_build_
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive ./sketch_simple {archives_folder} --include-build-dir")
result = run_command(f'archive ./sketch_simple "{archives_folder}" --include-build-dir')
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/sketch_simple.zip")
Expand Down Expand Up @@ -985,7 +986,7 @@ def test_archive_relative_sketch_path_with_absolute_zip_path_and_name_without_ex
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive ./sketch_simple {archives_folder}/my_custom_sketch --include-build-dir")
result = run_command(f'archive ./sketch_simple "{archives_folder}/my_custom_sketch" --include-build-dir')
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/my_custom_sketch.zip")
Expand Down Expand Up @@ -1015,7 +1016,7 @@ def test_archive_relative_sketch_path_with_absolute_zip_path_and_name_with_exten
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive ./sketch_simple {archives_folder}/my_custom_sketch.zip --include-build-dir")
result = run_command(f'archive ./sketch_simple "{archives_folder}/my_custom_sketch.zip" --include-build-dir')
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/my_custom_sketch.zip")
Expand Down Expand Up @@ -1045,7 +1046,7 @@ def test_archive_absolute_sketch_path_with_relative_zip_path_with_include_build_
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive {working_dir}/sketch_simple ./my_archives --include-build-dir")
result = run_command(f'archive "{working_dir}/sketch_simple" ./my_archives --include-build-dir')
assert result.ok

archive = zipfile.ZipFile(f"{working_dir}/my_archives/sketch_simple.zip")
Expand Down Expand Up @@ -1075,7 +1076,7 @@ def test_archive_absolute_sketch_path_with_absolute_zip_path_with_include_build_
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive {working_dir}/sketch_simple {archives_folder} --include-build-dir", copy_sketch)
result = run_command(f'archive "{working_dir}/sketch_simple" "{archives_folder}" --include-build-dir', copy_sketch)
assert result.ok

archive = zipfile.ZipFile(f"{archives_folder}/sketch_simple.zip")
Expand Down Expand Up @@ -1105,7 +1106,7 @@ def test_archive_absolute_sketch_path_with_relative_zip_path_and_name_without_ex
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive {working_dir}/sketch_simple ./my_archives/my_custom_sketch --include-build-dir")
result = run_command(f'archive "{working_dir}/sketch_simple" ./my_archives/my_custom_sketch --include-build-dir')
assert result.ok

archive = zipfile.ZipFile(f"{working_dir}/my_archives/my_custom_sketch.zip")
Expand Down Expand Up @@ -1135,7 +1136,9 @@ def test_archive_absolute_sketch_path_with_relative_zip_path_and_name_with_exten
archives_folder = f"{working_dir}/my_archives/"
Path(archives_folder).mkdir()

result = run_command(f"archive {working_dir}/sketch_simple ./my_archives/my_custom_sketch.zip --include-build-dir")
result = run_command(
f'archive "{working_dir}/sketch_simple" ./my_archives/my_custom_sketch.zip --include-build-dir'
)
assert result.ok

archive = zipfile.ZipFile(f"{working_dir}/my_archives/my_custom_sketch.zip")
Expand Down Expand Up @@ -1166,7 +1169,7 @@ def test_archive_absolute_sketch_path_with_absolute_zip_path_and_name_without_ex
Path(archives_folder).mkdir()

result = run_command(
f"archive {working_dir}/sketch_simple {archives_folder}/my_custom_sketch --include-build-dir", copy_sketch
f'archive "{working_dir}/sketch_simple" "{archives_folder}/my_custom_sketch" --include-build-dir', copy_sketch
)
assert result.ok

Expand Down Expand Up @@ -1198,7 +1201,8 @@ def test_archive_absolute_sketch_path_with_absolute_zip_path_and_name_with_exten
Path(archives_folder).mkdir()

result = run_command(
f"archive {working_dir}/sketch_simple {archives_folder}/my_custom_sketch.zip --include-build-dir", copy_sketch
f'archive "{working_dir}/sketch_simple" "{archives_folder}/my_custom_sketch.zip" --include-build-dir',
copy_sketch,
)
assert result.ok

Expand Down
6 changes: 3 additions & 3 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# otherwise use the software for commercial activities involving the Arduino
# software without disclosing the source code of your own applications. To purchase
# a commercial license, send an email to license@arduino.cc.
import os
from pathlib import Path


def test_init(run_command, data_dir, working_dir):
Expand All @@ -22,7 +22,7 @@ def test_init(run_command, data_dir, working_dir):


def test_init_dest(run_command, working_dir):
dest = os.path.join(working_dir, "config", "test")
result = run_command("config init --dest-dir " + dest)
dest = str(Path(working_dir) / "config" / "test")
result = run_command(f'config init --dest-dir "{dest}"')
assert result.ok
assert dest in result.stdout