def test_map_name_print(): assert (print_config_type_to_string(Map(str, int, key_label_name="name")) == """{ [name: String]: Int }""") assert (print_config_type_to_string(Map(int, float, key_label_name="title")) == """{ [title: Int]: Float }""")
def test_multi_type_config_array_map(snapshot): @solid(config_schema=Array(Map(str, int))) def fancy_solid(_): pass @pipeline def noop_pipeline(): fancy_solid() pipeline_snapshot = PipelineSnapshot.from_pipeline_def(noop_pipeline) solid_def_snap = pipeline_snapshot.get_node_def_snap("fancy_solid") recevied_config_type = pipeline_snapshot.get_config_type_from_solid_def_snap(solid_def_snap) snapshot.assert_match(serialize_pp(snap_from_config_type(recevied_config_type))) _array_has_stable_hashes( recevied_config_type, pipeline_snapshot.config_schema_snapshot.all_config_snaps_by_key )
def test_deserialize_solid_def_snaps_map_with_name(): @solid(config_schema=Field(Map(bool, float, key_label_name="title"))) def noop_solid(_): pass @pipeline def noop_pipeline(): noop_solid() pipeline_snapshot = PipelineSnapshot.from_pipeline_def(noop_pipeline) solid_def_snap = pipeline_snapshot.get_node_def_snap("noop_solid") recevied_config_type = pipeline_snapshot.get_config_type_from_solid_def_snap(solid_def_snap) assert isinstance(recevied_config_type, Map) assert isinstance(recevied_config_type.key_type, Bool) assert isinstance(recevied_config_type.inner_type, Float) assert recevied_config_type.given_name == "title" _map_has_stable_hashes( recevied_config_type, pipeline_snapshot.config_schema_snapshot.all_config_snaps_by_key )
def _construct_map_from_snap(config_type_snap, config_snap_map): check.list_param(config_type_snap.type_param_keys, "type_param_keys", str) check.invariant( len(config_type_snap.type_param_keys) == 2, "Expect map to provide exactly two types (key, value). Snapshot provided: {}" .format(config_type_snap.type_param_keys), ) return Map( key_type=construct_config_type_from_snap( config_snap_map[config_type_snap.type_param_keys[0]], config_snap_map, ), inner_type=construct_config_type_from_snap( config_snap_map[config_type_snap.type_param_keys[1]], config_snap_map, ), # In a Map, the given_name stores the optional key_label_name key_label_name=config_type_snap.given_name, )
def config_with_map(): @solid( config_schema={ "field_one": Field(Map(str, int, key_label_name="username")), "field_two": Field({bool: int}, is_required=False), "field_three": Field( {str: { "nested": [Noneable(int)] }}, is_required=False, default_value={"test": { "nested": [None, 1, 2] }}, ), }) def a_solid_with_map_config(_context): return None noop_solid() a_solid_with_map_config()