Unverified Commit 53a27683 authored by MatteoPologruto's avatar MatteoPologruto Committed by GitHub

[skip-changelog] Migrate `lib_test.py` to `test_lib.go` part two (#1999)

* Migrate TestUninstallSpaces from test_lib.py to lib_test.go

* Migrate TestLibOpsCaseInsensitive from test_lib.py to lib_test.go

* Migrate TestSearch from test_lib.py to lib_test.go

* Migrate TestSearchParagraph from test_lib.py to lib_test.go

* Migrate TestLibListWithUpdatableFlag from test_lib.py to lib_test.go

* Migrate TestInstallWithGitUrlFromCurrentDirectory from test_lib.py to lib_test.go

* Migrate TestInstallWithGitLocalUrl from test_lib.py to lib_test.go

* Migrate TestInstallWithGitUrlRelativePath from test_lib.py to lib_test.go

* Migrate TestInstallWithGitUrlDoesNotCreateGitRepo from test_lib.py to lib_test.go

* Migrate TestInstallWithGitUrlMultipleLibraries from test_lib.py to lib_test.go

* Migrate TestLibExamples from test_lib.py to lib_test.go

* Migrate TestLibExamplesWithPdeFile from test_lib.py to lib_test.go
parent f79974b3
......@@ -17,6 +17,7 @@ package lib_test
import (
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
......@@ -26,6 +27,7 @@ import (
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
"go.bug.st/testifyjson/requirejson"
"gopkg.in/src-d/go-git.v4"
)
func TestLibUpgradeCommand(t *testing.T) {
......@@ -676,3 +678,349 @@ func TestUninstall(t *testing.T) {
_, _, err = cli.Run("lib", "uninstall", libs[0], libs[1])
require.NoError(t, err)
}
func TestUninstallSpaces(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
key := "LiquidCrystal I2C"
_, _, err := cli.Run("lib", "install", key)
require.NoError(t, err)
_, _, err = cli.Run("lib", "uninstall", key)
require.NoError(t, err)
stdout, _, err := cli.Run("lib", "list", "--format", "json")
require.NoError(t, err)
requirejson.Len(t, stdout, 0)
}
func TestLibOpsCaseInsensitive(t *testing.T) {
/*This test is supposed to (un)install the following library,
As you can see the name is all caps:
Name: "PCM"
Author: David Mellis <d.mellis@bcmi-labs.cc>, Michael Smith <michael@hurts.ca>
Maintainer: David Mellis <d.mellis@bcmi-labs.cc>
Sentence: Playback of short audio samples.
Paragraph: These samples are encoded directly in the Arduino sketch as an array of numbers.
Website: http://highlowtech.org/?p=1963
Category: Signal Input/Output
Architecture: avr
Types: Contributed
Versions: [1.0.0]*/
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
key := "pcm"
_, _, err := cli.Run("lib", "install", key)
require.NoError(t, err)
_, _, err = cli.Run("lib", "uninstall", key)
require.NoError(t, err)
stdout, _, err := cli.Run("lib", "list", "--format", "json")
require.NoError(t, err)
requirejson.Len(t, stdout, 0)
}
func TestSearch(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
stdout, _, err := cli.Run("lib", "search", "--names")
require.NoError(t, err)
lines := strings.Split(strings.TrimSpace(string(stdout)), "\n")
var libs []string
for i, v := range lines {
lines[i] = strings.TrimSpace(v)
if strings.Contains(v, "Name:") {
libs = append(libs, strings.Trim(strings.SplitN(v, " ", 2)[1], "\""))
}
}
expected := []string{"WiFi101", "WiFi101OTA", "Firebase Arduino based on WiFi101", "WiFi101_Generic"}
require.Subset(t, libs, expected)
stdout, _, err = cli.Run("lib", "search", "--names", "--format", "json")
require.NoError(t, err)
requirejson.Query(t, stdout, ".libraries | length", fmt.Sprint(len(libs)))
runSearch := func(args string, expectedLibs []string) {
stdout, _, err = cli.Run("lib", "search", "--names", "--format", "json", args)
require.NoError(t, err)
libraries := requirejson.Parse(t, stdout).Query("[ .libraries | .[] | .name ]").String()
for _, l := range expectedLibs {
require.Contains(t, libraries, l)
}
}
runSearch("Arduino_MKRIoTCarrier", []string{"Arduino_MKRIoTCarrier"})
runSearch("Arduino mkr iot carrier", []string{"Arduino_MKRIoTCarrier"})
runSearch("mkr iot carrier", []string{"Arduino_MKRIoTCarrier"})
runSearch("mkriotcarrier", []string{"Arduino_MKRIoTCarrier"})
runSearch("dht", []string{"DHT sensor library", "DHT sensor library for ESPx", "DHT12", "SimpleDHT", "TinyDHT sensor library", "SDHT"})
runSearch("dht11", []string{"DHT sensor library", "DHT sensor library for ESPx", "SimpleDHT", "SDHT"})
runSearch("dht12", []string{"DHT12", "DHT12 sensor library", "SDHT"})
runSearch("dht22", []string{"DHT sensor library", "DHT sensor library for ESPx", "SimpleDHT", "SDHT"})
runSearch("dht sensor", []string{"DHT sensor library", "DHT sensor library for ESPx", "SimpleDHT", "SDHT"})
runSearch("sensor dht", []string{})
runSearch("arduino json", []string{"ArduinoJson", "Arduino_JSON"})
runSearch("arduinojson", []string{"ArduinoJson"})
runSearch("json", []string{"ArduinoJson", "Arduino_JSON"})
}
func TestSearchParagraph(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Search for a string that's only present in the `paragraph` field
// within the index file.
_, _, err := cli.Run("lib", "update-index")
require.NoError(t, err)
stdout, _, err := cli.Run("lib", "search", "A simple and efficient JSON library", "--names", "--format", "json")
require.NoError(t, err)
requirejson.Contains(t, stdout, `{
"libraries": [
{
"name": "ArduinoJson"
}
]
}`)
}
func TestLibListWithUpdatableFlag(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Init the environment explicitly
_, _, err := cli.Run("lib", "update-index")
require.NoError(t, err)
// No libraries to update
stdout, stderr, err := cli.Run("lib", "list", "--updatable")
require.NoError(t, err)
require.Empty(t, stderr)
require.Contains(t, string(stdout), "No libraries update is available.")
// No library to update in json
stdout, stderr, err = cli.Run("lib", "list", "--updatable", "--format", "json")
require.NoError(t, err)
require.Empty(t, stderr)
requirejson.Empty(t, stdout)
// Install outdated library
_, _, err = cli.Run("lib", "install", "ArduinoJson@6.11.0")
require.NoError(t, err)
// Install latest version of library
_, _, err = cli.Run("lib", "install", "WiFi101")
require.NoError(t, err)
stdout, stderr, err = cli.Run("lib", "list", "--updatable")
require.NoError(t, err)
require.Empty(t, stderr)
var lines [][]string
for _, v := range strings.Split(strings.TrimSpace(string(stdout)), "\n") {
v = strings.Join(strings.Fields(v), " ")
lines = append(lines, strings.SplitN(v, " ", 5))
}
require.Len(t, lines, 2)
require.Subset(t, lines[0], []string{"Name", "Installed", "Available", "Location", "Description"})
require.Equal(t, "ArduinoJson", lines[1][0])
require.Equal(t, "6.11.0", lines[1][1])
// Verifies available version is not equal to installed one and not empty
require.NotEqual(t, "6.11.0", lines[1][2])
require.NotEmpty(t, lines[1][2])
require.Equal(t, "An efficient and elegant JSON library...", lines[1][4])
// Look at the JSON output
stdout, stderr, err = cli.Run("lib", "list", "--updatable", "--format", "json")
require.NoError(t, err)
require.Empty(t, stderr)
requirejson.Len(t, stdout, 1)
// be sure data contains the available version
requirejson.Query(t, stdout, `.[0] | .library | .version`, `"6.11.0"`)
requirejson.Query(t, stdout, `.[0] | .release | .version != "6.11.0"`, `true`)
requirejson.Query(t, stdout, `.[0] | .release | .version != ""`, `true`)
}
func TestInstallWithGitUrlFromCurrentDirectory(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
_, _, err := cli.Run("update")
require.NoError(t, err)
envVar := cli.GetDefaultEnv()
envVar["ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL"] = "true"
libInstallDir := cli.SketchbookDir().Join("libraries", "WiFi101")
// Verifies library is not installed
require.NoDirExists(t, libInstallDir.String())
// Clone repository locally
gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
repoDir := cli.SketchbookDir().Join("WiFi101")
_, err = git.PlainClone(repoDir.String(), false, &git.CloneOptions{
URL: gitUrl,
})
require.NoError(t, err)
cli.SetWorkingDir(repoDir)
_, _, err = cli.RunWithCustomEnv(envVar, "lib", "install", "--git-url", ".")
require.NoError(t, err)
// Verifies library is installed to correct folder
require.DirExists(t, libInstallDir.String())
}
func TestInstallWithGitLocalUrl(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
_, _, err := cli.Run("update")
require.NoError(t, err)
envVar := cli.GetDefaultEnv()
envVar["ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL"] = "true"
libInstallDir := cli.SketchbookDir().Join("libraries", "WiFi101")
// Verifies library is not installed
require.NoDirExists(t, libInstallDir.String())
// Clone repository locally
gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
repoDir := cli.SketchbookDir().Join("WiFi101")
_, err = git.PlainClone(repoDir.String(), false, &git.CloneOptions{
URL: gitUrl,
})
require.NoError(t, err)
_, _, err = cli.RunWithCustomEnv(envVar, "lib", "install", "--git-url", repoDir.String())
require.NoError(t, err)
// Verifies library is installed
require.DirExists(t, libInstallDir.String())
}
func TestInstallWithGitUrlRelativePath(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
_, _, err := cli.Run("update")
require.NoError(t, err)
envVar := cli.GetDefaultEnv()
envVar["ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL"] = "true"
libInstallDir := cli.SketchbookDir().Join("libraries", "WiFi101")
// Verifies library is not installed
require.NoDirExists(t, libInstallDir.String())
// Clone repository locally
gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
repoDir := cli.SketchbookDir().Join("WiFi101")
_, err = git.PlainClone(repoDir.String(), false, &git.CloneOptions{
URL: gitUrl,
})
require.NoError(t, err)
cli.SetWorkingDir(cli.SketchbookDir())
_, _, err = cli.RunWithCustomEnv(envVar, "lib", "install", "--git-url", "./WiFi101")
require.NoError(t, err)
// Verifies library is installed
require.DirExists(t, libInstallDir.String())
}
func TestInstallWithGitUrlDoesNotCreateGitRepo(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
_, _, err := cli.Run("update")
require.NoError(t, err)
envVar := cli.GetDefaultEnv()
envVar["ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL"] = "true"
libInstallDir := cli.SketchbookDir().Join("libraries", "WiFi101")
// Verifies library is not installed
require.NoDirExists(t, libInstallDir.String())
// Clone repository locally
gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
repoDir := cli.SketchbookDir().Join("WiFi101")
_, err = git.PlainClone(repoDir.String(), false, &git.CloneOptions{
URL: gitUrl,
})
require.NoError(t, err)
_, _, err = cli.RunWithCustomEnv(envVar, "lib", "install", "--git-url", repoDir.String())
require.NoError(t, err)
// Verifies installed library is not a git repository
require.NoDirExists(t, libInstallDir.Join(".git").String())
}
func TestInstallWithGitUrlMultipleLibraries(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
_, _, err := cli.Run("update")
require.NoError(t, err)
envVar := cli.GetDefaultEnv()
envVar["ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL"] = "true"
wifiInstallDir := cli.SketchbookDir().Join("libraries", "WiFi101")
bleInstallDir := cli.SketchbookDir().Join("libraries", "ArduinoBLE")
// Verifies library are not installed
require.NoDirExists(t, wifiInstallDir.String())
require.NoDirExists(t, bleInstallDir.String())
wifiUrl := "https://github.com/arduino-libraries/WiFi101.git"
bleUrl := "https://github.com/arduino-libraries/ArduinoBLE.git"
_, _, err = cli.RunWithCustomEnv(envVar, "lib", "install", "--git-url", wifiUrl, bleUrl)
require.NoError(t, err)
// Verifies library are installed
require.DirExists(t, wifiInstallDir.String())
require.DirExists(t, bleInstallDir.String())
}
func TestLibExamples(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
_, _, err := cli.Run("update")
require.NoError(t, err)
_, _, err = cli.Run("lib", "install", "Arduino_JSON@0.1.0")
require.NoError(t, err)
stdout, _, err := cli.Run("lib", "examples", "Arduino_JSON", "--format", "json")
require.NoError(t, err)
requirejson.Len(t, stdout, 1)
examples := requirejson.Parse(t, stdout).Query(".[0] | .examples").String()
examples = strings.ReplaceAll(examples, "\\\\", "\\")
require.Contains(t, examples, cli.SketchbookDir().Join("libraries", "Arduino_JSON", "examples", "JSONArray").String())
require.Contains(t, examples, cli.SketchbookDir().Join("libraries", "Arduino_JSON", "examples", "JSONKitchenSink").String())
require.Contains(t, examples, cli.SketchbookDir().Join("libraries", "Arduino_JSON", "examples", "JSONObject").String())
}
func TestLibExamplesWithPdeFile(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
_, _, err := cli.Run("update")
require.NoError(t, err)
_, _, err = cli.Run("lib", "install", "Encoder@1.4.1")
require.NoError(t, err)
stdout, _, err := cli.Run("lib", "examples", "Encoder", "--format", "json")
require.NoError(t, err)
requirejson.Len(t, stdout, 1)
examples := requirejson.Parse(t, stdout).Query(".[0] | .examples").String()
examples = strings.ReplaceAll(examples, "\\\\", "\\")
require.Contains(t, examples, cli.SketchbookDir().Join("libraries", "Encoder", "examples", "Basic").String())
require.Contains(t, examples, cli.SketchbookDir().Join("libraries", "Encoder", "examples", "NoInterrupts").String())
require.Contains(t, examples, cli.SketchbookDir().Join("libraries", "Encoder", "examples", "SpeedTest").String())
require.Contains(t, examples, cli.SketchbookDir().Join("libraries", "Encoder", "examples", "TwoKnobs").String())
}
......@@ -146,172 +146,6 @@ def test_install_with_zip_path(run_command, data_dir, downloads_dir):
assert lib_install_dir / "README.adoc" in files
def test_uninstall_spaces(run_command):
key = "LiquidCrystal I2C"
assert run_command(["lib", "install", key])
assert run_command(["lib", "uninstall", key])
result = run_command(["lib", "list", "--format", "json"])
assert result.ok
assert len(json.loads(result.stdout)) == 0
def test_lib_ops_caseinsensitive(run_command):
"""
This test is supposed to (un)install the following library,
As you can see the name is all caps:
Name: "PCM"
Author: David Mellis <d.mellis@bcmi-labs.cc>, Michael Smith <michael@hurts.ca>
Maintainer: David Mellis <d.mellis@bcmi-labs.cc>
Sentence: Playback of short audio samples.
Paragraph: These samples are encoded directly in the Arduino sketch as an array of numbers.
Website: http://highlowtech.org/?p=1963
Category: Signal Input/Output
Architecture: avr
Types: Contributed
Versions: [1.0.0]
"""
key = "pcm"
assert run_command(["lib", "install", key])
assert run_command(["lib", "uninstall", key])
result = run_command(["lib", "list", "--format", "json"])
assert result.ok
assert len(json.loads(result.stdout)) == 0
def test_search(run_command):
assert run_command(["update"])
result = run_command(["lib", "search", "--names"])
assert result.ok
lines = [l.strip() for l in result.stdout.strip().splitlines()]
assert "Downloading index: library_index.tar.bz2 downloaded" in lines
libs = [l[6:].strip('"') for l in lines if "Name:" in l]
expected = {"WiFi101", "WiFi101OTA", "Firebase Arduino based on WiFi101", "WiFi101_Generic"}
assert expected == {lib for lib in libs if "WiFi101" in lib}
result = run_command(["lib", "search", "--names", "--format", "json"])
assert result.ok
libs_json = json.loads(result.stdout)
assert len(libs) == len(libs_json.get("libraries"))
result = run_command(["lib", "search", "--names"])
assert result.ok
def run_search(search_args, expected_libraries):
res = run_command(["lib", "search", "--names", "--format", "json"] + search_args.split(" "))
assert res.ok
data = json.loads(res.stdout)
libraries = [l["name"] for l in data["libraries"]]
for l in expected_libraries:
assert l in libraries
run_search("Arduino_MKRIoTCarrier", ["Arduino_MKRIoTCarrier"])
run_search("Arduino mkr iot carrier", ["Arduino_MKRIoTCarrier"])
run_search("mkr iot carrier", ["Arduino_MKRIoTCarrier"])
run_search("mkriotcarrier", ["Arduino_MKRIoTCarrier"])
run_search(
"dht",
["DHT sensor library", "DHT sensor library for ESPx", "DHT12", "SimpleDHT", "TinyDHT sensor library", "SDHT"],
)
run_search("dht11", ["DHT sensor library", "DHT sensor library for ESPx", "SimpleDHT", "SDHT"])
run_search("dht12", ["DHT12", "DHT12 sensor library", "SDHT"])
run_search("dht22", ["DHT sensor library", "DHT sensor library for ESPx", "SimpleDHT", "SDHT"])
run_search("dht sensor", ["DHT sensor library", "DHT sensor library for ESPx", "SimpleDHT", "SDHT"])
run_search("sensor dht", [])
run_search("arduino json", ["ArduinoJson", "Arduino_JSON"])
run_search("arduinojson", ["ArduinoJson"])
run_search("json", ["ArduinoJson", "Arduino_JSON"])
def test_search_paragraph(run_command):
"""
Search for a string that's only present in the `paragraph` field
within the index file.
"""
assert run_command(["lib", "update-index"])
result = run_command(["lib", "search", "A simple and efficient JSON library", "--names", "--format", "json"])
assert result.ok
data = json.loads(result.stdout)
libraries = [l["name"] for l in data["libraries"]]
assert "ArduinoJson" in libraries
def test_lib_list_with_updatable_flag(run_command):
# Init the environment explicitly
run_command(["lib", "update-index"])
# No libraries to update
result = run_command(["lib", "list", "--updatable"])
assert result.ok
assert "" == result.stderr
assert "No libraries update is available." in result.stdout.strip()
# No library to update in json
result = run_command(["lib", "list", "--updatable", "--format", "json"])
assert result.ok
assert "" == result.stderr
assert 0 == len(json.loads(result.stdout))
# Install outdated library
assert run_command(["lib", "install", "ArduinoJson@6.11.0"])
# Install latest version of library
assert run_command(["lib", "install", "WiFi101"])
res = run_command(["lib", "list", "--updatable"])
assert res.ok
assert "" == res.stderr
# lines = res.stdout.strip().splitlines()
lines = [l.strip().split(maxsplit=4) for l in res.stdout.strip().splitlines()]
assert 2 == len(lines)
assert ["Name", "Installed", "Available", "Location", "Description"] in lines
line = lines[1]
assert "ArduinoJson" == line[0]
assert "6.11.0" == line[1]
# Verifies available version is not equal to installed one and not empty
assert "6.11.0" != line[2]
assert "" != line[2]
assert "An efficient and elegant JSON library..." == line[4]
# Look at the JSON output
res = run_command(["lib", "list", "--updatable", "--format", "json"], hide=True)
assert res.ok
assert "" == res.stderr
data = json.loads(res.stdout)
assert 1 == len(data)
# be sure data contains the available version
assert "6.11.0" == data[0]["library"]["version"]
assert "6.11.0" != data[0]["release"]["version"]
assert "" != data[0]["release"]["version"]
def test_install_with_git_url_from_current_directory(run_command, downloads_dir, data_dir):
assert run_command(["update"])
env = {
"ARDUINO_DATA_DIR": data_dir,
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
"ARDUINO_SKETCHBOOK_DIR": data_dir,
"ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL": "true",
}
lib_install_dir = Path(data_dir, "libraries", "WiFi101")
# Verifies library is not installed
assert not lib_install_dir.exists()
# Clone repository locally
git_url = "https://github.com/arduino-libraries/WiFi101.git"
repo_dir = Path(data_dir, "WiFi101")
assert Repo.clone_from(git_url, repo_dir)
assert run_command(["lib", "install", "--git-url", "."], custom_working_dir=repo_dir, custom_env=env)
# Verifies library is installed to correct folder
assert lib_install_dir.exists()
@pytest.mark.skipif(
platform.system() == "Windows",
reason="Using a file uri as git url doesn't work on Windows, "
......@@ -342,107 +176,6 @@ def test_install_with_git_url_local_file_uri(run_command, downloads_dir, data_di
assert lib_install_dir.exists()
def test_install_with_git_local_url(run_command, downloads_dir, data_dir):
assert run_command(["update"])
env = {
"ARDUINO_DATA_DIR": data_dir,
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
"ARDUINO_SKETCHBOOK_DIR": data_dir,
"ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL": "true",
}
lib_install_dir = Path(data_dir, "libraries", "WiFi101")
# Verifies library is not installed
assert not lib_install_dir.exists()
# Clone repository locally
git_url = "https://github.com/arduino-libraries/WiFi101.git"
repo_dir = Path(data_dir, "WiFi101")
assert Repo.clone_from(git_url, repo_dir)
assert run_command(["lib", "install", "--git-url", repo_dir], custom_env=env)
# Verifies library is installed
assert lib_install_dir.exists()
def test_install_with_git_url_relative_path(run_command, downloads_dir, data_dir):
assert run_command(["update"])
env = {
"ARDUINO_DATA_DIR": data_dir,
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
"ARDUINO_SKETCHBOOK_DIR": data_dir,
"ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL": "true",
}
lib_install_dir = Path(data_dir, "libraries", "WiFi101")
# Verifies library is not installed
assert not lib_install_dir.exists()
# Clone repository locally
git_url = "https://github.com/arduino-libraries/WiFi101.git"
repo_dir = Path(data_dir, "WiFi101")
assert Repo.clone_from(git_url, repo_dir)
assert run_command(["lib", "install", "--git-url", "./WiFi101"], custom_working_dir=data_dir, custom_env=env)
# Verifies library is installed
assert lib_install_dir.exists()
def test_install_with_git_url_does_not_create_git_repo(run_command, downloads_dir, data_dir):
assert run_command(["update"])
env = {
"ARDUINO_DATA_DIR": data_dir,
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
"ARDUINO_SKETCHBOOK_DIR": data_dir,
"ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL": "true",
}
lib_install_dir = Path(data_dir, "libraries", "WiFi101")
# Verifies library is not installed
assert not lib_install_dir.exists()
# Clone repository locally
git_url = "https://github.com/arduino-libraries/WiFi101.git"
repo_dir = Path(data_dir, "WiFi101")
assert Repo.clone_from(git_url, repo_dir)
assert run_command(["lib", "install", "--git-url", repo_dir], custom_env=env)
# Verifies installed library is not a git repository
assert not Path(lib_install_dir, ".git").exists()
def test_install_with_git_url_multiple_libraries(run_command, downloads_dir, data_dir):
assert run_command(["update"])
env = {
"ARDUINO_DATA_DIR": data_dir,
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
"ARDUINO_SKETCHBOOK_DIR": data_dir,
"ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL": "true",
}
wifi_install_dir = Path(data_dir, "libraries", "WiFi101")
ble_install_dir = Path(data_dir, "libraries", "ArduinoBLE")
# Verifies libraries are not installed
assert not wifi_install_dir.exists()
assert not ble_install_dir.exists()
wifi_url = "https://github.com/arduino-libraries/WiFi101.git"
ble_url = "https://github.com/arduino-libraries/ArduinoBLE.git"
assert run_command(["lib", "install", "--git-url", wifi_url, ble_url], custom_env=env)
# Verifies library are installed
assert wifi_install_dir.exists()
assert ble_install_dir.exists()
def test_install_with_zip_path_multiple_libraries(run_command, downloads_dir, data_dir):
assert run_command(["update"])
......@@ -473,39 +206,6 @@ def test_install_with_zip_path_multiple_libraries(run_command, downloads_dir, da
assert ble_install_dir.exists()
def test_lib_examples(run_command, data_dir):
assert run_command(["update"])
assert run_command(["lib", "install", "Arduino_JSON@0.1.0"])
res = run_command(["lib", "examples", "Arduino_JSON", "--format", "json"])
assert res.ok
data = json.loads(res.stdout)
assert len(data) == 1
examples = data[0]["examples"]
assert str(Path(data_dir, "libraries", "Arduino_JSON", "examples", "JSONArray")) in examples
assert str(Path(data_dir, "libraries", "Arduino_JSON", "examples", "JSONKitchenSink")) in examples
assert str(Path(data_dir, "libraries", "Arduino_JSON", "examples", "JSONObject")) in examples
def test_lib_examples_with_pde_file(run_command, data_dir):
assert run_command(["update"])
assert run_command(["lib", "install", "Encoder@1.4.1"])
res = run_command(["lib", "examples", "Encoder", "--format", "json"])
assert res.ok
data = json.loads(res.stdout)
assert len(data) == 1
examples = data[0]["examples"]
assert str(Path(data_dir, "libraries", "Encoder", "examples", "Basic")) in examples
assert str(Path(data_dir, "libraries", "Encoder", "examples", "NoInterrupts")) in examples
assert str(Path(data_dir, "libraries", "Encoder", "examples", "SpeedTest")) in examples
assert str(Path(data_dir, "libraries", "Encoder", "examples", "TwoKnobs")) in examples
def test_lib_examples_with_case_mismatch(run_command, data_dir):
assert run_command(["update"])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment