16
16
import platform
17
17
import pytest
18
18
import simplejson as json
19
+ from pathlib import Path
19
20
20
21
21
- def test_core_search (run_command ):
22
- url = "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/test_index.json"
23
- assert run_command ("core update-index --additional-urls={}" .format (url ))
22
+ def test_core_search (run_command , httpserver ):
23
+ # Set up the server to serve our custom index file
24
+ test_index = Path (__file__ ).parent / "testdata" / "test_index.json"
25
+ httpserver .expect_request ("/test_index.json" ).respond_with_data (test_index .read_text ())
26
+
27
+ url = httpserver .url_for ("/test_index.json" )
28
+ assert run_command (f"core update-index --additional-urls={ url } " )
24
29
# search a specific core
25
30
result = run_command ("core search avr" )
26
31
assert result .ok
@@ -41,15 +46,19 @@ def test_core_search(run_command):
41
46
assert 2 == len (data )
42
47
43
48
44
- def test_core_search_no_args (run_command ):
49
+ def test_core_search_no_args (run_command , httpserver ):
45
50
"""
46
51
This tests `core search` with and without additional URLs in case no args
47
52
are passed (i.e. all results are shown).
48
53
"""
54
+ # Set up the server to serve our custom index file
55
+ test_index = Path (__file__ ).parent / "testdata" / "test_index.json"
56
+ httpserver .expect_request ("/test_index.json" ).respond_with_data (test_index .read_text ())
57
+
49
58
# update custom index and install test core (installed cores affect `core search`)
50
- url = "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/ test_index.json"
51
- assert run_command ("core update-index --additional-urls={}" . format ( url ) )
52
- assert run_command ("core install test:x86 --additional-urls={}" . format ( url ) )
59
+ url = httpserver . url_for ( "/ test_index.json")
60
+ assert run_command (f "core update-index --additional-urls={ url } " )
61
+ assert run_command (f "core install test:x86 --additional-urls={ url } " )
53
62
54
63
# list all with no additional urls, ensure the test core won't show up
55
64
result = run_command ("core search" )
@@ -69,7 +78,7 @@ def test_core_search_no_args(run_command):
69
78
assert len (platforms ) == num_platforms
70
79
71
80
# list all with additional urls, check the test core is there
72
- result = run_command ("core search --additional-urls={}" . format ( url ) )
81
+ result = run_command (f "core search --additional-urls={ url } " )
73
82
assert result .ok
74
83
num_platforms = 0
75
84
found = False
@@ -81,7 +90,7 @@ def test_core_search_no_args(run_command):
81
90
assert found
82
91
83
92
# same thing in JSON format, also check the number of platforms found is the same
84
- result = run_command ("core search --format json --additional-urls={}" . format ( url ) )
93
+ result = run_command (f "core search --format json --additional-urls={ url } " )
85
94
assert result .ok
86
95
found = False
87
96
platforms = json .loads (result .stdout )
0 commit comments