Skip to content

Commit e249fbf

Browse files
mastrolinuxmasci
authored andcommitted
Added integration test (#282)
* Added integration test * Added command lib search testing * Added update-index test and semver testinf for versioning * Improved error reporting, update test of version command * Avoid UnexpectedExit error so the output is more understandable, added result.ok check everywhere * Update requirements, removed unused comments * moved from custom markers to pytest.ini config for slow files * Testing with real lib names
1 parent 296c872 commit e249fbf

File tree

5 files changed

+158
-2
lines changed

5 files changed

+158
-2
lines changed

Diff for: .gitignore

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
/debug
22
/arduino-cli
33
/main
4-
/.vscode/settings.json
4+
/.vscode/
55
/cmd/formatter/debug.test
66
/arduino-cli.yaml
77
/wiki
88
.idea
9-
coverage_*.txt
9+
coverage_*.txt
10+
__pycache__
11+
venv
12+
.pytest_cache

Diff for: test/README.md

+15
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

Diff for: test/pytest.ini

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[pytest]
2+
filterwarnings =
3+
error
4+
ignore::DeprecationWarning
5+
ignore::ResourceWarning
6+
7+
markers =
8+
slow: marks tests as slow (deselect with '-m "not slow"')
9+
10+
addopts = -s --verbose --tb=short

Diff for: test/requirements.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
astroid==2.2.5
2+
atomicwrites==1.3.0
3+
attrs==19.1.0
4+
importlib-metadata==0.18
5+
invoke==1.2.0
6+
isort==4.3.21
7+
lazy-object-proxy==1.4.1
8+
mccabe==0.6.1
9+
more-itertools==7.1.0
10+
packaging==19.0
11+
pep8==1.7.1
12+
pluggy==0.12.0
13+
py==1.8.0
14+
pylint==2.3.1
15+
pyparsing==2.4.0
16+
pytest==5.0.1
17+
semver==2.8.1
18+
six==1.12.0
19+
typed-ast==1.4.0
20+
wcwidth==0.1.7
21+
wrapt==1.11.2
22+
zipp==0.5.2

Diff for: test/test_main.py

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
from invoke import run, Responder, exceptions
2+
import os
3+
import json
4+
import pytest
5+
import semver
6+
from datetime import datetime
7+
8+
this_test_path = os.path.dirname(os.path.realpath(__file__))
9+
# Calculate absolute path of the CLI
10+
cli_path = os.path.join(this_test_path, '..', 'arduino-cli')
11+
12+
# Useful reference:
13+
# http://docs.pyinvoke.org/en/1.2/api/runners.html#invoke.runners.Result
14+
15+
16+
def cli_line(*args):
17+
# Accept a list of arguments cli_line('lib list --format json')
18+
# Return a full command line string e.g. 'arduino-cli help --format json'
19+
cli_full_line = ' '.join([cli_path, ' '.join(str(arg) for arg in args)])
20+
return cli_full_line
21+
22+
23+
def run_command(*args):
24+
result = run(cli_line(*args), echo=False, hide=True, warn=True)
25+
return result
26+
27+
28+
def test_command_help():
29+
result = run_command('help')
30+
assert result.ok
31+
assert result.stderr == ''
32+
assert 'Usage' in result.stdout
33+
34+
35+
def test_command_lib_list():
36+
result = run_command('lib list')
37+
assert result.ok
38+
assert result.stderr == ''
39+
result = run_command('lib list', '--format json')
40+
assert '{}' == result.stdout
41+
42+
43+
def test_command_lib_install():
44+
libs = ['\"AzureIoTProtocol_MQTT\"', '\"CMMC MQTT Connector\"', '\"WiFiNINA\"']
45+
# Should be safe to run install multiple times
46+
result_1 = run_command('lib install {}'.format(' '.join(libs)))
47+
assert result_1.ok
48+
result_2 = run_command('lib install {}'.format(' '.join(libs)))
49+
assert result_2.ok
50+
51+
def test_command_lib_update_index():
52+
result = run_command('lib update-index')
53+
assert result.ok
54+
assert 'Updating index: library_index.json downloaded' == result.stdout.splitlines()[-1].strip()
55+
56+
def test_command_lib_remove():
57+
libs = ['\"AzureIoTProtocol_MQTT\"', '\"CMMC MQTT Connector\"', '\"WiFiNINA\"']
58+
result = run_command('lib uninstall {}'.format(' '.join(libs)))
59+
assert result.ok
60+
61+
@pytest.mark.slow
62+
def test_command_lib_search():
63+
result = run_command('lib search')
64+
assert result.ok
65+
out_lines = result.stdout.splitlines()
66+
libs = []
67+
# Create an array with just the name of the vars
68+
for line in out_lines:
69+
if 'Name: ' in line:
70+
libs.append(line.split()[1].strip('\"'))
71+
number_of_libs = len(libs)
72+
assert sorted(libs) == libs
73+
assert ['WiFi101', 'WiFi101OTA'] == [lib for lib in libs if 'WiFi101' in lib]
74+
result = run_command('lib search --format json')
75+
assert result.ok
76+
libs_found_from_json = json.loads(result.stdout)
77+
number_of_libs_from_json = len(libs_found_from_json.get('libraries'))
78+
assert number_of_libs == number_of_libs_from_json
79+
80+
81+
def test_command_board_list():
82+
result = run_command('board list --format json')
83+
assert result.ok
84+
# check is a valid json and contains a list of ports
85+
ports = json.loads(result.stdout).get('ports')
86+
assert isinstance(ports, list)
87+
for port in ports:
88+
assert 'protocol' in port
89+
assert 'protocol_label' in port
90+
91+
92+
def test_command_board_listall():
93+
result = run_command('board listall')
94+
assert result.ok
95+
assert ['Board', 'Name', 'FQBN'] == result.stdout.splitlines()[0].strip().split()
96+
97+
98+
def test_command_version():
99+
result = run_command('version --format json')
100+
assert result.ok
101+
parsed_out = json.loads(result.stdout)
102+
103+
assert parsed_out.get('Application', False) == 'arduino-cli'
104+
assert isinstance(semver.parse(parsed_out.get('VersionString', False)), dict)
105+
assert isinstance(parsed_out.get('Commit', False), str)
106+
assert datetime.strptime(parsed_out.get('BuildDate')[:-2], '%Y-%m-%dT%H:%M:%S.%f')

0 commit comments

Comments
 (0)