|
26 | 26 | import semver
|
27 | 27 |
|
28 | 28 |
|
29 |
| -def test_core_search(run_command, httpserver): |
30 |
| - # Set up the server to serve our custom index file |
31 |
| - test_index = Path(__file__).parent / "testdata" / "test_index.json" |
32 |
| - httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text()) |
33 |
| - |
34 |
| - url = httpserver.url_for("/test_index.json") |
35 |
| - assert run_command(["core", "update-index", f"--additional-urls={url}"]) |
36 |
| - # search a specific core |
37 |
| - result = run_command(["core", "search", "avr"]) |
38 |
| - assert result.ok |
39 |
| - assert 2 < len(result.stdout.splitlines()) |
40 |
| - result = run_command(["core", "search", "avr", "--format", "json"]) |
41 |
| - assert result.ok |
42 |
| - data = json.loads(result.stdout) |
43 |
| - assert 0 < len(data) |
44 |
| - # additional URL |
45 |
| - result = run_command(["core", "search", "test_core", "--format", "json", f"--additional-urls={url}"]) |
46 |
| - assert result.ok |
47 |
| - data = json.loads(result.stdout) |
48 |
| - assert 1 == len(data) |
49 |
| - # show all versions |
50 |
| - result = run_command(["core", "search", "test_core", "--all", "--format", "json", f"--additional-urls={url}"]) |
51 |
| - assert result.ok |
52 |
| - data = json.loads(result.stdout) |
53 |
| - assert 2 == len(data) |
54 |
| - |
55 |
| - def get_platforms(stdout): |
56 |
| - data = json.loads(stdout) |
57 |
| - platforms = {p["id"]: [] for p in data} |
58 |
| - for p in data: |
59 |
| - platforms[p["id"]].append(p["latest"]) |
60 |
| - return platforms |
61 |
| - |
62 |
| - # Search all Retrokit platforms |
63 |
| - result = run_command(["core", "search", "retrokit", "--all", f"--additional-urls={url}", "--format", "json"]) |
64 |
| - assert result.ok |
65 |
| - platforms = get_platforms(result.stdout) |
66 |
| - assert "1.0.5" in platforms["Retrokits-RK002:arm"] |
67 |
| - assert "1.0.6" in platforms["Retrokits-RK002:arm"] |
68 |
| - |
69 |
| - # Search using Retrokit Package Maintainer |
70 |
| - result = run_command(["core", "search", "Retrokits-RK002", "--all", f"--additional-urls={url}", "--format", "json"]) |
71 |
| - assert result.ok |
72 |
| - platforms = get_platforms(result.stdout) |
73 |
| - assert "1.0.5" in platforms["Retrokits-RK002:arm"] |
74 |
| - assert "1.0.6" in platforms["Retrokits-RK002:arm"] |
75 |
| - |
76 |
| - # Search using the Retrokit Platform name |
77 |
| - result = run_command(["core", "search", "rk002", "--all", f"--additional-urls={url}", "--format", "json"]) |
78 |
| - assert result.ok |
79 |
| - platforms = get_platforms(result.stdout) |
80 |
| - assert "1.0.5" in platforms["Retrokits-RK002:arm"] |
81 |
| - assert "1.0.6" in platforms["Retrokits-RK002:arm"] |
82 |
| - |
83 |
| - # Search using board names |
84 |
| - result = run_command(["core", "search", "myboard", "--all", f"--additional-urls={url}", "--format", "json"]) |
85 |
| - assert result.ok |
86 |
| - platforms = get_platforms(result.stdout) |
87 |
| - assert "1.2.3" in platforms["Package:x86"] |
88 |
| - |
89 |
| - def run_search(search_args, expected_ids): |
90 |
| - res = run_command(["core", "search", "--format", "json"] + search_args.split(" ")) |
91 |
| - assert res.ok |
92 |
| - data = json.loads(res.stdout) |
93 |
| - platform_ids = [p["id"] for p in data] |
94 |
| - for platform_id in expected_ids: |
95 |
| - assert platform_id in platform_ids |
96 |
| - |
97 |
| - run_search("mkr1000", ["arduino:samd"]) |
98 |
| - run_search("mkr 1000", ["arduino:samd"]) |
99 |
| - |
100 |
| - run_search("yún", ["arduino:avr"]) |
101 |
| - run_search("yùn", ["arduino:avr"]) |
102 |
| - run_search("yun", ["arduino:avr"]) |
103 |
| - |
104 |
| - run_search("nano", ["arduino:avr", "arduino:megaavr", "arduino:samd", "arduino:mbed_nano"]) |
105 |
| - run_search("nano 33", ["arduino:samd", "arduino:mbed_nano"]) |
106 |
| - run_search("nano ble", ["arduino:mbed_nano"]) |
107 |
| - run_search("ble", ["arduino:mbed_nano"]) |
108 |
| - run_search("ble nano", ["arduino:mbed_nano"]) |
109 |
| - |
110 |
| - |
111 | 29 | def test_core_search_no_args(run_command, httpserver):
|
112 | 30 | """
|
113 | 31 | This tests `core search` with and without additional URLs in case no args
|
|
0 commit comments