Skip to content

Commit f568ed2

Browse files
committed
adjust test to ensure output_file contains valid json
1 parent d1cc335 commit f568ed2

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

tests/integration/test_update_cp_org_libraries.py

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
"""Integration tests for 'adabot/update_cp_org_libraries.py'"""
2424

25+
import json
26+
2527
import pytest # pylint: disable=unused-import
2628

2729
from adabot.lib import common_funcs
@@ -31,9 +33,45 @@
3133
# pylint: disable=unused-argument
3234
def mock_list_repos(*args, **kwargs):
3335
"""Function to monkeypatch `common_funcs.list_repos()` for a shorter set of repos."""
34-
return [
35-
github_requests.get("/repos/adafruit/Adafruit_CircuitPython_TestRepo").json()
36-
]
36+
repos = []
37+
result = github_requests.get(
38+
"/search/repositories",
39+
params={
40+
"q": "Adafruit_CircuitPython user:adafruit archived:false fork:true",
41+
"per_page": 100,
42+
"sort": "updated",
43+
"order": "asc",
44+
},
45+
)
46+
47+
if result.ok:
48+
repos.extend(
49+
repo
50+
for repo in result.json()["items"]
51+
if (
52+
repo["owner"]["login"] == "adafruit"
53+
and (
54+
repo["name"].startswith("Adafruit_CircuitPython")
55+
or repo["name"] == "circuitpython"
56+
)
57+
)
58+
)
59+
60+
repo_names = [repo["name"] for repo in repos]
61+
62+
if kwargs.get("include_repos", False):
63+
for repo in kwargs["include_repos"]:
64+
if repo not in repo_names:
65+
add_repo = github_requests.get("/repos/adafruit/" + repo)
66+
if add_repo.ok:
67+
repos.append(add_repo.json())
68+
else:
69+
print("list_repos(): Failed to retrieve '{}'".format(repo))
70+
71+
if len(repos) > 5:
72+
repos = repos[:5]
73+
74+
return repos
3775

3876

3977
# pylint: disable=unused-argument
@@ -54,7 +92,7 @@ def test_update_cp_org_libraries(monkeypatch):
5492
monkeypatch.setattr(common_funcs, "list_repos", mock_list_repos)
5593
monkeypatch.setattr(update_cp_org_libraries, "get_contributors", mock_get_contribs)
5694

57-
update_cp_org_libraries.main()
95+
update_cp_org_libraries.main(loglevel="INFO")
5896

5997

6098
# pylint: disable=invalid-name
@@ -66,8 +104,8 @@ def test_update_cp_org_libraries_output_file(monkeypatch, tmp_path, capsys):
66104

67105
tmp_output_file = tmp_path / "output_test.txt"
68106

69-
update_cp_org_libraries.main(output_file=tmp_output_file)
107+
update_cp_org_libraries.main(loglevel="INFO", output_file=tmp_output_file)
70108

71-
captured = capsys.readouterr()
109+
output = tmp_output_file.read_text()
72110

73-
assert tmp_output_file.read_text() == captured.out
111+
assert json.loads(output)

0 commit comments

Comments
 (0)