forked from arduino/arduino-cli
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_core.py
645 lines (513 loc) · 26.4 KB
/
test_core.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# This file is part of arduino-cli.
#
# Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
#
# This software is released under the GNU General Public License version 3,
# which covers the main part of arduino-cli.
# The terms of this license can be found at:
# https://www.gnu.org/licenses/gpl-3.0.en.html
#
# You can be released from the requirements of the above licenses by purchasing
# a commercial license. Buying such a license is mandatory if you want to modify or
# otherwise use the software for commercial activities involving the Arduino
# software without disclosing the source code of your own applications. To purchase
# a commercial license, send an email to license@arduino.cc.
importos
importdatetime
importtime
importplatform
importpytest
importsimplejsonasjson
importtempfile
importhashlib
fromgitimportRepo
frompathlibimportPath
deftest_core_search(run_command, httpserver):
# Set up the server to serve our custom index file
test_index=Path(__file__).parent/"testdata"/"test_index.json"
httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text())
url=httpserver.url_for("/test_index.json")
assertrun_command(f"core update-index --additional-urls={url}")
# search a specific core
result=run_command("core search avr")
assertresult.ok
assert2<len(result.stdout.splitlines())
result=run_command("core search avr --format json")
assertresult.ok
data=json.loads(result.stdout)
assert0<len(data)
# additional URL
result=run_command("core search test_core --format json --additional-urls={}".format(url))
assertresult.ok
data=json.loads(result.stdout)
assert1==len(data)
# show all versions
result=run_command("core search test_core --all --format json --additional-urls={}".format(url))
assertresult.ok
data=json.loads(result.stdout)
assert2==len(data)
defget_platforms(stdout):
data=json.loads(stdout)
platforms= {p["id"]: [] forpindata}
forpindata:
platforms[p["id"]].append(p["latest"])
returnplatforms
# Search all Retrokit platforms
result=run_command(f"core search retrokit --all --additional-urls={url} --format json")
assertresult.ok
platforms=get_platforms(result.stdout)
assert"1.0.5"inplatforms["Retrokits-RK002:arm"]
assert"1.0.6"inplatforms["Retrokits-RK002:arm"]
# Search using Retrokit Package Maintainer
result=run_command(f"core search Retrokits-RK002 --all --additional-urls={url} --format json")
assertresult.ok
platforms=get_platforms(result.stdout)
assert"1.0.5"inplatforms["Retrokits-RK002:arm"]
assert"1.0.6"inplatforms["Retrokits-RK002:arm"]
# Search using the Retrokit Platform name
result=run_command(f"core search rk002 --all --additional-urls={url} --format json")
assertresult.ok
platforms=get_platforms(result.stdout)
assert"1.0.5"inplatforms["Retrokits-RK002:arm"]
assert"1.0.6"inplatforms["Retrokits-RK002:arm"]
# Search using board names
result=run_command(f"core search myboard --all --additional-urls={url} --format json")
assertresult.ok
platforms=get_platforms(result.stdout)
assert"1.2.3"inplatforms["Package:x86"]
defrun_search(search_args, expected_ids):
res=run_command(f"core search --format json {search_args}")
assertres.ok
data=json.loads(res.stdout)
platform_ids= [p["id"] forpindata]
forplatform_idinexpected_ids:
assertplatform_idinplatform_ids
run_search("mkr1000", ["arduino:samd"])
run_search("mkr 1000", ["arduino:samd"])
run_search("yún", ["arduino:avr"])
run_search("yùn", ["arduino:avr"])
run_search("yun", ["arduino:avr"])
run_search("nano", ["arduino:avr", "arduino:megaavr", "arduino:samd", "arduino:mbed_nano"])
run_search("nano 33", ["arduino:samd", "arduino:mbed_nano"])
run_search("nano ble", ["arduino:mbed_nano"])
run_search("ble", ["arduino:mbed_nano"])
run_search("ble nano", ["arduino:mbed_nano"])
deftest_core_search_no_args(run_command, httpserver):
"""
This tests `core search` with and without additional URLs in case no args
are passed (i.e. all results are shown).
"""
# Set up the server to serve our custom index file
test_index=Path(__file__).parent/"testdata"/"test_index.json"
httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text())
# update custom index and install test core (installed cores affect `core search`)
url=httpserver.url_for("/test_index.json")
assertrun_command(f"core update-index --additional-urls={url}")
assertrun_command(f"core install test:x86 --additional-urls={url}")
# list all with no additional urls, ensure the test core won't show up
result=run_command("core search")
assertresult.ok
num_platforms=0
lines= [l.strip().split() forlinresult.stdout.strip().splitlines()]
# The header is printed on the first lines
assert ["test:x86", "2.0.0", "test_core"] inlines
header_index=lines.index(["ID", "Version", "Name"])
# We use black to format and flake8 to lint .py files but they disagree on certain
# things like this one, thus we ignore this specific flake8 rule and stand by black
# opinion.
# We ignore this specific case because ignoring it globally would probably cause more
# issue. For more info about the rule see: https://www.flake8rules.com/rules/E203.html
num_platforms=len(lines[header_index+1 :]) # noqa: E203
# same thing in JSON format, also check the number of platforms found is the same
result=run_command("core search --format json")
assertresult.ok
platforms=json.loads(result.stdout)
assert1==len([eforeinplatformsife.get("name") =="test_core"])
assertlen(platforms) ==num_platforms
# list all with additional urls, check the test core is there
result=run_command(f"core search --additional-urls={url}")
assertresult.ok
num_platforms=0
lines= [l.strip().split() forlinresult.stdout.strip().splitlines()]
# The header is printed on the first lines
assert ["test:x86", "2.0.0", "test_core"] inlines
header_index=lines.index(["ID", "Version", "Name"])
# We use black to format and flake8 to lint .py files but they disagree on certain
# things like this one, thus we ignore this specific flake8 rule and stand by black
# opinion.
# We ignore this specific case because ignoring it globally would probably cause more
# issue. For more info about the rule see: https://www.flake8rules.com/rules/E203.html
num_platforms=len(lines[header_index+1 :]) # noqa: E203
# same thing in JSON format, also check the number of platforms found is the same
result=run_command(f"core search --format json --additional-urls={url}")
assertresult.ok
platforms=json.loads(result.stdout)
assert1==len([eforeinplatformsife.get("name") =="test_core"])
assertlen(platforms) ==num_platforms
deftest_core_updateindex_url_not_found(run_command, httpserver):
assertrun_command("core update-index")
# Brings up a local server to fake a failure
httpserver.expect_request("/test_index.json").respond_with_data(status=404)
url=httpserver.url_for("/test_index.json")
result=run_command(f"core update-index --additional-urls={url}")
assertresult.failed
lines= [l.strip() forlinresult.stderr.splitlines()]
assertf"Error updating index: downloading index {url}: 404 NOT FOUND"inlines
deftest_core_updateindex_internal_server_error(run_command, httpserver):
assertrun_command("core update-index")
# Brings up a local server to fake a failure
httpserver.expect_request("/test_index.json").respond_with_data(status=500)
url=httpserver.url_for("/test_index.json")
result=run_command(f"core update-index --additional-urls={url}")
assertresult.failed
lines= [l.strip() forlinresult.stderr.splitlines()]
assertf"Error updating index: downloading index {url}: 500 INTERNAL SERVER ERROR"inlines
deftest_core_install_without_updateindex(run_command):
# Missing "core update-index"
# Download samd core pinned to 1.8.6
result=run_command("core install arduino:samd@1.8.6")
assertresult.ok
assert"Updating index: package_index.json downloaded"inresult.stdout
@pytest.mark.skipif(
platform.system() =="Windows", reason="core fails with fatal error: bits/c++config.h: No such file or directory",
)
deftest_core_install_esp32(run_command, data_dir):
# update index
url="https://dl.espressif.com/dl/package_esp32_index.json"
assertrun_command(f"core update-index --additional-urls={url}")
# install 3rd-party core
assertrun_command(f"core install esp32:esp32@1.0.4 --additional-urls={url}")
# create a sketch and compile to double check the core was successfully installed
sketch_name="test_core_install_esp32"
sketch_path=os.path.join(data_dir, sketch_name)
assertrun_command(f"sketch new {sketch_path}")
assertrun_command(f"compile -b esp32:esp32:esp32 {sketch_path}")
# prevent regressions for https://github.com/arduino/arduino-cli/issues/163
sketch_path_md5=hashlib.md5(sketch_path.encode()).hexdigest().upper()
build_dir=Path(tempfile.gettempdir(), f"arduino-sketch-{sketch_path_md5}")
assert (build_dir/f"{sketch_name}.ino.partitions.bin").exists()
deftest_core_download(run_command, downloads_dir):
assertrun_command("core update-index")
# Download a specific core version
assertrun_command("core download arduino:avr@1.6.16")
assertos.path.exists(os.path.join(downloads_dir, "packages", "avr-1.6.16.tar.bz2"))
# Wrong core version
result=run_command("core download arduino:avr@69.42.0")
assertresult.failed
# Wrong core
result=run_command("core download bananas:avr")
assertresult.failed
def_in(jsondata, name, version=None):
installed_cores=json.loads(jsondata)
forcininstalled_cores:
ifname==c.get("id"):
ifversionisNone:
returnTrue
elifversion==c.get("installed"):
returnTrue
returnFalse
deftest_core_install(run_command):
assertrun_command("core update-index")
# Install a specific core version
assertrun_command("core install arduino:avr@1.6.16")
result=run_command("core list --format json")
assertresult.ok
assert_in(result.stdout, "arduino:avr", "1.6.16")
# Replace it with a more recent one
assertrun_command("core install arduino:avr@1.6.17")
result=run_command("core list --format json")
assertresult.ok
assert_in(result.stdout, "arduino:avr", "1.6.17")
# Confirm core is listed as "updatable"
result=run_command("core list --updatable --format json")
assertresult.ok
assert_in(result.stdout, "arduino:avr", "1.6.17")
# Upgrade the core to latest version
assertrun_command("core upgrade arduino:avr")
result=run_command("core list --format json")
assertresult.ok
assertnot_in(result.stdout, "arduino:avr", "1.6.17")
# double check the code isn't updatable anymore
result=run_command("core list --updatable --format json")
assertresult.ok
assertnot_in(result.stdout, "arduino:avr")
deftest_core_uninstall(run_command):
assertrun_command("core update-index")
assertrun_command("core install arduino:avr")
result=run_command("core list --format json")
assertresult.ok
assert_in(result.stdout, "arduino:avr")
assertrun_command("core uninstall arduino:avr")
result=run_command("core list --format json")
assertresult.ok
assertnot_in(result.stdout, "arduino:avr")
deftest_core_uninstall_tool_dependency_removal(run_command, data_dir):
# These platforms both have a dependency on the arduino:avr-gcc@7.3.0-atmel3.6.1-arduino5 tool
# arduino:avr@1.8.2 has a dependency on arduino:avrdude@6.3.0-arduino17
assertrun_command("core install arduino:avr@1.8.2")
# arduino:megaavr@1.8.4 has a dependency on arduino:avrdude@6.3.0-arduino16
assertrun_command("core install arduino:megaavr@1.8.4")
assertrun_command("core uninstall arduino:avr")
arduino_tools_path=Path(data_dir, "packages", "arduino", "tools")
avr_gcc_binaries_path=arduino_tools_path.joinpath("avr-gcc", "7.3.0-atmel3.6.1-arduino5", "bin")
# The tool arduino:avr-gcc@7.3.0-atmel3.6.1-arduino5 that is a dep of another installed platform should remain
assertavr_gcc_binaries_path.joinpath("avr-gcc").exists() oravr_gcc_binaries_path.joinpath("avr-gcc.exe").exists()
avrdude_binaries_path=arduino_tools_path.joinpath("avrdude", "6.3.0-arduino17", "bin")
# The tool arduino:avrdude@6.3.0-arduino17 that is only a dep of arduino:avr should have been removed
assert (
avrdude_binaries_path.joinpath("avrdude").exists() oravrdude_binaries_path.joinpath("avrdude.exe").exists()
) isFalse
deftest_core_zipslip(run_command):
url="https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/test_index.json"
assertrun_command("core update-index --additional-urls={}".format(url))
# Install a core and check if malicious content has been extracted.
run_command("core install zipslip:x86 --additional-urls={}".format(url))
assertos.path.exists("/tmp/evil.txt") isFalse
deftest_core_broken_install(run_command):
url="https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/test_index.json"
assertrun_command("core update-index --additional-urls={}".format(url))
assertnotrun_command("core install brokenchecksum:x86 --additional-urls={}".format(url))
deftest_core_install_creates_installed_json(run_command, data_dir):
assertrun_command("core update-index")
assertrun_command("core install arduino:avr@1.6.23")
installed_json_file=Path(data_dir, "packages", "arduino", "hardware", "avr", "1.6.23", "installed.json")
assertinstalled_json_file.exists()
installed_json=json.load(installed_json_file.open("r"))
expected_installed_json=json.load((Path(__file__).parent/"testdata"/"installed.json").open("r"))
defordered(obj):
ifisinstance(obj, dict):
returnsorted({k: ordered(v) fork, vinobj.items()})
ifisinstance(obj, list):
returnsorted(ordered(x) forxinobj)
else:
returnobj
assertordered(installed_json) ==ordered(expected_installed_json)
deftest_core_update_with_local_url(run_command):
test_index=str(Path(__file__).parent/"testdata"/"test_index.json")
ifplatform.system() =="Windows":
test_index=f"/{test_index}".replace("\\", "/")
res=run_command(f'core update-index --additional-urls="file://{test_index}"')
assertres.ok
assert"Updating index: test_index.json downloaded"inres.stdout
deftest_core_search_manually_installed_cores_not_printed(run_command, data_dir):
assertrun_command("core update-index")
# Verifies only cores in board manager are shown
res=run_command("core search --format json")
assertres.ok
cores=json.loads(res.stdout)
num_cores=len(cores)
assertnum_cores>0
# Manually installs a core in sketchbooks hardware folder
git_url="https://github.com/arduino/ArduinoCore-avr.git"
repo_dir=Path(data_dir, "hardware", "arduino-beta-development", "avr")
assertRepo.clone_from(git_url, repo_dir, multi_options=["-b 1.8.3"])
# Verifies manually installed core is not shown
res=run_command("core search --format json")
assertres.ok
cores=json.loads(res.stdout)
assertnum_cores==len(cores)
mapped= {core["id"]: coreforcoreincores}
core_id="arduino-beta-development:avr"
assertcore_idnotinmapped
deftest_core_list_all_manually_installed_core(run_command, data_dir):
assertrun_command("core update-index")
# Verifies only cores in board manager are shown
res=run_command("core list --all --format json")
assertres.ok
cores=json.loads(res.stdout)
num_cores=len(cores)
assertnum_cores>0
# Manually installs a core in sketchbooks hardware folder
git_url="https://github.com/arduino/ArduinoCore-avr.git"
repo_dir=Path(data_dir, "hardware", "arduino-beta-development", "avr")
assertRepo.clone_from(git_url, repo_dir, multi_options=["-b 1.8.3"])
# Verifies manually installed core is shown
res=run_command("core list --all --format json")
assertres.ok
cores=json.loads(res.stdout)
assertnum_cores+1==len(cores)
mapped= {core["id"]: coreforcoreincores}
expected_core_id="arduino-beta-development:avr"
assertexpected_core_idinmapped
assert"Arduino AVR Boards"==mapped[expected_core_id]["name"]
assert"1.8.3"==mapped[expected_core_id]["latest"]
deftest_core_list_updatable_all_flags(run_command, data_dir):
assertrun_command("core update-index")
# Verifies only cores in board manager are shown
res=run_command("core list --all --updatable --format json")
assertres.ok
cores=json.loads(res.stdout)
num_cores=len(cores)
assertnum_cores>0
# Manually installs a core in sketchbooks hardware folder
git_url="https://github.com/arduino/ArduinoCore-avr.git"
repo_dir=Path(data_dir, "hardware", "arduino-beta-development", "avr")
assertRepo.clone_from(git_url, repo_dir, multi_options=["-b 1.8.3"])
# Verifies using both --updatable and --all flags --all takes precedence
res=run_command("core list --all --updatable --format json")
assertres.ok
cores=json.loads(res.stdout)
assertnum_cores+1==len(cores)
mapped= {core["id"]: coreforcoreincores}
expected_core_id="arduino-beta-development:avr"
assertexpected_core_idinmapped
assert"Arduino AVR Boards"==mapped[expected_core_id]["name"]
assert"1.8.3"==mapped[expected_core_id]["latest"]
deftest_core_upgrade_removes_unused_tools(run_command, data_dir):
assertrun_command("update")
# Installs a core
assertrun_command("core install arduino:avr@1.8.2")
# Verifies expected tool is installed
tool_path=Path(data_dir, "packages", "arduino", "tools", "avr-gcc", "7.3.0-atmel3.6.1-arduino5")
asserttool_path.exists()
# Upgrades core
assertrun_command("core upgrade arduino:avr")
# Verifies tool is uninstalled since it's not used by newer core version
assertnottool_path.exists()
deftest_core_install_removes_unused_tools(run_command, data_dir):
assertrun_command("update")
# Installs a core
assertrun_command("core install arduino:avr@1.8.2")
# Verifies expected tool is installed
tool_path=Path(data_dir, "packages", "arduino", "tools", "avr-gcc", "7.3.0-atmel3.6.1-arduino5")
asserttool_path.exists()
# Installs newer version of already installed core
assertrun_command("core install arduino:avr@1.8.3")
# Verifies tool is uninstalled since it's not used by newer core version
assertnottool_path.exists()
deftest_core_list_with_installed_json(run_command, data_dir):
assertrun_command("update")
# Install core
url="https://adafruit.github.io/arduino-board-index/package_adafruit_index.json"
assertrun_command(f"core update-index --additional-urls={url}")
assertrun_command(f"core install adafruit:avr@1.4.13 --additional-urls={url}")
# Verifies installed core is correctly found and name is set
res=run_command("core list --format json")
assertres.ok
cores=json.loads(res.stdout)
mapped= {core["id"]: coreforcoreincores}
assertlen(mapped) ==1
assert"adafruit:avr"inmapped
assertmapped["adafruit:avr"]["name"] =="Adafruit AVR Boards"
# Deletes installed.json file, this file stores information about the core,
# that is used mostly when removing package indexes and their cores are still installed;
# this way we don't lose much information about it.
# It might happen that the user has old cores installed before the addition of
# the installed.json file so we need to handle those cases.
installed_json=Path(data_dir, "packages", "adafruit", "hardware", "avr", "1.4.13", "installed.json")
installed_json.unlink()
# Verifies installed core is still found and name is set
res=run_command("core list --format json")
assertres.ok
cores=json.loads(res.stdout)
mapped= {core["id"]: coreforcoreincores}
assertlen(mapped) ==1
assert"adafruit:avr"inmapped
# Name for this core changes since if there's installed.json file we read it from
# platform.txt, turns out that this core has different names used in different files
# thus the change.
assertmapped["adafruit:avr"]["name"] =="Adafruit Boards"
deftest_core_search_update_index_delay(run_command, data_dir):
assertrun_command("update")
# Verifies index update is not run
res=run_command("core search")
assertres.ok
assert"Updating index"notinres.stdout
# Change edit time of package index file
index_file=Path(data_dir, "package_index.json")
date=datetime.datetime.now() -datetime.timedelta(hours=25)
mod_time=time.mktime(date.timetuple())
os.utime(index_file, (mod_time, mod_time))
# Verifies index update is run
res=run_command("core search")
assertres.ok
assert"Updating index"inres.stdout
# Verifies index update is not run again
res=run_command("core search")
assertres.ok
assert"Updating index"notinres.stdout
deftest_core_search_sorted_results(run_command, httpserver):
# Set up the server to serve our custom index file
test_index=Path(__file__).parent/"testdata"/"test_index.json"
httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text())
# update custom index
url=httpserver.url_for("/test_index.json")
assertrun_command(f"core update-index --additional-urls={url}")
# list all with additional url specified
result=run_command(f"core search --additional-urls={url}")
assertresult.ok
lines= [l.strip().split(maxsplit=2) forlinresult.stdout.strip().splitlines()][1:]
not_deprecated= [lforlinlinesifnotl[2].startswith("[DEPRECATED]")]
deprecated= [lforlinlinesifl[2].startswith("[DEPRECATED]")]
# verify that results are already sorted correctly
assertnot_deprecated==sorted(not_deprecated, key=lambdatokens: tokens[2].lower())
assertdeprecated==sorted(deprecated, key=lambdatokens: tokens[2].lower())
# verify that deprecated platforms are the last ones
assertlines==not_deprecated+deprecated
# test same behaviour with json output
result=run_command(f"core search --additional-urls={url} --format=json")
assertresult.ok
platforms=json.loads(result.stdout)
not_deprecated= [pforpinplatformsifnotp.get("deprecated")]
deprecated= [pforpinplatformsifp.get("deprecated")]
# verify that results are already sorted correctly
assertnot_deprecated==sorted(not_deprecated, key=lambdakeys: keys["name"].lower())
assertdeprecated==sorted(deprecated, key=lambdakeys: keys["name"].lower())
# verify that deprecated platforms are the last ones
assertplatforms==not_deprecated+deprecated
deftest_core_list_sorted_results(run_command, httpserver):
# Set up the server to serve our custom index file
test_index=Path(__file__).parent/"testdata"/"test_index.json"
httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text())
# update custom index
url=httpserver.url_for("/test_index.json")
assertrun_command(f"core update-index --additional-urls={url}")
# install some core for testing
assertrun_command(f"core install test:x86 Retrokits-RK002:arm Package:x86 --additional-urls={url}")
# list all with additional url specified
result=run_command(f"core list --additional-urls={url}")
assertresult.ok
lines= [l.strip().split(maxsplit=3) forlinresult.stdout.strip().splitlines()][1:]
assertlen(lines) ==3
not_deprecated= [lforlinlinesifnotl[3].startswith("[DEPRECATED]")]
deprecated= [lforlinlinesifl[3].startswith("[DEPRECATED]")]
# verify that results are already sorted correctly
assertnot_deprecated==sorted(not_deprecated, key=lambdatokens: tokens[3].lower())
assertdeprecated==sorted(deprecated, key=lambdatokens: tokens[3].lower())
# verify that deprecated platforms are the last ones
assertlines==not_deprecated+deprecated
# test same behaviour with json output
result=run_command(f"core list --additional-urls={url} --format=json")
assertresult.ok
platforms=json.loads(result.stdout)
assertlen(platforms) ==3
not_deprecated= [pforpinplatformsifnotp.get("deprecated")]
deprecated= [pforpinplatformsifp.get("deprecated")]
# verify that results are already sorted correctly
assertnot_deprecated==sorted(not_deprecated, key=lambdakeys: keys["name"].lower())
assertdeprecated==sorted(deprecated, key=lambdakeys: keys["name"].lower())
# verify that deprecated platforms are the last ones
assertplatforms==not_deprecated+deprecated
deftest_core_list_deprecated_platform_with_installed_json(run_command, httpserver, data_dir):
# Set up the server to serve our custom index file
test_index=Path(__file__).parent/"testdata"/"test_index.json"
httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text())
# update custom index
url=httpserver.url_for("/test_index.json")
assertrun_command(f"core update-index --additional-urls={url}")
# install some core for testing
assertrun_command(f"core install Package:x86 --additional-urls={url}")
installed_json_file=Path(data_dir, "packages", "Package", "hardware", "x86", "1.2.3", "installed.json")
assertinstalled_json_file.exists()
installed_json=json.load(installed_json_file.open("r"))
platform=installed_json["packages"][0]["platforms"][0]
delplatform["deprecated"]
installed_json["packages"][0]["platforms"][0] =platform
withopen(installed_json_file, "w") asf:
json.dump(installed_json, f)
# test same behaviour with json output
result=run_command(f"core list --additional-urls={url} --format=json")
assertresult.ok
platforms=json.loads(result.stdout)
assertlen(platforms) ==1
assertplatforms[0]["deprecated"]