-
-
Notifications
You must be signed in to change notification settings - Fork 400
/
Copy pathtest_lib.py
109 lines (87 loc) · 3.62 KB
/
test_lib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# This file is part of arduino-cli.
# Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
# This software is released under the GNU General Public License version 3,
# which covers the main part of arduino-cli.
# The terms of this license can be found at:
# https://www.gnu.org/licenses/gpl-3.0.en.html
# You can be released from the requirements of the above licenses by purchasing
# a commercial license. Buying such a license is mandatory if you want to modify or
# otherwise use the software for commercial activities involving the Arduino
# software without disclosing the source code of your own applications. To purchase
# a commercial license, send an email to license@arduino.cc.
import pytest
import simplejson as json
def test_list(run_command):
# Init the environment explicitly
assert run_command("core update-index")
# When ouput is empty, nothing is printed out, no matter the output format
result = run_command("lib list")
assert result.ok
assert "" == result.stderr
assert "" == result.stdout
result = run_command("lib list --format json")
assert result.ok
assert "" == result.stderr
assert "" == result.stdout
# Install something we can list at a version older than latest
result = run_command("lib install ArduinoJson@6.11.0")
assert result.ok
# Look at the plain text output
result = run_command("lib list")
assert result.ok
assert "" == result.stderr
lines = result.stdout.strip().splitlines()
assert 2 == len(lines)
toks = lines[1].split("\t")
# be sure line contain the current version AND the available version
assert "" != toks[1]
assert "" != toks[2]
# Look at the JSON output
result = run_command("lib list --format json")
assert result.ok
assert "" == result.stderr
data = json.loads(result.stdout)
assert 1 == len(data)
# be sure data contains the available version
assert "" != data[0]["release"]["version"]
def test_install(run_command):
libs = ['"AzureIoTProtocol_MQTT"', '"CMMC MQTT Connector"', '"WiFiNINA"']
# Should be safe to run install multiple times
assert run_command("lib install {}".format(" ".join(libs)))
assert run_command("lib install {}".format(" ".join(libs)))
def test_update_index(run_command):
result = run_command("lib update-index")
assert result.ok
assert (
"Updating index: library_index.json downloaded"
== result.stdout.splitlines()[-1].strip()
)
def test_remove(run_command):
libs = ['"AzureIoTProtocol_MQTT"', '"CMMC MQTT Connector"', '"WiFiNINA"']
assert run_command("lib install {}".format(" ".join(libs)))
result = run_command("lib uninstall {}".format(" ".join(libs)))
assert result.ok
@pytest.mark.slow
def test_search(run_command):
result = run_command("lib search")
assert result.ok
out_lines = result.stdout.splitlines()
# Create an array with just the name of the vars
libs = []
for line in out_lines:
if line.startswith("Name: "):
start = line.find('"') + 1
libs.append(line[start:-1])
expected = {"WiFi101", "WiFi101OTA", "Firebase Arduino based on WiFi101"}
assert expected == {lib for lib in libs if "WiFi101" in lib}
result = run_command("lib search --format json")
assert result.ok
libs_json = json.loads(result.stdout)
assert len(libs) == len(libs_json.get("libraries"))
result = run_command("lib search")
assert result.ok
# Search for a specific target
result = run_command("lib search ArduinoJson --format json")
assert result.ok
libs_json = json.loads(result.stdout)
assert 1 == len(libs_json.get("libraries"))