2828 SimcoreS3FileID ,
2929)
3030from models_library .services_types import ServicePortKey
31+ from pydantic import TypeAdapter
3132from servicelib .progress_bar import ProgressBarData
3233from settings_library .r_clone import RCloneSettings
3334from simcore_sdk import node_ports_v2
@@ -224,7 +225,7 @@ async def test_port_value_accessors(
224225 item_pytype : type ,
225226 option_r_clone_settings : RCloneSettings | None ,
226227): # pylint: disable=W0613, W0621
227- item_key = ServicePortKey ("some_key" )
228+ item_key = TypeAdapter ( ServicePortKey ). validate_python ("some_key" )
228229 config_dict , _ , _ = create_special_configuration (
229230 inputs = [(item_key , item_type , item_value )],
230231 outputs = [(item_key , item_type , None )],
@@ -299,17 +300,26 @@ async def test_port_file_accessors(
299300 )
300301 await check_config_valid (PORTS , config_dict )
301302 assert (
302- await (await PORTS .outputs )[ServicePortKey ("out_34" )].get () is None
303+ await (await PORTS .outputs )[
304+ TypeAdapter (ServicePortKey ).validate_python ("out_34" )
305+ ].get ()
306+ is None
303307 ) # check emptyness
304308 with pytest .raises (exceptions .S3InvalidPathError ):
305- await (await PORTS .inputs )[ServicePortKey ("in_1" )].get ()
309+ await (await PORTS .inputs )[
310+ TypeAdapter (ServicePortKey ).validate_python ("in_1" )
311+ ].get ()
306312
307313 # this triggers an upload to S3 + configuration change
308- await (await PORTS .outputs )[ServicePortKey ("out_34" )].set (item_value )
314+ await (await PORTS .outputs )[
315+ TypeAdapter (ServicePortKey ).validate_python ("out_34" )
316+ ].set (item_value )
309317 # this is the link to S3 storage
310- value = (await PORTS .outputs )[ServicePortKey ("out_34" )].value
318+ value = (await PORTS .outputs )[
319+ TypeAdapter (ServicePortKey ).validate_python ("out_34" )
320+ ].value
311321 assert isinstance (value , DownloadLink | PortLink | BaseFileLink )
312- received_file_link = value .dict (by_alias = True , exclude_unset = True )
322+ received_file_link = value .model_dump (by_alias = True , exclude_unset = True )
313323 assert received_file_link ["store" ] == s3_simcore_location
314324 assert (
315325 received_file_link ["path" ]
@@ -322,12 +332,21 @@ async def test_port_file_accessors(
322332
323333 # this triggers a download from S3 to a location in /tempdir/simcorefiles/item_key
324334 assert isinstance (
325- await (await PORTS .outputs )[ServicePortKey ("out_34" )].get (), item_pytype
335+ await (await PORTS .outputs )[
336+ TypeAdapter (ServicePortKey ).validate_python ("out_34" )
337+ ].get (),
338+ item_pytype ,
326339 )
327- downloaded_file = await (await PORTS .outputs )[ServicePortKey ("out_34" )].get ()
340+ downloaded_file = await (await PORTS .outputs )[
341+ TypeAdapter (ServicePortKey ).validate_python ("out_34" )
342+ ].get ()
328343 assert isinstance (downloaded_file , Path )
329344 assert downloaded_file .exists ()
330- assert str (await (await PORTS .outputs )[ServicePortKey ("out_34" )].get ()).startswith (
345+ assert str (
346+ await (await PORTS .outputs )[
347+ TypeAdapter (ServicePortKey ).validate_python ("out_34" )
348+ ].get ()
349+ ).startswith (
331350 str (
332351 Path (
333352 tempfile .gettempdir (),
@@ -472,9 +491,16 @@ async def test_get_value_from_previous_node(
472491 )
473492
474493 await check_config_valid (PORTS , config_dict )
475- input_value = await (await PORTS .inputs )[ServicePortKey ("in_15" )].get ()
494+ input_value = await (await PORTS .inputs )[
495+ TypeAdapter (ServicePortKey ).validate_python ("in_15" )
496+ ].get ()
476497 assert isinstance (input_value , item_pytype )
477- assert await (await PORTS .inputs )[ServicePortKey ("in_15" )].get () == item_value
498+ assert (
499+ await (await PORTS .inputs )[
500+ TypeAdapter (ServicePortKey ).validate_python ("in_15" )
501+ ].get ()
502+ == item_value
503+ )
478504
479505
480506@pytest .mark .parametrize (
@@ -516,7 +542,9 @@ async def test_get_file_from_previous_node(
516542 r_clone_settings = option_r_clone_settings ,
517543 )
518544 await check_config_valid (PORTS , config_dict )
519- file_path = await (await PORTS .inputs )[ServicePortKey ("in_15" )].get ()
545+ file_path = await (await PORTS .inputs )[
546+ TypeAdapter (ServicePortKey ).validate_python ("in_15" )
547+ ].get ()
520548 assert isinstance (file_path , item_pytype )
521549 assert file_path == Path (
522550 tempfile .gettempdir (),
@@ -577,7 +605,9 @@ async def test_get_file_from_previous_node_with_mapping_of_same_key_name(
577605 postgres_db , project_id , this_node_uuid , config_dict
578606 ) # pylint: disable=E1101
579607 await check_config_valid (PORTS , config_dict )
580- file_path = await (await PORTS .inputs )[ServicePortKey ("in_15" )].get ()
608+ file_path = await (await PORTS .inputs )[
609+ TypeAdapter (ServicePortKey ).validate_python ("in_15" )
610+ ].get ()
581611 assert isinstance (file_path , item_pytype )
582612 assert file_path == Path (
583613 tempfile .gettempdir (),
@@ -637,7 +667,9 @@ async def test_file_mapping(
637667 postgres_db , project_id , node_uuid , config_dict
638668 ) # pylint: disable=E1101
639669 await check_config_valid (PORTS , config_dict )
640- file_path = await (await PORTS .inputs )[ServicePortKey ("in_1" )].get ()
670+ file_path = await (await PORTS .inputs )[
671+ TypeAdapter (ServicePortKey ).validate_python ("in_1" )
672+ ].get ()
641673 assert isinstance (file_path , item_pytype )
642674 assert file_path == Path (
643675 tempfile .gettempdir (),
@@ -648,7 +680,9 @@ async def test_file_mapping(
648680 )
649681
650682 # let's get it a second time to see if replacing works
651- file_path = await (await PORTS .inputs )[ServicePortKey ("in_1" )].get ()
683+ file_path = await (await PORTS .inputs )[
684+ TypeAdapter (ServicePortKey ).validate_python ("in_1" )
685+ ].get ()
652686 assert isinstance (file_path , item_pytype )
653687 assert file_path == Path (
654688 tempfile .gettempdir (),
@@ -665,9 +699,11 @@ async def test_file_mapping(
665699 assert isinstance (file_path , Path )
666700 await PORTS .set_file_by_keymap (file_path )
667701 file_id = create_valid_file_uuid ("out_1" , file_path )
668- value = (await PORTS .outputs )[ServicePortKey ("out_1" )].value
702+ value = (await PORTS .outputs )[
703+ TypeAdapter (ServicePortKey ).validate_python ("out_1" )
704+ ].value
669705 assert isinstance (value , DownloadLink | PortLink | BaseFileLink )
670- received_file_link = value .dict (by_alias = True , exclude_unset = True )
706+ received_file_link = value .model_dump (by_alias = True , exclude_unset = True )
671707 assert received_file_link ["store" ] == s3_simcore_location
672708 assert received_file_link ["path" ] == file_id
673709 # received a new eTag
@@ -720,15 +756,19 @@ async def test_regression_concurrent_port_update_fails(
720756
721757 # when writing in serial these are expected to work
722758 for item_key , _ , _ in outputs :
723- await (await PORTS .outputs )[ServicePortKey (item_key )].set (int_item_value )
724- assert (await PORTS .outputs )[ServicePortKey (item_key )].value == int_item_value
759+ await (await PORTS .outputs )[
760+ TypeAdapter (ServicePortKey ).validate_python (item_key )
761+ ].set (int_item_value )
762+ assert (await PORTS .outputs )[
763+ TypeAdapter (ServicePortKey ).validate_python (item_key )
764+ ].value == int_item_value
725765
726766 # when writing in parallel and reading back,
727767 # they fail, with enough concurrency
728768 async def _upload_create_task (item_key : str ) -> None :
729- await (await PORTS .outputs )[ServicePortKey ( item_key )]. set (
730- parallel_int_item_value
731- )
769+ await (await PORTS .outputs )[
770+ TypeAdapter ( ServicePortKey ). validate_python ( item_key )
771+ ]. set ( parallel_int_item_value )
732772
733773 # updating in parallel creates a race condition
734774 results = await gather (
@@ -741,7 +781,7 @@ async def _upload_create_task(item_key: str) -> None:
741781 with pytest .raises (AssertionError ) as exc_info : # noqa: PT012
742782 for item_key , _ , _ in outputs :
743783 assert (await PORTS .outputs )[
744- ServicePortKey (item_key )
784+ TypeAdapter ( ServicePortKey ). validate_python (item_key )
745785 ].value == parallel_int_item_value
746786
747787 assert exc_info .value .args [0 ].startswith (
@@ -773,7 +813,7 @@ async def test_batch_update_inputs_outputs(
773813 async with ProgressBarData (num_steps = 2 , description = faker .pystr ()) as progress_bar :
774814 await PORTS .set_multiple (
775815 {
776- ServicePortKey (port .key ): (k , None )
816+ TypeAdapter ( ServicePortKey ). validate_python (port .key ): (k , None )
777817 for k , port in enumerate ((await PORTS .outputs ).values ())
778818 },
779819 progress_bar = progress_bar ,
@@ -782,7 +822,7 @@ async def test_batch_update_inputs_outputs(
782822 assert progress_bar ._current_steps == pytest .approx (1 ) # noqa: SLF001
783823 await PORTS .set_multiple (
784824 {
785- ServicePortKey (port .key ): (k , None )
825+ TypeAdapter ( ServicePortKey ). validate_python (port .key ): (k , None )
786826 for k , port in enumerate ((await PORTS .inputs ).values (), start = 1000 )
787827 },
788828 progress_bar = progress_bar ,
@@ -793,18 +833,38 @@ async def test_batch_update_inputs_outputs(
793833 ports_inputs = await PORTS .inputs
794834 for k , asd in enumerate (outputs ):
795835 item_key , _ , _ = asd
796- assert ports_outputs [ServicePortKey (item_key )].value == k
797- assert await ports_outputs [ServicePortKey (item_key )].get () == k
836+ assert (
837+ ports_outputs [TypeAdapter (ServicePortKey ).validate_python (item_key )].value
838+ == k
839+ )
840+ assert (
841+ await ports_outputs [
842+ TypeAdapter (ServicePortKey ).validate_python (item_key )
843+ ].get ()
844+ == k
845+ )
798846
799847 for k , asd in enumerate (inputs , start = 1000 ):
800848 item_key , _ , _ = asd
801- assert ports_inputs [ServicePortKey (item_key )].value == k
802- assert await ports_inputs [ServicePortKey (item_key )].get () == k
849+ assert (
850+ ports_inputs [TypeAdapter (ServicePortKey ).validate_python (item_key )].value
851+ == k
852+ )
853+ assert (
854+ await ports_inputs [
855+ TypeAdapter (ServicePortKey ).validate_python (item_key )
856+ ].get ()
857+ == k
858+ )
803859
804860 # test missing key raises error
805861 async with ProgressBarData (num_steps = 1 , description = faker .pystr ()) as progress_bar :
806862 with pytest .raises (UnboundPortError ):
807863 await PORTS .set_multiple (
808- {ServicePortKey ("missing_key_in_both" ): (123132 , None )},
864+ {
865+ TypeAdapter (ServicePortKey ).validate_python (
866+ "missing_key_in_both"
867+ ): (123132 , None )
868+ },
809869 progress_bar = progress_bar ,
810870 )
0 commit comments