22importlib.reload(negotiation)
24from atlas
import Object
26def stop():
import pdb; pdb.set_trace()
28def test(input, result="", result_str="", str="", codec=""):
30 if result!=res:
raise ValueError(
"result: %s" % res)
31 send_str = neg.get_send_str()
32 if result_str!=send_str:
33 raise ValueError(
"send_str: %s" % send_str)
34 if str!=neg.str:
raise ValueError(
"str: %s" % neg.str)
35 if codec!=neg.selected_codec:
36 raise ValueError(
"codec: %s" % neg.selected_codec)
39neg = NegotiationServer([
"Packed",
"XML"])
40test(
"Foo\n", result=
"fail", result_str=
"ATLAS server\nHuh?\n\n")
41test(
"Bar", result=
"fail", str=
"Bar")
42assert(neg.other_codecs==[])
45neg = NegotiationServer([
"Packed",
"XML"], id=
"this is test server")
46test(
"ATLAS client test here\n", result_str=
"ATLAS this is test server\n")
47test(
"ICAN ", str=
"ICAN ")
48test(
"Foo", str=
"ICAN Foo")
50test(
"ICAN XML\nICAN Packed\n\n", result=
"found", result_str=
"IWILL XML\n\n", codec=
"XML")
51assert(neg.other_codecs==[
'Foo',
'XML',
'Packed'])
54neg = NegotiationServer([
"Packed",
"XML"])
55test(
"ATLAS client test here\nICAN XML\n", codec=
"XML", result_str=
"ATLAS server\n")
56test(
"ICAN Packed\n\n", result=
"found", result_str=
"IWILL XML\n\n", codec=
"XML")
57assert(neg.other_codecs==[
'XML',
'Packed'])
60neg = NegotiationServer([
"Packed",
"XML"])
61test(
"", result_str=
"ATLAS server\n")
62test(
"ATLAS client test here\nICAN XML\n", codec=
"XML")
63test(
"ICAN Packed\n\n", result=
"found", result_str=
"IWILL XML\n\n", codec=
"XML")
64assert(neg.other_codecs==[
'XML',
'Packed'])
67neg = NegotiationServer([
"Packed",
"XML"])
68test(
"ATLAS client test here\nICAN X-foo\n", result_str=
"ATLAS server\n")
69test(
"\n", result=
"fail", result_str=
"ICAN Packed\nICAN XML\n\n")
70assert(neg.other_codecs==[
'X-foo'])
74neg = NegotiationClient([
"Packed",
"XML"])
75test(
"", result_str=
"ATLAS client\n")
76test(
"ATLAS server hi there\n", result_str=
"ICAN Packed\nICAN XML\n\n")
77test(
"IWILL Packed\n\n", result=
"found", codec=
"Packed")
78assert(neg.other_codecs==[
'Packed'])
82neg = NegotiationClient([
"X-foo"])
83test(
"", result_str=
"ATLAS client\n")
84test(
"ATLAS server hi there\n", result_str=
"ICAN X-foo\n\n")
85test(
"ICAN Packed\nICAN XML\n\n", result=
"fail")
86assert(neg.other_codecs==[
'Packed',
'XML'])
88neg = NegotiationClient()
89test(
"ATLAS server hi there\n", result_str=
"ATLAS client\nICAN Bach_beta2\nICAN XML\nICAN XML2_test\nICAN Packed\nICAN Binary1_beta\nICAN Binary2_test\n\n")
90test(
"IWILL XML\n\n", result=
"found", codec=
"XML")
92s = co.encode(Object(foo=42))+co.encoder.close()
93assert(s ==
'<atlas>\n\t<map>\n\t\t<int name="foo">42</int>\n\t</map>\n</atlas>\n')
94assert(co.decode(
"<atlas>")==[])
95assert(co.decode(s) == [Object(foo=42)])