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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
/arduino-cli.yaml
/wiki
.idea
coverage_*.txt
coverage_*.txt
__pycache__
venv
15 changes: 15 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Integration tests

This dir contains integration tests, the aim is to test the Command Line Interface and its output
from a pure user point of view.

### Installation

cd test
virtualenv --python=python3 venv
source venv/bin/activate
pip install -r requirements.txt

### Running tests

pytest
7 changes: 7 additions & 0 deletions test/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[pytest]
filterwarnings =
error
ignore::DeprecationWarning
ignore::ResourceWarning

addopts = -s --verbose
14 changes: 14 additions & 0 deletions test/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
atomicwrites==1.3.0
attrs==19.1.0
importlib-metadata==0.18
invoke==1.2.0
more-itertools==7.1.0
packaging==19.0
pep8==1.7.1
pluggy==0.12.0
py==1.8.0
pyparsing==2.4.0
pytest==5.0.1
six==1.12.0
wcwidth==0.1.7
zipp==0.5.2
67 changes: 67 additions & 0 deletions test/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from invoke import run, Responder
import os
import json

this_test_path = os.path.dirname(os.path.realpath(__file__))
# Calculate absolute path of the CLI
cli_path = os.path.join(this_test_path, '..', 'arduino-cli')

# Useful reference:
# http://docs.pyinvoke.org/en/1.2/api/runners.html#invoke.runners.Result


def cli_line(*args):
# Accept a list of arguments cli_line('lib list --format json')
# Return a full command line string e.g. 'arduino-cli help --format json'
cli_full_line = ' '.join([cli_path, ' '.join(str(arg) for arg in args)])
# print(cli_full_line)
return cli_full_line


def run_command(*args):
result = run(cli_line(*args), echo=False, hide='out')
return result


def test_command_help():
result = run_command('help')
assert result.ok
assert result.stderr == ''
assert 'Usage' in result.stdout
# result.out


def test_command_lib_list():
result = run_command('lib list')
assert result.stderr == ''
result = run_command('lib list', '--format json')
assert '{}' == result.stdout


def test_command_lib_install():
libs = ['\"AzureIoTProtocol_MQTT\"', '\"CMMC MQTT Connector\"', '\"WiFiNINA\"']
# Should be safe to run install multiple times
result_1 = run_command('lib install {}'.format(' '.join(libs)))
assert result_1.ok
result_2 = run_command('lib install {}'.format(' '.join(libs)))
assert result_2.ok


def test_command_lib_remove():
libs = ['\"AzureIoTProtocol_MQTT\"', '\"CMMC MQTT Connector\"', '\"WiFiNINA\"']
result = run_command('lib uninstall {}'.format(' '.join(libs)))


def test_command_board_list():
result = run_command('board list --format json')
# check is a valid json and contains a list of ports
ports = json.loads(result.stdout).get('ports')
assert isinstance(ports, list)
for port in ports:
assert 'protocol' in port
assert 'protocol_label' in port


def test_command_board_listall():
result = run_command('board listall')
assert ['Board', 'Name', 'FQBN'] == result.stdout.splitlines()[0].strip().split()