def test_seqtype_serialize(self): ls = [ ListOf(), ListOf(int), ListOf(int, str, bool, float), ListOf(int, str, min=1), ListOf(int, str, max=5), ListOf(int, str, bool, repeat=2), ListOf(int, str, bool, min=1, max=5, repeat=2), TupleOf(), TupleOf(int), TupleOf(int, str, bool, float), TupleOf(int, str, min=1), TupleOf(int, str, max=5), TupleOf(int, str, bool, repeat=2), TupleOf(int, str, bool, min=1, max=5, repeat=2), ] for typ in ls: val = typ.to_node() typ2 = node_to_type(val) self.assert_types_identical(typ, typ2) typ = ListOf(TupleOf(int, str, bool), TupleOf(int, str, min=1, max=5, repeat=1), ListOf()) val = typ.to_node() typ2 = node_to_type(val) self.assertEqual(repr(typ), repr(typ2))
def test_basetype_serialize(self): ls = [ int, str, bool, float, list, tuple, sample.Sample, agent.Agent, ] for typ in ls: val = type_to_node(typ) typ2 = node_to_type(val) self.assertEqual(typ, typ2) ls = [ (long, int), (unicode, str), (builtin.NullAgent, agent.Agent), (sample.MixinSample, sample.Sample), ] for (typ, restyp) in ls: val = type_to_node(typ) typ2 = node_to_type(val) self.assertEqual(restyp, typ2)
def test_seqtype_serialize(self): ls = [ ListOf(), ListOf(int), ListOf(int, str, bool, float), ListOf(int, str, min=1), ListOf(int, str, max=5), ListOf(int, str, bool, repeat=2), ListOf(int, str, bool, min=1, max=5, repeat=2), TupleOf(), TupleOf(int), TupleOf(int, str, bool, float), TupleOf(int, str, min=1), TupleOf(int, str, max=5), TupleOf(int, str, bool, repeat=2), TupleOf(int, str, bool, min=1, max=5, repeat=2), ] for typ in ls: val = typ.to_node() typ2 = node_to_type(val) self.assert_types_identical(typ, typ2) typ = ListOf( TupleOf(int, str, bool), TupleOf(int, str, min=1, max=5, repeat=1), ListOf() ) val = typ.to_node() typ2 = node_to_type(val) self.assertEqual(repr(typ), repr(typ2))
def test_wrapped_serialize(self): typ = Wrapped(int) val = type_to_node(typ) typ2 = node_to_type(val) self.assert_(isinstance(typ2, Wrapped)) self.assertEqual(typ2.type, int) typ = Wrapped(ListOf(int, bool)) val = type_to_node(typ) typ2 = node_to_type(val) self.assert_(isinstance(typ2, Wrapped)) self.assert_(isinstance(typ2.type, ListOf)) self.assertEqual(typ2.type.types, (int, bool))
def test_basetype_serialize(self): ls = [ int, str, bool, float, list, tuple, sample.Sample, agent.Agent, ] for typ in ls: val = type_to_node(typ) typ2 = node_to_type(val) self.assertEqual(typ, typ2) ls = [ (long,int), (unicode,str), (builtin.NullAgent, agent.Agent), (sample.MixinSample, sample.Sample), ] for (typ, restyp) in ls: val = type_to_node(typ) typ2 = node_to_type(val) self.assertEqual(restyp, typ2)