Skip to content

Added integration test #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 18, 2019
21 changes: 21 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest


def pytest_addoption(parser):
parser.addoption(
"--runslow", action="store_true", default=False, help="run slow tests"
)


def pytest_configure(config):
config.addinivalue_line("markers", "slow: mark test as slow to run")


def pytest_collection_modifyitems(config, items):
if config.getoption("--runslow"):
# --runslow given in cli: do not skip slow tests
return
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)
2 changes: 1 addition & 1 deletion test/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ filterwarnings =
ignore::DeprecationWarning
ignore::ResourceWarning

addopts = -s --verbose
addopts = -s --verbose --tb=short
42 changes: 39 additions & 3 deletions test/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from invoke import run, Responder
import os
import json
import pytest
import semver
from datetime import datetime

this_test_path = os.path.dirname(os.path.realpath(__file__))
# Calculate absolute path of the CLI
Expand All @@ -14,12 +17,11 @@ 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')
result = run(cli_line(*args), echo=False, hide=True)
return result


Expand All @@ -28,7 +30,6 @@ def test_command_help():
assert result.ok
assert result.stderr == ''
assert 'Usage' in result.stdout
# result.out


def test_command_lib_list():
Expand All @@ -37,6 +38,9 @@ def test_command_lib_list():
result = run_command('lib list', '--format json')
assert '{}' == result.stdout

# def test_command_lib_download():
# result = run_command('lib download')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove this before merging


def test_command_lib_install():
libs = ['\"AzureIoTProtocol_MQTT\"', '\"CMMC MQTT Connector\"', '\"WiFiNINA\"']
Expand All @@ -46,10 +50,31 @@ def test_command_lib_install():
result_2 = run_command('lib install {}'.format(' '.join(libs)))
assert result_2.ok

def test_command_lib_update_index():
result = run_command('lib update-index')
assert 'Updating index: library_index.json downloaded' == result.stdout.splitlines()[-1].strip()

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

@pytest.mark.slow
def test_command_lib_search():
result = run_command('lib search')
out_lines = result.stdout.splitlines()
libs = []
# Create an array with just the name of the vars
for line in out_lines:
if 'Name: ' in line:
libs.append(line.split()[1].strip('\"'))
number_of_libs = len(libs)
# It would be strange to have less than 2000 Arduino Libs published
assert number_of_libs > 2000
result = run_command('lib search --format json')
libs_found_from_json = json.loads(result.stdout)
number_of_libs_from_json = len(libs_found_from_json.get('libraries'))
assert number_of_libs == number_of_libs_from_json


def test_command_board_list():
Expand All @@ -65,3 +90,14 @@ def test_command_board_list():
def test_command_board_listall():
result = run_command('board listall')
assert ['Board', 'Name', 'FQBN'] == result.stdout.splitlines()[0].strip().split()


def test_command_version():
result = run_command('version --format json')
parsed_out = json.loads(result.stdout)

assert parsed_out.get('Application', False) == 'arduino-cli'
assert isinstance(semver.parse(parsed_out.get('VersionString', False)), dict)
assert isinstance(parsed_out.get('Commit', False), str)
assert datetime.strptime(parsed_out.get('BuildDate')[:-2], '%Y-%m-%dT%H:%M:%S.%f')