def test_naming(self): self.assertEqual(d.unpack('<40s[name]', self.buf), d.odict(name='Jonny Normal'+(28*'\x00'))) self.buf.pos = 0 expected = d.odict() expected.append('Jonny Normal' + (28 * '\x00')) expected['pid'] = 0x12e expected['points'] = ls_odict([0, 1, 5, 5, 16, 8, 24] + ([0] * 35)) expected.append(4) self.assertEqual(d.unpack('<40s I [pid] (42B)[points] I', self.buf), expected)
def test_comments(self): self.assertEqual(d.unpack('<5s #6s\n x\n# s\n 6s', self.buf), ls_odict(['Jonny', 'Normal'])) self.buf.pos = 0 self.assertEqual(d.unpack('<(5s\n x #ignore space\n 6s)[name]', self.buf), d.odict(name=ls_odict(['Jonny', 'Normal'])))
def test_dont_care(self): self.assertEqual(d.unpack('<5s x 6s', self.buf), ls_odict(['Jonny', 'Normal'])) self.buf.pos = 0 self.assertEqual(d.unpack('<3s[nickname] 3x c[initial] 5s', self.buf), d.odict([('nickname', 'Jon'), ('initial', 'N'), (2, 'ormal')]))
def test_whitespace(self): self.assertEqual(d.unpack('<\n\n12s [name]\n 28x\n\tI \n\t[pid]\n\n\n', self.buf), d.odict([('name', 'Jonny Normal'), ('pid', 0x12e)]))