diff options
author | Walter Dörwald <walter@livinglogic.de> | 2006-12-01 16:59:47 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2006-12-01 16:59:47 (GMT) |
commit | f008203cb4c98329bdcfd871afc66dfa3ed4ec94 (patch) | |
tree | 9b52282d7af15b74de0fc3cc73aa810044528773 /Lib/test/test_xdrlib.py | |
parent | c764340ba263d0358bffaa65a08a324d5035de45 (diff) | |
download | cpython-f008203cb4c98329bdcfd871afc66dfa3ed4ec94.zip cpython-f008203cb4c98329bdcfd871afc66dfa3ed4ec94.tar.gz cpython-f008203cb4c98329bdcfd871afc66dfa3ed4ec94.tar.bz2 |
Move xdrlib tests from the module into a separate test script,
port the tests to unittest and add a few new tests.
Diffstat (limited to 'Lib/test/test_xdrlib.py')
-rw-r--r-- | Lib/test/test_xdrlib.py | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/Lib/test/test_xdrlib.py b/Lib/test/test_xdrlib.py index e9517c5..8fc88a5 100644 --- a/Lib/test/test_xdrlib.py +++ b/Lib/test/test_xdrlib.py @@ -1,3 +1,56 @@ +from test import test_support +import unittest + import xdrlib -xdrlib._test() +class XDRTest(unittest.TestCase): + + def test_xdr(self): + p = xdrlib.Packer() + + s = 'hello world' + a = ['what', 'is', 'hapnin', 'doctor'] + + p.pack_int(42) + p.pack_uint(9) + p.pack_bool(True) + p.pack_bool(False) + p.pack_uhyper(45L) + p.pack_float(1.9) + p.pack_double(1.9) + p.pack_string(s) + p.pack_list(range(5), p.pack_uint) + p.pack_array(a, p.pack_string) + + # now verify + data = p.get_buffer() + up = xdrlib.Unpacker(data) + + self.assertEqual(up.get_position(), 0) + + self.assertEqual(up.unpack_int(), 42) + self.assertEqual(up.unpack_uint(), 9) + self.assert_(up.unpack_bool() is True) + + # remember position + pos = up.get_position() + self.assert_(up.unpack_bool() is False) + + # rewind and unpack again + up.set_position(pos) + self.assert_(up.unpack_bool() is False) + + self.assertEqual(up.unpack_uhyper(), 45L) + self.assertAlmostEqual(up.unpack_float(), 1.9) + self.assertAlmostEqual(up.unpack_double(), 1.9) + self.assertEqual(up.unpack_string(), s) + self.assertEqual(up.unpack_list(up.unpack_uint), range(5)) + self.assertEqual(up.unpack_array(up.unpack_string), a) + up.done() + self.assertRaises(EOFError, up.unpack_uint) + +def test_main(): + test_support.run_unittest(XDRTest) + +if __name__ == "__main__": + test_main() |