Skip to content

Commit 79c75b1

Browse files
committed
[skip changelog] Add integration tests
1 parent 81431c0 commit 79c75b1

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

test/test_lib.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,3 +703,65 @@ def test_lib_examples_with_case_mismatch(run_command, data_dir):
703703
# Verifies sketches with wrong casing are not returned
704704
assert str(examples_path / "NonBlocking" / "OnDemandNonBlocking") not in examples
705705
assert str(examples_path / "OnDemand" / "OnDemandWebPortal") not in examples
706+
707+
708+
def test_lib_list_using_library_with_invalid_version(run_command, data_dir):
709+
assert run_command("update")
710+
711+
# Install a library
712+
assert run_command("lib install [email protected]")
713+
714+
# Verifies library is correctly returned
715+
res = run_command("lib list --format json")
716+
assert res.ok
717+
data = json.loads(res.stdout)
718+
assert len(data) == 1
719+
assert "0.16.1" == data[0]["library"]["version"]
720+
721+
# Changes the version of the currently installed library so that it's
722+
# invalid
723+
lib_path = Path(data_dir, "libraries", "WiFi101")
724+
Path(lib_path, "library.properties").write_text("version=1.0001")
725+
726+
# Verifies version is now empty
727+
res = run_command("lib list --format json")
728+
assert res.ok
729+
data = json.loads(res.stdout)
730+
assert len(data) == 1
731+
assert "version" not in data[0]["library"]
732+
733+
734+
def test_lib_upgrade_using_library_with_invalid_version(run_command, data_dir):
735+
assert run_command("update")
736+
737+
# Install a library
738+
assert run_command("lib install [email protected]")
739+
740+
# Verifies library is correctly returned
741+
res = run_command("lib list --format json")
742+
assert res.ok
743+
data = json.loads(res.stdout)
744+
assert len(data) == 1
745+
assert "0.16.1" == data[0]["library"]["version"]
746+
747+
# Changes the version of the currently installed library so that it's
748+
# invalid
749+
lib_path = Path(data_dir, "libraries", "WiFi101")
750+
Path(lib_path, "library.properties").write_text("version=1.0001")
751+
752+
# Verifies version is now empty
753+
res = run_command("lib list --format json")
754+
assert res.ok
755+
data = json.loads(res.stdout)
756+
assert len(data) == 1
757+
assert "version" not in data[0]["library"]
758+
759+
# Upgrade library
760+
assert run_command("lib upgrade WiFi101")
761+
762+
# Verifies library has been updated
763+
res = run_command("lib list --format json")
764+
assert res.ok
765+
data = json.loads(res.stdout)
766+
assert len(data) == 1
767+
assert "" != data[0]["library"]["version"]

test/test_outdated.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# software without disclosing the source code of your own applications. To purchase
1414
# a commercial license, send an email to [email protected].
1515

16+
from pathlib import Path
17+
1618

1719
def test_outdated(run_command):
1820
# Updates index for cores and libraries
@@ -33,3 +35,26 @@ def test_outdated(run_command):
3335
lines = [l.strip() for l in result.stdout.splitlines()]
3436
assert lines[1].startswith("Arduino AVR Boards")
3537
assert lines[4].startswith("USBHost")
38+
39+
40+
def test_outdated_using_library_with_invalid_version(run_command, data_dir):
41+
assert run_command("update")
42+
43+
# Install latest version of a library library
44+
assert run_command("lib install WiFi101")
45+
46+
# Verifies library is correctly returned
47+
res = run_command("outdated")
48+
assert res.ok
49+
assert "WiFi101" not in res.stdout
50+
51+
# Changes the version of the currently installed library so that it's
52+
# invalid
53+
lib_path = Path(data_dir, "libraries", "WiFi101")
54+
Path(lib_path, "library.properties").write_text("version=1.0001")
55+
56+
# Verifies library is correctly returned
57+
res = run_command("outdated")
58+
assert res.ok
59+
lines = [l.strip().split() for l in res.stdout.splitlines()]
60+
assert "WiFi101" == lines[1][0]

test/test_update.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# software without disclosing the source code of your own applications. To purchase
1414
# a commercial license, send an email to [email protected].
1515

16+
from pathlib import Path
17+
1618

1719
def test_update(run_command):
1820
res = run_command("update")
@@ -73,3 +75,25 @@ def test_update_with_url_internal_server_error(run_command, httpserver):
7375
assert res.failed
7476
lines = [l.strip() for l in res.stderr.splitlines()]
7577
assert f"Error updating core and libraries index: downloading index {url}: 500 INTERNAL SERVER ERROR" in lines
78+
79+
80+
def test_update_showing_outdated_using_library_with_invalid_version(run_command, data_dir):
81+
assert run_command("update")
82+
83+
# Install latest version of a library
84+
assert run_command("lib install WiFi101")
85+
86+
# Verifies library doesn't get updated
87+
res = run_command("update --show-outdated")
88+
assert res.ok
89+
assert "WiFi101" not in res.stdout
90+
91+
# Changes the version of the currently installed library so that it's
92+
# invalid
93+
lib_path = Path(data_dir, "libraries", "WiFi101")
94+
Path(lib_path, "library.properties").write_text("version=1.0001")
95+
96+
# Verifies library gets updated
97+
res = run_command("update --show-outdated")
98+
assert res.ok
99+
assert "WiFi101" in res.stdout

test/test_upgrade.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# software without disclosing the source code of your own applications. To purchase
1414
# a commercial license, send an email to [email protected].
1515

16+
from pathlib import Path
17+
1618

1719
def test_upgrade(run_command):
1820
# Updates index for cores and libraries
@@ -41,3 +43,25 @@ def test_upgrade(run_command):
4143
result = run_command("outdated")
4244
assert result.ok
4345
assert result.stdout == ""
46+
47+
48+
def test_upgrade_using_library_with_invalid_version(run_command, data_dir):
49+
assert run_command("update")
50+
51+
# Install latest version of a library
52+
assert run_command("lib install WiFi101")
53+
54+
# Verifies library is not shown
55+
res = run_command("outdated")
56+
assert res.ok
57+
assert "WiFi101" not in res.stdout
58+
59+
# Changes the version of the currently installed library so that it's
60+
# invalid
61+
lib_path = Path(data_dir, "libraries", "WiFi101")
62+
Path(lib_path, "library.properties").write_text("version=1.0001")
63+
64+
# Verifies library gets upgraded
65+
res = run_command("upgrade")
66+
assert res.ok
67+
assert "WiFi101" in res.stdout

0 commit comments

Comments
 (0)