def test_map_parse(self):
     dtype = ParamDType.parse(
         {
             "type": "map",
             "value_dtype": {
                 "type": "dict",  # test nesting
                 "properties": {"foo": {"type": "string"}},
             },
         }
     )
     self.assertEqual(
         repr(dtype),
         repr(
             ParamDType.Map(
                 value_dtype=ParamDType.Dict(properties={"foo": ParamDType.String()})
             )
         ),
     )
 def test_map_coerce_dict_wrong_value_type(self):
     dtype = ParamDType.Map(value_dtype=ParamDType.String())
     value = dtype.coerce({"a": 1, "b": None})
     self.assertEqual(value, {"a": "1", "b": ""})
 def test_map_coerce_non_dict(self):
     dtype = ParamDType.Map(value_dtype=ParamDType.String())
     value = dtype.coerce([1, 2, 3])
     self.assertEqual(value, {})
 def test_map_coerce_none(self):
     dtype = ParamDType.Map(value_dtype=ParamDType.String())
     value = dtype.coerce(None)
     self.assertEqual(value, {})
 def test_map_validate_bad_value_dtype(self):
     dtype = ParamDType.Map(value_dtype=ParamDType.String())
     value = {"a": 1, "c": 2}
     with self.assertRaises(ValueError):
         dtype.validate(value)
 def test_map_validate_ok(self):
     dtype = ParamDType.Map(value_dtype=ParamDType.String())
     value = {"a": "b", "c": "d"}
     dtype.validate(value)