Skip to content

Commit a9fb4cd

Browse files
committed
Added command lib search testing
1 parent 19494d9 commit a9fb4cd

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

test/conftest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
3+
4+
def pytest_addoption(parser):
5+
parser.addoption(
6+
"--runslow", action="store_true", default=False, help="run slow tests"
7+
)
8+
9+
10+
def pytest_configure(config):
11+
config.addinivalue_line("markers", "slow: mark test as slow to run")
12+
13+
14+
def pytest_collection_modifyitems(config, items):
15+
if config.getoption("--runslow"):
16+
# --runslow given in cli: do not skip slow tests
17+
return
18+
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
19+
for item in items:
20+
if "slow" in item.keywords:
21+
item.add_marker(skip_slow)

test/pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ filterwarnings =
44
ignore::DeprecationWarning
55
ignore::ResourceWarning
66

7-
addopts = -s --verbose
7+
addopts = -s --verbose --runslow

test/test_main.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from invoke import run, Responder
22
import os
33
import json
4+
import pytest
45

56
this_test_path = os.path.dirname(os.path.realpath(__file__))
67
# Calculate absolute path of the CLI
@@ -14,12 +15,11 @@ def cli_line(*args):
1415
# Accept a list of arguments cli_line('lib list --format json')
1516
# Return a full command line string e.g. 'arduino-cli help --format json'
1617
cli_full_line = ' '.join([cli_path, ' '.join(str(arg) for arg in args)])
17-
# print(cli_full_line)
1818
return cli_full_line
1919

2020

2121
def run_command(*args):
22-
result = run(cli_line(*args), echo=False, hide='out')
22+
result = run(cli_line(*args), echo=False, hide=True)
2323
return result
2424

2525

@@ -28,7 +28,6 @@ def test_command_help():
2828
assert result.ok
2929
assert result.stderr == ''
3030
assert 'Usage' in result.stdout
31-
# result.out
3231

3332

3433
def test_command_lib_list():
@@ -50,6 +49,24 @@ def test_command_lib_install():
5049
def test_command_lib_remove():
5150
libs = ['\"AzureIoTProtocol_MQTT\"', '\"CMMC MQTT Connector\"', '\"WiFiNINA\"']
5251
result = run_command('lib uninstall {}'.format(' '.join(libs)))
52+
assert result.ok
53+
54+
@pytest.mark.slow
55+
def test_command_lib_search():
56+
result = run_command('lib search')
57+
out_lines = result.stdout.splitlines()
58+
libs = []
59+
# Create an array with just the name of the vars
60+
for line in out_lines:
61+
if 'Name: ' in line:
62+
libs.append(line.split()[1].strip('\"'))
63+
number_of_libs = len(libs)
64+
# It would be strange to have less than 2000 Arduino Libs published
65+
assert number_of_libs > 2000
66+
result = run_command('lib search --format json')
67+
libs_found_from_json = json.loads(result.stdout)
68+
number_of_libs_from_json = len(libs_found_from_json.get('libraries'))
69+
assert number_of_libs == number_of_libs_from_json
5370

5471

5572
def test_command_board_list():
@@ -65,3 +82,12 @@ def test_command_board_list():
6582
def test_command_board_listall():
6683
result = run_command('board listall')
6784
assert ['Board', 'Name', 'FQBN'] == result.stdout.splitlines()[0].strip().split()
85+
86+
def test_command_version():
87+
result = run_command('version --format json')
88+
parsed_out = json.loads(result.stdout)
89+
90+
assert parsed_out.get('command', False) == 'arduino-cli'
91+
assert parsed_out.get('version', False)
92+
assert parsed_out.get('commit', False)
93+
assert parsed_out.get('build_date', False)

0 commit comments

Comments
 (0)