MCPcopy Index your code
hub / github.com/python/cpython / test_new_features

Method test_new_features

Lib/test/test_struct.py:90–148  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

88 self.assertEqual(tp, t)
89
90 def test_new_features(self):
91 # Test some of the new features in detail
92 # (format, argument, big-endian result, little-endian result, asymmetric)
93 tests = [
94 ('c', b'a', b'a', b'a', 0),
95 ('xc', b'a', b'\0a', b'\0a', 0),
96 ('cx', b'a', b'a\0', b'a\0', 0),
97 ('s', b'a', b'a', b'a', 0),
98 ('0s', b'helloworld', b'', b'', 1),
99 ('1s', b'helloworld', b'h', b'h', 1),
100 ('9s', b'helloworld', b'helloworl', b'helloworl', 1),
101 ('10s', b'helloworld', b'helloworld', b'helloworld', 0),
102 ('11s', b'helloworld', b'helloworld\0', b'helloworld\0', 1),
103 ('20s', b'helloworld', b'helloworld'+10*b'\0', b'helloworld'+10*b'\0', 1),
104 ('0p', b'helloworld', b'', b'', 1),
105 ('1p', b'helloworld', b'\x00', b'\x00', 1),
106 ('2p', b'helloworld', b'\x01h', b'\x01h', 1),
107 ('10p', b'helloworld', b'\x09helloworl', b'\x09helloworl', 1),
108 ('11p', b'helloworld', b'\x0Ahelloworld', b'\x0Ahelloworld', 0),
109 ('12p', b'helloworld', b'\x0Ahelloworld\0', b'\x0Ahelloworld\0', 1),
110 ('20p', b'helloworld', b'\x0Ahelloworld'+9*b'\0', b'\x0Ahelloworld'+9*b'\0', 1),
111 ('b', 7, b'\7', b'\7', 0),
112 ('b', -7, b'\371', b'\371', 0),
113 ('B', 7, b'\7', b'\7', 0),
114 ('B', 249, b'\371', b'\371', 0),
115 ('h', 700, b'\002\274', b'\274\002', 0),
116 ('h', -700, b'\375D', b'D\375', 0),
117 ('H', 700, b'\002\274', b'\274\002', 0),
118 ('H', 0x10000-700, b'\375D', b'D\375', 0),
119 ('i', 70000000, b'\004,\035\200', b'\200\035,\004', 0),
120 ('i', -70000000, b'\373\323\342\200', b'\200\342\323\373', 0),
121 ('I', 70000000, b'\004,\035\200', b'\200\035,\004', 0),
122 ('I', 0x100000000-70000000, b'\373\323\342\200', b'\200\342\323\373', 0),
123 ('l', 70000000, b'\004,\035\200', b'\200\035,\004', 0),
124 ('l', -70000000, b'\373\323\342\200', b'\200\342\323\373', 0),
125 ('L', 70000000, b'\004,\035\200', b'\200\035,\004', 0),
126 ('L', 0x100000000-70000000, b'\373\323\342\200', b'\200\342\323\373', 0),
127 ('f', 2.0, b'@\000\000\000', b'\000\000\000@', 0),
128 ('d', 2.0, b'@\000\000\000\000\000\000\000',
129 b'\000\000\000\000\000\000\000@', 0),
130 ('f', -2.0, b'\300\000\000\000', b'\000\000\000\300', 0),
131 ('d', -2.0, b'\300\000\000\000\000\000\000\000',
132 b'\000\000\000\000\000\000\000\300', 0),
133 ('?', 0, b'\0', b'\0', 0),
134 ('?', 3, b'\1', b'\1', 1),
135 ('?', True, b'\1', b'\1', 0),
136 ('?', [], b'\0', b'\0', 1),
137 ('?', (1,), b'\1', b'\1', 1),
138 ]
139
140 for fmt, arg, big, lil, asy in tests:
141 for (xfmt, exp) in [('>'+fmt, big), ('!'+fmt, big), ('<'+fmt, lil),
142 ('='+fmt, ISBIGENDIAN and big or lil)]:
143 res = struct.pack(xfmt, arg)
144 self.assertEqual(res, exp)
145 self.assertEqual(struct.calcsize(xfmt), len(res))
146 rev = struct.unpack(xfmt, res)[0]
147 if rev != arg:

Callers

nothing calls this directly

Calls 4

unpackMethod · 0.80
assertTrueMethod · 0.80
packMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected