def test_variable_type_parse(): vtype = VariableType.parse("name: TYPE") assert vtype.name == "name" assert vtype.type == "TYPE" assert vtype.parent is None assert vtype.is_constant vtype = VariableType.parse("name: type -> parent") assert vtype.name == "name" assert vtype.type == "type" assert vtype.parent == "parent" assert not vtype.is_constant
def _to_type_tree(types): vtypes = [] for vtype in sorted(types): if vtype.parents: parent = vtype.parents[0] else: parent = None vtypes.append(VariableType(vtype.name, vtype.name, parent)) return VariableTypeTree(vtypes)
def test_variable_type_serialization_deserialization(): signature = "name: type -> parent1" vtype = VariableType.parse(signature) data = vtype.serialize() vtype2 = VariableType.deserialize(data) assert vtype == vtype2