1
- # Source:
2
- # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-integration/test_all.py
3
1
# Copyright 2021 ARDUINO SA (http://www.arduino.cc/)
4
2
#
5
3
# This program is free software: you can redistribute it and/or modify
27
25
import hashlib
28
26
import json
29
27
import pathlib
30
- import platform
31
- import typing
32
28
import math
33
29
34
- import invoke .context
35
- import pytest
36
-
37
30
test_data_path = pathlib .Path (__file__ ).resolve ().parent .joinpath ("testdata" )
38
31
size_comparison_tolerance = 0.03 # Maximum allowed archive size difference ratio
39
32
40
33
41
- def test_all (run_command , working_dir ):
34
+ def test_sync (run_command , working_dir ):
42
35
working_dir_path = pathlib .Path (working_dir )
43
36
configuration = {
44
37
"BaseDownloadUrl" : "http://www.example.com/libraries/" ,
@@ -62,7 +55,7 @@ def test_all(run_command, working_dir):
62
55
"sync" ,
63
56
"--config-file" ,
64
57
working_dir_path .joinpath ("config.json" ),
65
- test_data_path .joinpath ("test_all " , "repos.txt" ),
58
+ test_data_path .joinpath ("test_sync " , "repos.txt" ),
66
59
]
67
60
68
61
# Run the engine
@@ -73,12 +66,12 @@ def test_all(run_command, working_dir):
73
66
check_libraries (configuration = configuration )
74
67
check_logs (
75
68
configuration = configuration ,
76
- golden_logs_parent_path = test_data_path .joinpath ("test_all " , "golden" , "logs" , "generate" ),
69
+ golden_logs_parent_path = test_data_path .joinpath ("test_sync " , "golden" , "logs" , "generate" ),
77
70
logs_subpath = pathlib .Path ("github.com" , "arduino-libraries" , "ArduinoCloudThing" , "index.html" ),
78
71
)
79
72
check_logs (
80
73
configuration = configuration ,
81
- golden_logs_parent_path = test_data_path .joinpath ("test_all " , "golden" , "logs" , "generate" ),
74
+ golden_logs_parent_path = test_data_path .joinpath ("test_sync " , "golden" , "logs" , "generate" ),
82
75
logs_subpath = pathlib .Path ("github.com" , "arduino-libraries" , "SpacebrewYun" , "index.html" ),
83
76
)
84
77
check_db (configuration = configuration )
@@ -92,12 +85,12 @@ def test_all(run_command, working_dir):
92
85
check_libraries (configuration = configuration )
93
86
check_logs (
94
87
configuration = configuration ,
95
- golden_logs_parent_path = test_data_path .joinpath ("test_all " , "golden" , "logs" , "update" ),
88
+ golden_logs_parent_path = test_data_path .joinpath ("test_sync " , "golden" , "logs" , "update" ),
96
89
logs_subpath = pathlib .Path ("github.com" , "arduino-libraries" , "ArduinoCloudThing" , "index.html" ),
97
90
)
98
91
check_logs (
99
92
configuration = configuration ,
100
- golden_logs_parent_path = test_data_path .joinpath ("test_all " , "golden" , "logs" , "update" ),
93
+ golden_logs_parent_path = test_data_path .joinpath ("test_sync " , "golden" , "logs" , "update" ),
101
94
logs_subpath = pathlib .Path ("github.com" , "arduino-libraries" , "SpacebrewYun" , "index.html" ),
102
95
)
103
96
check_db (configuration = configuration )
@@ -190,7 +183,7 @@ def check_db(configuration):
190
183
release ["Log" ] = "\n " .join ([line .rstrip () for line in release ["Log" ].splitlines ()])
191
184
192
185
# Load golden db
193
- golden_db_template = test_data_path .joinpath ("test_all " , "golden" , "db.json" ).read_text (encoding = "utf-8" )
186
+ golden_db_template = test_data_path .joinpath ("test_sync " , "golden" , "db.json" ).read_text (encoding = "utf-8" )
194
187
# Fill in mutable content
195
188
golden_db_string = string .Template (template = golden_db_template ).substitute (
196
189
base_download_url = configuration ["BaseDownloadUrl" ],
@@ -248,7 +241,7 @@ def check_index(configuration):
248
241
release ["checksum" ] = checksum_placeholder
249
242
250
243
# Load golden index
251
- golden_library_index_template = test_data_path .joinpath ("test_all " , "golden" , "library_index.json" ).read_text (
244
+ golden_library_index_template = test_data_path .joinpath ("test_sync " , "golden" , "library_index.json" ).read_text (
252
245
encoding = "utf-8"
253
246
)
254
247
# Fill in mutable content
@@ -319,57 +312,3 @@ def test_clean_checkout(run_command, working_dir):
319
312
for release in library_index ["libraries" ]:
320
313
# ssd1306@1.0.0 contains a .exe and so should fail validation.
321
314
assert not (release ["name" ] == "ssd1306" and release ["version" ] == "1.0.0" )
322
-
323
-
324
- @pytest .fixture (scope = "function" )
325
- def run_command (pytestconfig , working_dir ) -> typing .Callable [..., invoke .runners .Result ]:
326
- """Provide a wrapper around invoke's `run` API so that every test will work in the same temporary folder.
327
-
328
- Useful reference:
329
- http://docs.pyinvoke.org/en/1.4/api/runners.html#invoke.runners.Result
330
- """
331
-
332
- executable_path = pathlib .Path (pytestconfig .rootdir ).parent / "libraries-repository-engine"
333
-
334
- def _run (
335
- cmd : list ,
336
- custom_working_dir : typing .Optional [str ] = None ,
337
- custom_env : typing .Optional [dict ] = None ,
338
- ) -> invoke .runners .Result :
339
- if cmd is None :
340
- cmd = []
341
- if not custom_working_dir :
342
- custom_working_dir = working_dir
343
- quoted_cmd = []
344
- for token in cmd :
345
- quoted_cmd .append (f'"{ token } "' )
346
- cli_full_line = '"{}" {}' .format (executable_path , " " .join (quoted_cmd ))
347
- run_context = invoke .context .Context ()
348
- # It might happen that we need to change directories between drives on Windows,
349
- # in that case the "/d" flag must be used otherwise directory wouldn't change
350
- cd_command = "cd"
351
- if platform .system () == "Windows" :
352
- cd_command += " /d"
353
- # Context.cd() is not used since it doesn't work correctly on Windows.
354
- # It escapes spaces in the path using "\ " but it doesn't always work,
355
- # wrapping the path in quotation marks is the safest approach
356
- with run_context .prefix (f'{ cd_command } "{ custom_working_dir } "' ):
357
- return run_context .run (
358
- command = cli_full_line ,
359
- echo = False ,
360
- hide = True ,
361
- warn = True ,
362
- env = custom_env ,
363
- encoding = "utf-8" ,
364
- )
365
-
366
- return _run
367
-
368
-
369
- @pytest .fixture (scope = "function" )
370
- def working_dir (tmpdir_factory ) -> str :
371
- """Create a temporary folder for the test to run in. It will be created before running each test and deleted at the
372
- end. This way all the tests work in isolation.
373
- """
374
- work_dir = tmpdir_factory .mktemp (basename = "TestWorkingDir" )
375
- yield str (work_dir )
0 commit comments