Skip to content

Commit 19494d9

Browse files
committed
Added integration test
1 parent 1628b39 commit 19494d9

File tree

5 files changed

+106
-1
lines changed

5 files changed

+106
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
/arduino-cli.yaml
77
/wiki
88
.idea
9-
coverage_*.txt
9+
coverage_*.txt
10+
__pycache__
11+
venv

test/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Integration tests
2+
3+
This dir contains integration tests, the aim is to test the Command Line Interface and its output
4+
from a pure user point of view.
5+
6+
### Installation
7+
8+
cd test
9+
virtualenv --python=python3 venv
10+
source venv/bin/activate
11+
pip install -r requirements.txt
12+
13+
### Running tests
14+
15+
pytest

test/pytest.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[pytest]
2+
filterwarnings =
3+
error
4+
ignore::DeprecationWarning
5+
ignore::ResourceWarning
6+
7+
addopts = -s --verbose

test/requirements.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
atomicwrites==1.3.0
2+
attrs==19.1.0
3+
importlib-metadata==0.18
4+
invoke==1.2.0
5+
more-itertools==7.1.0
6+
packaging==19.0
7+
pep8==1.7.1
8+
pluggy==0.12.0
9+
py==1.8.0
10+
pyparsing==2.4.0
11+
pytest==5.0.1
12+
six==1.12.0
13+
wcwidth==0.1.7
14+
zipp==0.5.2

test/test_main.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from invoke import run, Responder
2+
import os
3+
import json
4+
5+
this_test_path = os.path.dirname(os.path.realpath(__file__))
6+
# Calculate absolute path of the CLI
7+
cli_path = os.path.join(this_test_path, '..', 'arduino-cli')
8+
9+
# Useful reference:
10+
# http://docs.pyinvoke.org/en/1.2/api/runners.html#invoke.runners.Result
11+
12+
13+
def cli_line(*args):
14+
# Accept a list of arguments cli_line('lib list --format json')
15+
# Return a full command line string e.g. 'arduino-cli help --format json'
16+
cli_full_line = ' '.join([cli_path, ' '.join(str(arg) for arg in args)])
17+
# print(cli_full_line)
18+
return cli_full_line
19+
20+
21+
def run_command(*args):
22+
result = run(cli_line(*args), echo=False, hide='out')
23+
return result
24+
25+
26+
def test_command_help():
27+
result = run_command('help')
28+
assert result.ok
29+
assert result.stderr == ''
30+
assert 'Usage' in result.stdout
31+
# result.out
32+
33+
34+
def test_command_lib_list():
35+
result = run_command('lib list')
36+
assert result.stderr == ''
37+
result = run_command('lib list', '--format json')
38+
assert '{}' == result.stdout
39+
40+
41+
def test_command_lib_install():
42+
libs = ['\"AzureIoTProtocol_MQTT\"', '\"CMMC MQTT Connector\"', '\"WiFiNINA\"']
43+
# Should be safe to run install multiple times
44+
result_1 = run_command('lib install {}'.format(' '.join(libs)))
45+
assert result_1.ok
46+
result_2 = run_command('lib install {}'.format(' '.join(libs)))
47+
assert result_2.ok
48+
49+
50+
def test_command_lib_remove():
51+
libs = ['\"AzureIoTProtocol_MQTT\"', '\"CMMC MQTT Connector\"', '\"WiFiNINA\"']
52+
result = run_command('lib uninstall {}'.format(' '.join(libs)))
53+
54+
55+
def test_command_board_list():
56+
result = run_command('board list --format json')
57+
# check is a valid json and contains a list of ports
58+
ports = json.loads(result.stdout).get('ports')
59+
assert isinstance(ports, list)
60+
for port in ports:
61+
assert 'protocol' in port
62+
assert 'protocol_label' in port
63+
64+
65+
def test_command_board_listall():
66+
result = run_command('board listall')
67+
assert ['Board', 'Name', 'FQBN'] == result.stdout.splitlines()[0].strip().split()

0 commit comments

Comments
 (0)