Improve test coverage
Adds coverage for `format_suggested_follow_up` for empty suggestions.
Adds coverage for `show_list` for Versions.
Adds coverage for `show_list` for list of tools.
@@ -458,6 +458,10 @@ def test_format_suggested_follow_up():
assert format_suggested_follow_up(suggestions) == expected
+def test_format_suggested_follow_up_empty():
+ assert format_suggested_follow_up([]) == ""
+
+
@pytest.mark.parametrize(
"meta, expect",
(
@@ -640,6 +644,33 @@ def test_show_list_tools_long_ifw(capsys, monkeypatch, columns, expect):
assert out == expect
+def test_show_list_versions(monkeypatch, capsys):
+ _html = (Path(__file__).parent / "data" / "mac-desktop.html").read_text("utf-8")
+ monkeypatch.setattr(MetadataFactory, "fetch_http", lambda *args: _html)
+
+ expect_file = Path(__file__).parent / "data" / "mac-desktop-expect.json"
+ expected = "\n".join(json.loads(expect_file.read_text("utf-8"))["qt5"]["qt"]) + "\n"
+
+ assert show_list(MetadataFactory(mac_qt5)) == 0
+ out, err = capsys.readouterr()
+ assert out == expected
+
+
+def test_show_list_tools(monkeypatch, capsys):
+ page = (Path(__file__).parent / "data" / "mac-desktop.html").read_text("utf-8")
+ monkeypatch.setattr(MetadataFactory, "fetch_http", lambda self, _: page)
+
+ expect_file = Path(__file__).parent / "data" / "mac-desktop-expect.json"
+ expect = "\n".join(json.loads(expect_file.read_text("utf-8"))["tools"]) + "\n"
+
+ meta = MetadataFactory(ArchiveId("tools", "mac", "desktop"))
+ assert show_list(meta) == 0
+ out, err = capsys.readouterr()
+ sys.stdout.write(out)
+ sys.stderr.write(err)
+ assert out == expect
+
+
def test_fetch_http_ok(monkeypatch):
monkeypatch.setattr("aqt.metadata.getUrl", lambda **kwargs: "some_html_content")
assert MetadataFactory.fetch_http("some_url") == "some_html_content"
