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