Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanocerza committed Jul 28, 2021
1 parent 6685633 commit ccdc20d
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions test/test_upload_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
# a commercial license, send an email to license@arduino.cc.

import tempfile
import sys
import hashlib
import pytest
from pathlib import Path
from dataclasses import dataclass
from typing import Union


def generate_build_dir(sketch_path):
Expand All @@ -26,13 +29,26 @@ def generate_build_dir(sketch_path):
return build_dir.resolve()


def generate_expected_output(
output: str, upload_tools: Union[dict, str], data_dir: str, upload_port: str, build_dir: str, sketch_name: str
) -> str:
if isinstance(upload_tools, str):
tool = upload_tools
else:
tool = upload_tools[sys.platform]
return output.format(
tool_executable=tool, data_dir=data_dir, upload_port=upload_port, build_dir=build_dir, sketch_name=sketch_name,
).replace("\\", "/")


testdata = [
(
"",
"arduino:avr:uno",
"arduino:avr@1.8.3",
"/dev/ttyACM0",
'"{data_dir}/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude" '
'"{data_dir}/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude"',
"{tool_executable} "
+ '"-C{data_dir}/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf" '
+ '-v -V -patmega328p -carduino "-P{upload_port}" -b115200 -D "-Uflash:w:{build_dir}/{sketch_name}.ino.hex:i"',
),
Expand All @@ -41,7 +57,8 @@ def generate_build_dir(sketch_path):
"arduino:avr:leonardo",
"arduino:avr@1.8.3",
"/dev/ttyACM999",
'"{data_dir}/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude" '
'"{data_dir}/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude"',
"{tool_executable} "
+ '"-C{data_dir}/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf" '
+ '-v -V -patmega32u4 -cavr109 "-P{upload_port}0" -b57600 -D "-Uflash:w:{build_dir}/{sketch_name}.ino.hex:i"',
),
Expand All @@ -50,7 +67,8 @@ def generate_build_dir(sketch_path):
"adafruit:avr:flora8",
"adafruit:avr@1.4.13",
"/dev/ttyACM0",
'"{data_dir}/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude" '
'"{data_dir}/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude"',
"{tool_executable} "
+ '"-C{data_dir}/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf" '
+ '-v -patmega32u4 -cavr109 -P{upload_port} -b57600 -D "-Uflash:w:{build_dir}/{sketch_name}.ino.hex:i"',
),
Expand All @@ -59,7 +77,8 @@ def generate_build_dir(sketch_path):
"adafruit:avr:flora8",
"adafruit:avr@1.4.13",
"/dev/ttyACM999",
'"{data_dir}/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude" '
'"{data_dir}/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude"',
"{tool_executable} "
+ '"-C{data_dir}/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf" '
+ '-v -patmega32u4 -cavr109 -P{upload_port}0 -b57600 -D "-Uflash:w:{build_dir}/{sketch_name}.ino.hex:i"',
),
Expand All @@ -68,7 +87,12 @@ def generate_build_dir(sketch_path):
"esp32:esp32:esp32thing",
"esp32:esp32@1.0.6",
"/dev/ttyACM0",
'python "{data_dir}/packages/esp32/tools/esptool_py/3.0.0/esptool.py" '
{
"linux": 'python "{data_dir}/packages/esp32/tools/esptool_py/3.0.0/esptool.py"',
"darwin": '"{data_dir}/packages/esp32/tools/esptool_py/3.0.0/esptool.py"',
"win32": '"{data_dir}/packages/esp32/tools/esptool_py/3.0.0/esptool.exe"',
},
"{tool_executable} "
+ '--chip esp32 --port "{upload_port}" --baud 921600 --before default_reset '
+ "--after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 "
+ '"{data_dir}/packages/esp32/hardware/esp32/1.0.6/tools/partitions/boot_app0.bin" 0x1000 '
Expand All @@ -80,7 +104,8 @@ def generate_build_dir(sketch_path):
"esp8266:esp8266:generic",
"esp8266:esp8266@3.0.1",
"/dev/ttyACM0",
'"{data_dir}/packages/esp8266/tools/python3/3.7.2-post1/python3" '
'"{data_dir}/packages/esp8266/tools/python3/3.7.2-post1/python3"',
"{tool_executable} "
+ '"{data_dir}/packages/esp8266/hardware/esp8266/3.0.1/tools/upload.py" '
+ '--chip esp8266 --port "{upload_port}" --baud "115200" "" '
+ "--before default_reset --after hard_reset write_flash 0x0 "
Expand All @@ -89,17 +114,19 @@ def generate_build_dir(sketch_path):
]


@pytest.mark.parametrize("index, fqbn, core, upload_port, expected_output", testdata)
def test_upload_sketch(run_command, session_data_dir, downloads_dir, index, fqbn, core, upload_port, expected_output):
@pytest.mark.parametrize("package_index, fqbn, core, upload_port, upload_tools, output", testdata)
def test_upload_sketch(
run_command, session_data_dir, downloads_dir, package_index, fqbn, core, upload_port, upload_tools, output
):
env = {
"ARDUINO_DATA_DIR": session_data_dir,
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
"ARDUINO_SKETCHBOOK_DIR": session_data_dir,
}

if index:
if package_index:
assert run_command("config init --overwrite", custom_env=env)
assert run_command(f"config add board_manager.additional_urls {index}", custom_env=env)
assert run_command(f"config add board_manager.additional_urls {package_index}", custom_env=env)
assert run_command("update", custom_env=env)

assert run_command(f"core install {core}", custom_env=env)
Expand All @@ -115,6 +142,11 @@ def test_upload_sketch(run_command, session_data_dir, downloads_dir, index, fqbn
res = run_command(f'upload -p {upload_port} -b {fqbn} "{sketch_path}" --dry-run -v', custom_env=env)
assert res.ok

assert expected_output.format(
data_dir=session_data_dir, upload_port=upload_port, build_dir=build_dir, sketch_name=sketch_name
).replace("\\", "/") in res.stdout.replace("\\", "/")
generate_expected_output(
output=output,
upload_tools=upload_tools,
data_dir=session_data_dir,
upload_port=upload_port,
build_dir=build_dir,
sketch_name=sketch_name,
) in res.stdout.replace("\\", "/")

0 comments on commit ccdc20d

Please sign in to comment.