1616import platform
1717import pytest
1818import simplejson as json
19+ from pathlib import Path
1920
2021
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 } " )
2429 # search a specific core
2530 result = run_command ("core search avr" )
2631 assert result .ok
@@ -41,15 +46,19 @@ def test_core_search(run_command):
4146 assert 2 == len (data )
4247
4348
44- def test_core_search_no_args (run_command ):
49+ def test_core_search_no_args (run_command , httpserver ):
4550 """
4651 This tests `core search` with and without additional URLs in case no args
4752 are passed (i.e. all results are shown).
4853 """
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+
4958 # 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 } " )
5362
5463 # list all with no additional urls, ensure the test core won't show up
5564 result = run_command ("core search" )
@@ -69,7 +78,7 @@ def test_core_search_no_args(run_command):
6978 assert len (platforms ) == num_platforms
7079
7180 # 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 } " )
7382 assert result .ok
7483 num_platforms = 0
7584 found = False
@@ -81,7 +90,7 @@ def test_core_search_no_args(run_command):
8190 assert found
8291
8392 # 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 } " )
8594 assert result .ok
8695 found = False
8796 platforms = json .loads (result .stdout )
0 commit comments