Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 47eebca

Browse files
committedNov 9, 2022
Migrate TestCoreSearchNoArgs from test_core.py to core_test.go
1 parent 79e6484 commit 47eebca

File tree

2 files changed

+62
-59
lines changed

2 files changed

+62
-59
lines changed
 

‎internal/integrationtest/core/core_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,65 @@ func TestCoreSearch(t *testing.T) {
126126
runSearch("ble nano", "arduino:mbed_nano")
127127
runSearch("nano", "arduino:avr", "arduino:megaavr", "arduino:samd", "arduino:mbed_nano")
128128
}
129+
130+
func TestCoreSearchNoArgs(t *testing.T) {
131+
// This tests `core search` with and without additional URLs in case no args
132+
// are passed (i.e. all results are shown).
133+
134+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
135+
defer env.CleanUp()
136+
137+
// Set up an http server to serve our custom index file
138+
testIndex := paths.New("..", "testdata", "test_index.json")
139+
url := env.HTTPServeFile(8000, testIndex)
140+
141+
// update custom index and install test core (installed cores affect `core search`)
142+
_, _, err := cli.Run("core", "update-index", "--additional-urls="+url.String())
143+
require.NoError(t, err)
144+
_, _, err = cli.Run("core", "install", "test:x86", "--additional-urls="+url.String())
145+
require.NoError(t, err)
146+
147+
// list all with no additional urls, ensure the test core won't show up
148+
stdout, _, err := cli.Run("core", "search")
149+
require.NoError(t, err)
150+
var lines [][]string
151+
for _, v := range strings.Split(strings.TrimSpace(string(stdout)), "\n") {
152+
lines = append(lines, strings.Fields(strings.TrimSpace(v)))
153+
}
154+
// The header is printed on the first lines
155+
require.Equal(t, []string{"test:x86", "2.0.0", "test_core"}, lines[19])
156+
// We use black to format and flake8 to lint .py files but they disagree on certain
157+
// things like this one, thus we ignore this specific flake8 rule and stand by black
158+
// opinion.
159+
// We ignore this specific case because ignoring it globally would probably cause more
160+
// issue. For more info about the rule see: https://www.flake8rules.com/rules/E203.html
161+
numPlatforms := len(lines) - 1 // noqa: E203
162+
163+
// same thing in JSON format, also check the number of platforms found is the same
164+
stdout, _, err = cli.Run("core", "search", "--format", "json")
165+
require.NoError(t, err)
166+
requirejson.Query(t, stdout, " .[] | select(.name == \"test_core\") | . != \"\"", "true")
167+
requirejson.Query(t, stdout, "length", fmt.Sprint(numPlatforms))
168+
169+
// list all with additional urls, check the test core is there
170+
stdout, _, err = cli.Run("core", "search", "--additional-urls="+url.String())
171+
require.NoError(t, err)
172+
lines = nil
173+
for _, v := range strings.Split(strings.TrimSpace(string(stdout)), "\n") {
174+
lines = append(lines, strings.Fields(strings.TrimSpace(v)))
175+
}
176+
// The header is printed on the first lines
177+
require.Equal(t, []string{"test:x86", "2.0.0", "test_core"}, lines[20])
178+
// We use black to format and flake8 to lint .py files but they disagree on certain
179+
// things like this one, thus we ignore this specific flake8 rule and stand by black
180+
// opinion.
181+
// We ignore this specific case because ignoring it globally would probably cause more
182+
// issue. For more info about the rule see: https://www.flake8rules.com/rules/E203.html
183+
numPlatforms = len(lines) - 1 // noqa: E203
184+
185+
// same thing in JSON format, also check the number of platforms found is the same
186+
stdout, _, err = cli.Run("core", "search", "--format", "json", "--additional-urls="+url.String())
187+
require.NoError(t, err)
188+
requirejson.Query(t, stdout, " .[] | select(.name == \"test_core\") | . != \"\"", "true")
189+
requirejson.Query(t, stdout, "length", fmt.Sprint(numPlatforms))
190+
}

‎test/test_core.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -26,65 +26,6 @@
2626
import semver
2727

2828

29-
def test_core_search_no_args(run_command, httpserver):
30-
"""
31-
This tests `core search` with and without additional URLs in case no args
32-
are passed (i.e. all results are shown).
33-
"""
34-
# Set up the server to serve our custom index file
35-
test_index = Path(__file__).parent / "testdata" / "test_index.json"
36-
httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text())
37-
38-
# update custom index and install test core (installed cores affect `core search`)
39-
url = httpserver.url_for("/test_index.json")
40-
assert run_command(["core", "update-index", f"--additional-urls={url}"])
41-
assert run_command(["core", "install", "test:x86", f"--additional-urls={url}"])
42-
43-
# list all with no additional urls, ensure the test core won't show up
44-
result = run_command(["core", "search"])
45-
assert result.ok
46-
num_platforms = 0
47-
lines = [l.strip().split() for l in result.stdout.strip().splitlines()]
48-
# The header is printed on the first lines
49-
assert ["test:x86", "2.0.0", "test_core"] in lines
50-
header_index = lines.index(["ID", "Version", "Name"])
51-
# We use black to format and flake8 to lint .py files but they disagree on certain
52-
# things like this one, thus we ignore this specific flake8 rule and stand by black
53-
# opinion.
54-
# We ignore this specific case because ignoring it globally would probably cause more
55-
# issue. For more info about the rule see: https://www.flake8rules.com/rules/E203.html
56-
num_platforms = len(lines[header_index + 1 :]) # noqa: E203
57-
58-
# same thing in JSON format, also check the number of platforms found is the same
59-
result = run_command(["core", "search", "--format", "json"])
60-
assert result.ok
61-
platforms = json.loads(result.stdout)
62-
assert 1 == len([e for e in platforms if e.get("name") == "test_core"])
63-
assert len(platforms) == num_platforms
64-
65-
# list all with additional urls, check the test core is there
66-
result = run_command(["core", "search", f"--additional-urls={url}"])
67-
assert result.ok
68-
num_platforms = 0
69-
lines = [l.strip().split() for l in result.stdout.strip().splitlines()]
70-
# The header is printed on the first lines
71-
assert ["test:x86", "2.0.0", "test_core"] in lines
72-
header_index = lines.index(["ID", "Version", "Name"])
73-
# We use black to format and flake8 to lint .py files but they disagree on certain
74-
# things like this one, thus we ignore this specific flake8 rule and stand by black
75-
# opinion.
76-
# We ignore this specific case because ignoring it globally would probably cause more
77-
# issue. For more info about the rule see: https://www.flake8rules.com/rules/E203.html
78-
num_platforms = len(lines[header_index + 1 :]) # noqa: E203
79-
80-
# same thing in JSON format, also check the number of platforms found is the same
81-
result = run_command(["core", "search", "--format", "json", f"--additional-urls={url}"])
82-
assert result.ok
83-
platforms = json.loads(result.stdout)
84-
assert 1 == len([e for e in platforms if e.get("name") == "test_core"])
85-
assert len(platforms) == num_platforms
86-
87-
8829
def test_core_updateindex_url_not_found(run_command, httpserver):
8930
assert run_command(["core", "update-index"])
9031

0 commit comments

Comments
 (0)
Please sign in to comment.