diff options
Diffstat (limited to 'source3/python/examples/tdbpack')
-rwxr-xr-x | source3/python/examples/tdbpack/test_tdbpack.py | 66 |
1 files changed, 29 insertions, 37 deletions
diff --git a/source3/python/examples/tdbpack/test_tdbpack.py b/source3/python/examples/tdbpack/test_tdbpack.py index 659dc0efed..36fed881e3 100755 --- a/source3/python/examples/tdbpack/test_tdbpack.py +++ b/source3/python/examples/tdbpack/test_tdbpack.py @@ -17,12 +17,13 @@ string, with one character per field.""" __author__ = 'Martin Pool <mbp@sourcefrog.net>' import unittest -import oldtdbutil +# import tdbutil import samba.tdbpack -both_unpackers = (samba.tdbpack.unpack, oldtdbutil.unpack) -both_packers = (samba.tdbpack.pack, oldtdbutil.pack) - +packer = samba.tdbpack.pack +unpacker = samba.tdbpack.unpack + + class PackTests(unittest.TestCase): symm_cases = [('B', ['hello' * 51], '\xff\0\0\0' + 'hello' * 51), ('w', [42], '\x2a\0'), @@ -77,13 +78,11 @@ class PackTests(unittest.TestCase): def test_symmetric(self): """Cookbook of symmetric pack/unpack tests """ - for packer in both_packers: - for unpacker in both_unpackers: - for format, values, expected in self.symm_cases: - self.assertEquals(packer(format, values), expected) - out, rest = unpacker(format, expected) - self.assertEquals(rest, '') - self.assertEquals(list(values), list(out)) + for format, values, expected in self.symm_cases: + self.assertEquals(packer(format, values), expected) + out, rest = unpacker(format, expected) + self.assertEquals(rest, '') + self.assertEquals(list(values), list(out)) def test_pack(self): @@ -101,30 +100,25 @@ class PackTests(unittest.TestCase): # as if you called list() ] - for packer in both_packers: - for format, values, expected in cases: - self.assertEquals(packer(format, values), expected) + for format, values, expected in cases: + self.assertEquals(packer(format, values), expected) def test_unpack_extra(self): # Test leftover data - for unpacker in both_unpackers: - for format, values, packed in self.symm_cases: - out, rest = unpacker(format, packed + 'hello sailor!') - self.assertEquals(rest, 'hello sailor!') - self.assertEquals(list(values), list(out)) + for format, values, packed in self.symm_cases: + out, rest = unpacker(format, packed + 'hello sailor!') + self.assertEquals(rest, 'hello sailor!') + self.assertEquals(list(values), list(out)) def test_unpack(self): """Cookbook of tricky unpack tests""" cases = [ - # Apparently I couldn't think of any tests that weren't - # symmetric :-/ ] - for unpacker in both_unpackers: - for format, values, expected in cases: - out, rest = unpacker(format, expected) - self.assertEquals(rest, '') - self.assertEquals(list(values), list(out)) + for format, values, expected in cases: + out, rest = unpacker(format, expected) + self.assertEquals(rest, '') + self.assertEquals(list(values), list(out)) def test_pack_failures(self): @@ -147,7 +141,7 @@ class PackTests(unittest.TestCase): ('f', [2], TypeError), ('P', [None], TypeError), ('P', (), IndexError), - ('f', [hex], TypeError), + ('f', [packer], TypeError), ('fw', ['hello'], IndexError), ('f', [u'hello'], TypeError), ('B', [2], TypeError), @@ -159,11 +153,10 @@ class PackTests(unittest.TestCase): ('fQ', ['2'], IndexError), (2, [2], TypeError), ({}, {}, TypeError)] - for packer in both_packers: - for format, values, throwable_class in cases: - def do_pack(): - packer(format, values) - self.assertRaises(throwable_class, do_pack) + for format, values, throwable_class in cases: + def do_pack(): + packer(format, values) + self.assertRaises(throwable_class, do_pack) def test_unpack_failures(self): @@ -189,11 +182,10 @@ class PackTests(unittest.TestCase): ('B', 'foobar', IndexError), ('BB', '\x01\0\0\0a\x01', IndexError), ] - - for unpacker in both_unpackers: - for format, values, throwable_class in cases: - def do_unpack(): - unpacker(format, values) + + for format, values, throwable_class in cases: + def do_unpack(): + unpacker(format, values) self.assertRaises(throwable_class, do_unpack) |