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