def test_to_dict(self): param_spec = ParamSpec.List( id_name="l", child_parameters=[ ParamSpec.String(id_name="s", default="foo"), ParamSpec.Column(id_name="c", visible_if=dict(id_name="s", value="iddqd")), ], ) param_dict = param_spec.to_dict() self.assertEqual( param_dict, { "type": "list", "id_name": "l", "name": "", "visible_if": None, "child_parameters": [ { "type": "string", "id_name": "s", "name": "", "default": "foo", "multiline": False, "placeholder": "", "syntax": None, "visible_if": None, }, { "type": "column", "id_name": "c", "placeholder": "", "name": "", "tab_parameter": None, "column_types": None, "visible_if": { "id_name": "s", "value": "iddqd" }, }, ], }, ) # Just to make sure our unit-test is sane: verify from_dict(to_json) # returns the original. self.assertEqual(ParamSpec.from_dict(param_dict), param_spec)
def test_list_dtype(self): # Check that ParamSpec's with List type produce correct nested DTypes param_spec = ParamSpec.from_dict( dict( id_name="p", type="list", child_parameters=[ { "id_name": "intparam", "type": "integer", "name": "my number" }, { "id_name": "colparam", "type": "column", "name": "my column" }, ], )) self.assertEqual( param_spec, ParamSpec.List( id_name="p", child_parameters=[ ParamSpec.Integer(id_name="intparam", name="my number"), ParamSpec.Column(id_name="colparam", name="my column"), ], ), ) dtype = param_spec.dtype expected_dtype = DT.List( DT.Dict({ "intparam": DT.Integer(), "colparam": DT.Column() })) # effectively do a deep compare with repr self.assertEqual(repr(dtype), repr(expected_dtype))