def test_weechat_sample_private_message(): """This is a real message received from weechat.""" with open('page/test/private_hdata.bin') as hdata: msg = RelayParser(hdata.read()).message() with open('out', 'w') as f: f.write(pformat(msg))
def test_weechat_sample_data(): """This is the output I got from Weechat's "test" method.""" data = ( '\x00\x00\x00\x9e' '\x00' '\xff\xff\xff\xff' 'chrA' 'int\x00\x01\xe2@' 'lon\n1234567890' 'str\x00\x00\x00\x08a string' 'str\x00\x00\x00\x00' 'str\xff\xff\xff\xff' 'buf\x00\x00\x00\x06buffer' 'buf\xff\xff\xff\xff' 'ptr\x0c7fffd30a5778' 'tim\n1321993456' 'arrstr\x00\x00\x00\x02\x00\x00\x00\x03abc\x00\x00\x00\x02de' 'arrint\x00\x00\x00\x03\x00\x00\x00{\x00\x00\x01\xc8\x00\x00\x03\x15') eq_( RelayParser(data).message()[1], [ 'A', 123456, 1234567890, 'a string', '', None, 'buffer', None, '0x7fffd30a5778', datetime(2011, 11, 22, 20, 24, 16), ['abc', 'de'], [123, 456, 789], ])
def test_object_hdata_parts(): """ H-Data is really complicated. This tests each of the parts, building up to a full H-Data object. """ # H-Path data = '\x00\x00\x00\x1Bbuffer/lines/line/line_data' eq_(RelayParser(data).hpath(), ['buffer', 'lines', 'line', 'line_data']) # H-key data = 'foo:int' eq_(RelayParser(data).hkey(), ('foo', 'int')) # H-Keys data = '\x00\x00\x00\x0Anumber:int' eq_(RelayParser(data).hkeys(), [('number', 'int')]) data = '\x00\x00\x00\x13number:int,name:str' eq_(RelayParser(data).hkeys(), [('number', 'int'), ('name', 'str')])
def test_object_hdata_full(): # Full H-Data data = ( '\x00\x00\x00\x06' 'buffer' # h-path '\x00\x00\x00\x18' 'number:int,full_name:str' # keys '\x00\x00\x00\x02' # count # value 1 '\x05' '12345' # pointer '\x00\x00\x00\x01' # number '\x00\x00\x00\x0C' 'core.weechat' # full_name # value 2 '\x05' '6789a' # pointer '\x00\x00\x00\x02' # number '\x00\x00\x00\x13' 'irc.server.freenode' # full_name ) with open('d', 'w') as d: d.write(data) expected = { 'path': ['buffer'], 'keys': [('number', 'int'), ('full_name', 'str')], 'values': [ { '_pointers': [('buffer', '0x12345')], 'number': 1, 'full_name': 'core.weechat', }, { '_pointers': [('buffer', '0x6789a')], 'number': 2, 'full_name': 'irc.server.freenode', }, ] } eq_(RelayParser(data).o_hda(), expected)
def t(i, o): eq_(RelayParser(i).object(), o)
def test_parser_type(): eq_(RelayParser('chr').type(), 'chr')
def test_parser_int4(): eq_(RelayParser('\x02\x00\x00\x42').int4(), 0x02000042)
def t(i, o): eq_(RelayParser(i).message()[1], o)