3
3
# pylint:disable=redefined-outer-name
4
4
5
5
import json
6
+ from copy import deepcopy
6
7
import shutil
7
8
import urllib .request
8
9
from pathlib import Path
18
19
# HELPERS
19
20
def _download_url (url : str , file : Path ):
20
21
# Download the file from `url` and save it locally under `file_name`:
21
- with urllib .request .urlopen (url ) as response , file .open ('wb' ) as out_file :
22
+ with urllib .request .urlopen (url ) as response , file .open ("wb" ) as out_file :
22
23
shutil .copyfileobj (response , out_file )
23
24
assert file .exists ()
24
25
@@ -36,6 +37,7 @@ def _convert_to_simcore_labels(image_labels: Dict) -> Dict:
36
37
assert len (io_simcore_labels ) > 0
37
38
return io_simcore_labels
38
39
40
+
39
41
# FIXTURES
40
42
@pytest .fixture
41
43
def osparc_service_labels_jsonschema (tmp_path ) -> Dict :
@@ -44,19 +46,23 @@ def osparc_service_labels_jsonschema(tmp_path) -> Dict:
44
46
_download_url (url , file_name )
45
47
with file_name .open () as fp :
46
48
json_schema = json .load (fp )
49
+ json_schema ["properties" ]["icon" ] = deepcopy (json_schema ["properties" ]["thumbnail" ])
47
50
return json_schema
48
51
49
52
50
- @pytest .fixture (scope = ' session' )
53
+ @pytest .fixture (scope = " session" )
51
54
def metadata_labels (metadata_file : Path ) -> Dict :
52
55
with metadata_file .open () as fp :
53
56
metadata = yaml .safe_load (fp )
54
57
return metadata
55
58
59
+
56
60
# TESTS
57
61
58
62
59
- def test_docker_io_simcore_labels_against_files (docker_image : docker .models .images .Image , metadata_labels : Dict ):
63
+ def test_docker_io_simcore_labels_against_files (
64
+ docker_image : docker .models .images .Image , metadata_labels : Dict
65
+ ):
60
66
image_labels = docker_image .labels
61
67
io_simcore_labels = _convert_to_simcore_labels (image_labels )
62
68
# check files are identical
@@ -65,16 +71,18 @@ def test_docker_io_simcore_labels_against_files(docker_image: docker.models.imag
65
71
assert value == metadata_labels [key ]
66
72
67
73
68
- def test_validate_docker_io_simcore_labels (docker_image : docker .models .images .Image , osparc_service_labels_jsonschema : Dict ):
74
+ def test_validate_docker_io_simcore_labels (
75
+ docker_image : docker .models .images .Image , osparc_service_labels_jsonschema : Dict
76
+ ):
69
77
image_labels = docker_image .labels
70
78
# get io labels
71
79
io_simcore_labels = _convert_to_simcore_labels (image_labels )
72
80
# validate schema
73
81
try :
74
- jsonschema .validate (io_simcore_labels ,
75
- osparc_service_labels_jsonschema )
82
+ jsonschema .validate (io_simcore_labels , osparc_service_labels_jsonschema )
76
83
except jsonschema .SchemaError :
77
- pytest .fail ("Schema {} contains errors" .format (
78
- osparc_service_labels_jsonschema ))
84
+ pytest .fail (
85
+ "Schema {} contains errors" .format (osparc_service_labels_jsonschema )
86
+ )
79
87
except jsonschema .ValidationError :
80
88
pytest .fail ("Failed to validate docker image io labels against schema" )
0 commit comments