Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_xdrlib.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | d3f9a6d7f6e4 |
| children |
| rev | line source |
|---|---|
|
40412
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
1 from test import test_support |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
2 import unittest |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
3 |
|
34632
77b57087fe45
Patch #1049151: adding bool support to xdrlib.py.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
4 import xdrlib |
|
77b57087fe45
Patch #1049151: adding bool support to xdrlib.py.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
5 |
|
40412
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
6 class XDRTest(unittest.TestCase): |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
7 |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
8 def test_xdr(self): |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
9 p = xdrlib.Packer() |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
10 |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
11 s = 'hello world' |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
12 a = ['what', 'is', 'hapnin', 'doctor'] |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
13 |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
14 p.pack_int(42) |
|
69010
d3f9a6d7f6e4
Issue #9696: Fix exception incorrectly raised by xdrlib.Packer.pack_int when trying to pack a negative (in-range) integer.
Mark Dickinson <mdickinson@enthought.com>
parents:
55002
diff
changeset
|
15 p.pack_int(-17) |
|
40412
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
16 p.pack_uint(9) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
17 p.pack_bool(True) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
18 p.pack_bool(False) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
19 p.pack_uhyper(45L) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
20 p.pack_float(1.9) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
21 p.pack_double(1.9) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
22 p.pack_string(s) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
23 p.pack_list(range(5), p.pack_uint) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
24 p.pack_array(a, p.pack_string) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
25 |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
26 # now verify |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
27 data = p.get_buffer() |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
28 up = xdrlib.Unpacker(data) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
29 |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
30 self.assertEqual(up.get_position(), 0) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
31 |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
32 self.assertEqual(up.unpack_int(), 42) |
|
69010
d3f9a6d7f6e4
Issue #9696: Fix exception incorrectly raised by xdrlib.Packer.pack_int when trying to pack a negative (in-range) integer.
Mark Dickinson <mdickinson@enthought.com>
parents:
55002
diff
changeset
|
33 self.assertEqual(up.unpack_int(), -17) |
|
40412
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
34 self.assertEqual(up.unpack_uint(), 9) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40412
diff
changeset
|
35 self.assertTrue(up.unpack_bool() is True) |
|
40412
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
36 |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
37 # remember position |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
38 pos = up.get_position() |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40412
diff
changeset
|
39 self.assertTrue(up.unpack_bool() is False) |
|
40412
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
40 |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
41 # rewind and unpack again |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
42 up.set_position(pos) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40412
diff
changeset
|
43 self.assertTrue(up.unpack_bool() is False) |
|
40412
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
44 |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
45 self.assertEqual(up.unpack_uhyper(), 45L) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
46 self.assertAlmostEqual(up.unpack_float(), 1.9) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
47 self.assertAlmostEqual(up.unpack_double(), 1.9) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
48 self.assertEqual(up.unpack_string(), s) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
49 self.assertEqual(up.unpack_list(up.unpack_uint), range(5)) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
50 self.assertEqual(up.unpack_array(up.unpack_string), a) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
51 up.done() |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
52 self.assertRaises(EOFError, up.unpack_uint) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
53 |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
54 def test_main(): |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
55 test_support.run_unittest(XDRTest) |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
56 |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
57 if __name__ == "__main__": |
|
d800d6737556
Move xdrlib tests from the module into a separate test script,
Walter Dörwald <walter@livinglogic.de>
parents:
34818
diff
changeset
|
58 test_main() |
