33# pylint:disable=redefined-outer-name 
44
55import  json 
6+ from  copy  import  deepcopy 
67import  shutil 
78import  urllib .request 
89from  pathlib  import  Path 
1819# HELPERS 
1920def  _download_url (url : str , file : Path ):
2021    # 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 :
2223        shutil .copyfileobj (response , out_file )
2324    assert  file .exists ()
2425
@@ -36,6 +37,7 @@ def _convert_to_simcore_labels(image_labels: Dict) -> Dict:
3637    assert  len (io_simcore_labels ) >  0 
3738    return  io_simcore_labels 
3839
40+ 
3941# FIXTURES 
4042@pytest .fixture  
4143def  osparc_service_labels_jsonschema (tmp_path ) ->  Dict :
@@ -44,19 +46,25 @@ def osparc_service_labels_jsonschema(tmp_path) -> Dict:
4446    _download_url (url , file_name )
4547    with  file_name .open () as  fp :
4648        json_schema  =  json .load (fp )
49+         # artifically add to legacy scheme new icon field which is optional 
50+         # NOTE: a prpoer fix is to migrate this repository to using ooil 
51+         json_schema ["properties" ]["icon" ] =  deepcopy (json_schema ["properties" ]["thumbnail" ])
4752        return  json_schema 
4853
4954
50- @pytest .fixture (scope = ' session'  ) 
55+ @pytest .fixture (scope = " session"  ) 
5156def  metadata_labels (metadata_file : Path ) ->  Dict :
5257    with  metadata_file .open () as  fp :
5358        metadata  =  yaml .safe_load (fp )
5459        return  metadata 
5560
61+ 
5662# TESTS 
5763
5864
59- def  test_docker_io_simcore_labels_against_files (docker_image : docker .models .images .Image , metadata_labels : Dict ):
65+ def  test_docker_io_simcore_labels_against_files (
66+     docker_image : docker .models .images .Image , metadata_labels : Dict 
67+ ):
6068    image_labels  =  docker_image .labels 
6169    io_simcore_labels  =  _convert_to_simcore_labels (image_labels )
6270    # check files are identical 
@@ -65,16 +73,18 @@ def test_docker_io_simcore_labels_against_files(docker_image: docker.models.imag
6573        assert  value  ==  metadata_labels [key ]
6674
6775
68- def  test_validate_docker_io_simcore_labels (docker_image : docker .models .images .Image , osparc_service_labels_jsonschema : Dict ):
76+ def  test_validate_docker_io_simcore_labels (
77+     docker_image : docker .models .images .Image , osparc_service_labels_jsonschema : Dict 
78+ ):
6979    image_labels  =  docker_image .labels 
7080    # get io labels 
7181    io_simcore_labels  =  _convert_to_simcore_labels (image_labels )
7282    # validate schema 
7383    try :
74-         jsonschema .validate (io_simcore_labels ,
75-                             osparc_service_labels_jsonschema )
84+         jsonschema .validate (io_simcore_labels , osparc_service_labels_jsonschema )
7685    except  jsonschema .SchemaError :
77-         pytest .fail ("Schema {} contains errors" .format (
78-             osparc_service_labels_jsonschema ))
86+         pytest .fail (
87+             "Schema {} contains errors" .format (osparc_service_labels_jsonschema )
88+         )
7989    except  jsonschema .ValidationError :
8090        pytest .fail ("Failed to validate docker image io labels against schema" )
0 commit comments