forked from platformio/platformio-core
Refactor CMD:LIB tests
This commit is contained in:
@ -35,25 +35,11 @@ def test_search(clirunner, validate_cliresult):
|
||||
def test_global_install_registry(clirunner, validate_cliresult,
|
||||
isolated_pio_home):
|
||||
result = clirunner.invoke(cmd_lib, [
|
||||
"-g", "install", "58", "547@2.2.4", "DallasTemperature",
|
||||
"http://dl.platformio.org/libraries/archives/3/5174.tar.gz",
|
||||
"ArduinoJson@5.6.7", "ArduinoJson@~5.7.0", "999@77d4eb3f8a"
|
||||
"-g", "install", "64", "ArduinoJson@~5.10.0", "547@2.2.4",
|
||||
"AsyncMqttClient@<=0.8.2", "999@77d4eb3f8a"
|
||||
])
|
||||
validate_cliresult(result)
|
||||
|
||||
# check lib with duplicate URL
|
||||
result = clirunner.invoke(cmd_lib, [
|
||||
"-g", "install",
|
||||
"http://dl.platformio.org/libraries/archives/3/5174.tar.gz"
|
||||
])
|
||||
validate_cliresult(result)
|
||||
assert "is already installed" in result.output
|
||||
|
||||
# check lib with duplicate ID
|
||||
result = clirunner.invoke(cmd_lib, ["-g", "install", "305"])
|
||||
validate_cliresult(result)
|
||||
assert "is already installed" in result.output
|
||||
|
||||
# install unknown library
|
||||
result = clirunner.invoke(cmd_lib, ["-g", "install", "Unknown"])
|
||||
assert result.exit_code != 0
|
||||
@ -61,8 +47,8 @@ def test_global_install_registry(clirunner, validate_cliresult,
|
||||
|
||||
items1 = [d.basename for d in isolated_pio_home.join("lib").listdir()]
|
||||
items2 = [
|
||||
"ArduinoJson_ID64", "ArduinoJson_ID64@5.6.7", "DallasTemperature_ID54",
|
||||
"DHT22_ID58", "ESPAsyncTCP_ID305", "NeoPixelBus_ID547", "OneWire_ID1",
|
||||
"ArduinoJson_ID64", "ArduinoJson_ID64@5.10.1", "NeoPixelBus_ID547",
|
||||
"AsyncMqttClient_ID346", "ESPAsyncTCP_ID305", "AsyncTCP_ID1826",
|
||||
"RFcontrol_ID999"
|
||||
]
|
||||
assert set(items1) == set(items2)
|
||||
@ -71,11 +57,12 @@ def test_global_install_registry(clirunner, validate_cliresult,
|
||||
def test_global_install_archive(clirunner, validate_cliresult,
|
||||
isolated_pio_home):
|
||||
result = clirunner.invoke(cmd_lib, [
|
||||
"-g", "install", "https://github.com/adafruit/Adafruit-ST7735-Library/"
|
||||
"archive/master.zip",
|
||||
"-g", "install",
|
||||
"http://www.airspayce.com/mikem/arduino/RadioHead/RadioHead-1.62.zip",
|
||||
"https://github.com/bblanchon/ArduinoJson/archive/v5.8.2.zip",
|
||||
"https://github.com/bblanchon/ArduinoJson/archive/v5.8.2.zip@5.8.2"
|
||||
"https://github.com/bblanchon/ArduinoJson/archive/v5.8.2.zip@5.8.2",
|
||||
"http://dl.platformio.org/libraries/archives/0/9540.tar.gz",
|
||||
"https://github.com/adafruit/Adafruit-ST7735-Library/archive/master.zip"
|
||||
])
|
||||
validate_cliresult(result)
|
||||
|
||||
@ -86,16 +73,11 @@ def test_global_install_archive(clirunner, validate_cliresult,
|
||||
])
|
||||
assert result.exit_code != 0
|
||||
|
||||
# check lib with duplicate URL
|
||||
result = clirunner.invoke(cmd_lib, [
|
||||
"-g", "install",
|
||||
"http://www.airspayce.com/mikem/arduino/RadioHead/RadioHead-1.62.zip"
|
||||
])
|
||||
validate_cliresult(result)
|
||||
assert "is already installed" in result.output
|
||||
|
||||
items1 = [d.basename for d in isolated_pio_home.join("lib").listdir()]
|
||||
items2 = ["Adafruit ST7735 Library", "RadioHead-1.62"]
|
||||
items2 = [
|
||||
"RadioHead-1.62", "ArduinoJson", "DallasTemperature_ID54",
|
||||
"OneWire_ID1", "Adafruit ST7735 Library"
|
||||
]
|
||||
assert set(items1) >= set(items2)
|
||||
|
||||
|
||||
@ -112,18 +94,41 @@ def test_global_install_repository(clirunner, validate_cliresult,
|
||||
"https://gitlab.com/ivankravets/rs485-nodeproto.git",
|
||||
"https://github.com/platformio/platformio-libmirror.git",
|
||||
# "https://developer.mbed.org/users/simon/code/TextLCD/",
|
||||
"knolleary/pubsubclient"
|
||||
"knolleary/pubsubclient#bef58148582f956dfa772687db80c44e2279a163"
|
||||
])
|
||||
validate_cliresult(result)
|
||||
items1 = [d.basename for d in isolated_pio_home.join("lib").listdir()]
|
||||
items2 = [
|
||||
"PJON", "PJON@src-79de467ebe19de18287becff0a1fb42d",
|
||||
"ArduinoJson@src-69ebddd821f771debe7ee734d3c7fa81", "rs485-nodeproto",
|
||||
"PubSubClient"
|
||||
"platformio-libmirror", "PubSubClient"
|
||||
]
|
||||
assert set(items1) >= set(items2)
|
||||
|
||||
# check lib with duplicate URL
|
||||
|
||||
def test_install_duplicates(clirunner, validate_cliresult, without_internet):
|
||||
# registry
|
||||
result = clirunner.invoke(cmd_lib, [
|
||||
"-g", "install",
|
||||
"http://dl.platformio.org/libraries/archives/0/9540.tar.gz"
|
||||
])
|
||||
validate_cliresult(result)
|
||||
assert "is already installed" in result.output
|
||||
|
||||
# by ID
|
||||
result = clirunner.invoke(cmd_lib, ["-g", "install", "999"])
|
||||
validate_cliresult(result)
|
||||
assert "is already installed" in result.output
|
||||
|
||||
# archive
|
||||
result = clirunner.invoke(cmd_lib, [
|
||||
"-g", "install",
|
||||
"http://www.airspayce.com/mikem/arduino/RadioHead/RadioHead-1.62.zip"
|
||||
])
|
||||
validate_cliresult(result)
|
||||
assert "is already installed" in result.output
|
||||
|
||||
# repository
|
||||
result = clirunner.invoke(cmd_lib, [
|
||||
"-g", "install",
|
||||
"https://github.com/platformio/platformio-libmirror.git"
|
||||
@ -135,23 +140,44 @@ def test_global_install_repository(clirunner, validate_cliresult,
|
||||
def test_global_lib_list(clirunner, validate_cliresult):
|
||||
result = clirunner.invoke(cmd_lib, ["-g", "list"])
|
||||
validate_cliresult(result)
|
||||
assert all([n in result.output for n in ("OneWire", "DHT22", "64")])
|
||||
assert all([
|
||||
n in result.output
|
||||
for n in
|
||||
("Source: https://github.com/adafruit/Adafruit-ST7735-Library/archive/master.zip",
|
||||
"Version: 5.10.1",
|
||||
"Source: git+https://github.com/gioblu/PJON.git#3.0",
|
||||
"Version: 1fb26fd", "RadioHead-1.62")
|
||||
])
|
||||
|
||||
result = clirunner.invoke(cmd_lib, ["-g", "list", "--json-output"])
|
||||
assert all([
|
||||
n in result.output
|
||||
for n in (
|
||||
"PJON", "git+https://github.com/knolleary/pubsubclient",
|
||||
"https://github.com/bblanchon/ArduinoJson/archive/v5.8.2.zip")
|
||||
for n in
|
||||
("__pkg_dir",
|
||||
'"__src_url": "git+https://gitlab.com/ivankravets/rs485-nodeproto.git"',
|
||||
'"version": "5.10.1"')
|
||||
])
|
||||
items1 = [i['name'] for i in json.loads(result.output)]
|
||||
items2 = [
|
||||
"OneWire", "DHT22", "PJON", "ESPAsyncTCP", "ArduinoJson",
|
||||
"PubSubClient", "rs485-nodeproto", "Adafruit ST7735 Library",
|
||||
"RadioHead-1.62", "DallasTemperature", "NeoPixelBus", "RFcontrol",
|
||||
"platformio-libmirror"
|
||||
"Adafruit ST7735 Library", "ArduinoJson", "ArduinoJson", "ArduinoJson",
|
||||
"ArduinoJson", "AsyncMqttClient", "AsyncTCP", "DallasTemperature",
|
||||
"ESPAsyncTCP", "NeoPixelBus", "OneWire", "PJON", "PJON",
|
||||
"PubSubClient", "RFcontrol", "RadioHead-1.62", "platformio-libmirror",
|
||||
"rs485-nodeproto"
|
||||
]
|
||||
assert set(items1) == set(items2)
|
||||
assert sorted(items1) == sorted(items2)
|
||||
|
||||
versions1 = [
|
||||
"{name}@{version}".format(**item)
|
||||
for item in json.loads(result.output)
|
||||
]
|
||||
versions2 = [
|
||||
'ArduinoJson@5c33fd4', 'ArduinoJson@5.8.2', 'ArduinoJson@5.10.1',
|
||||
'AsyncMqttClient@0.8.2', 'AsyncTCP@1.0.1', 'ESPAsyncTCP@1.1.3',
|
||||
'NeoPixelBus@2.2.4', 'PJON@07fe9aa', 'PJON@1fb26fd',
|
||||
'PubSubClient@bef5814', 'RFcontrol@77d4eb3f8a', 'RadioHead-1.62@0.0.0'
|
||||
]
|
||||
assert set(versions1) >= set(versions2)
|
||||
|
||||
|
||||
def test_global_lib_update_check(clirunner, validate_cliresult):
|
||||
@ -159,7 +185,7 @@ def test_global_lib_update_check(clirunner, validate_cliresult):
|
||||
cmd_lib, ["-g", "update", "--only-check", "--json-output"])
|
||||
validate_cliresult(result)
|
||||
output = json.loads(result.output)
|
||||
assert set(["ArduinoJson", "RFcontrol",
|
||||
assert set(["RFcontrol",
|
||||
"NeoPixelBus"]) == set([l['name'] for l in output])
|
||||
|
||||
|
||||
@ -180,10 +206,8 @@ def test_global_lib_update(clirunner, validate_cliresult):
|
||||
# update rest libraries
|
||||
result = clirunner.invoke(cmd_lib, ["-g", "update"])
|
||||
validate_cliresult(result)
|
||||
validate_cliresult(result)
|
||||
assert result.output.count("[Fixed]") == 5
|
||||
assert result.output.count("[Up-to-date]") == 10
|
||||
assert "Uninstalling ArduinoJson @ 5.7.3" in result.output
|
||||
assert result.output.count("[Fixed]") == 6
|
||||
assert result.output.count("[Up-to-date]") == 11
|
||||
assert "Uninstalling RFcontrol @ 77d4eb3f8a" in result.output
|
||||
|
||||
# update unknown library
|
||||
@ -212,10 +236,11 @@ def test_global_lib_uninstall(clirunner, validate_cliresult,
|
||||
|
||||
items1 = [d.basename for d in isolated_pio_home.join("lib").listdir()]
|
||||
items2 = [
|
||||
"ArduinoJson_ID64", "ArduinoJson_ID64@5.6.7", "DallasTemperature_ID54",
|
||||
"DHT22_ID58", "ESPAsyncTCP_ID305", "NeoPixelBus_ID547", "PJON",
|
||||
"PJON@src-79de467ebe19de18287becff0a1fb42d", "PubSubClient",
|
||||
"RadioHead-1.62", "rs485-nodeproto", "platformio-libmirror"
|
||||
"RadioHead-1.62", "rs485-nodeproto", "platformio-libmirror",
|
||||
"PubSubClient", "ArduinoJson@src-69ebddd821f771debe7ee734d3c7fa81",
|
||||
"ESPAsyncTCP_ID305", "DallasTemperature_ID54", "NeoPixelBus_ID547",
|
||||
"PJON", "AsyncMqttClient_ID346", "ArduinoJson_ID64",
|
||||
"PJON@src-79de467ebe19de18287becff0a1fb42d", "AsyncTCP_ID1826"
|
||||
]
|
||||
assert set(items1) == set(items2)
|
||||
|
||||
|
@ -13,14 +13,10 @@
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from click.testing import CliRunner
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def clirunner():
|
||||
return CliRunner()
|
||||
from platformio import util
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
@ -33,6 +29,11 @@ def validate_cliresult():
|
||||
return decorator
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def clirunner():
|
||||
return CliRunner()
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def isolated_pio_home(request, tmpdir_factory):
|
||||
home_dir = tmpdir_factory.mktemp(".platformio")
|
||||
@ -43,3 +44,8 @@ def isolated_pio_home(request, tmpdir_factory):
|
||||
|
||||
request.addfinalizer(fin)
|
||||
return home_dir
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def without_internet(monkeypatch):
|
||||
monkeypatch.setattr(util, "_internet_on", lambda: False)
|
||||
|
@ -23,13 +23,13 @@ def test_ping_internet_ips():
|
||||
requests.get("http://%s" % ip, allow_redirects=False, timeout=2)
|
||||
|
||||
|
||||
def test_api_internet_offline(monkeypatch, isolated_pio_home):
|
||||
monkeypatch.setattr(util, "_internet_on", lambda: False)
|
||||
def test_api_internet_offline(without_internet, isolated_pio_home):
|
||||
with pytest.raises(exception.InternetIsOffline):
|
||||
util.get_api_result("/stats")
|
||||
|
||||
|
||||
def test_api_cache(monkeypatch, isolated_pio_home):
|
||||
api_kwargs = {"url": "/stats", "cache_valid": "1m"}
|
||||
api_kwargs = {"url": "/stats", "cache_valid": "10s"}
|
||||
result = util.get_api_result(**api_kwargs)
|
||||
assert result and "boards" in result
|
||||
monkeypatch.setattr(util, '_internet_on', lambda: False)
|
||||
|
Reference in New Issue
Block a user