|
7 | 7 | import unittest |
8 | 8 | import struct |
9 | 9 | import sys |
| 10 | +import warnings |
10 | 11 | import weakref |
11 | 12 |
|
12 | 13 | from test import support |
@@ -995,14 +996,25 @@ def test_c_complex_round_trip(self): |
995 | 996 | values = [complex(*_) for _ in combinations([1, -1, 0.0, -0.0, 2, |
996 | 997 | -3, INF, -INF, NAN], 2)] |
997 | 998 | for z in values: |
998 | | - for f in [ |
999 | | - 'F', 'D', 'Zf', 'Zd', |
1000 | | - '>F', '>D', '>Zf', '>Zd', |
1001 | | - '<F', '<D', '<Zf', '<Zd', |
1002 | | - ]: |
| 999 | + for f in ['Zf', 'Zd', '>Zf', '>Zd', '<Zf', '<Zd']: |
1003 | 1000 | with self.subTest(z=z, format=f): |
1004 | 1001 | round_trip = struct.unpack(f, struct.pack(f, z))[0] |
1005 | 1002 | self.assertComplexesAreIdentical(z, round_trip) |
| 1003 | + for f in ['F', 'D', '>F', '>D', '<F', '<D']: |
| 1004 | + z = 1+1j |
| 1005 | + with self.subTest(format=f): |
| 1006 | + with warnings.catch_warnings(): |
| 1007 | + warnings.simplefilter("error", DeprecationWarning) |
| 1008 | + self.assertRaises(DeprecationWarning, struct.pack, f, z) |
| 1009 | + with warnings.catch_warnings(): |
| 1010 | + with self.assertWarns(DeprecationWarning): |
| 1011 | + b = struct.pack(f, z) |
| 1012 | + with warnings.catch_warnings(): |
| 1013 | + warnings.simplefilter("error", DeprecationWarning) |
| 1014 | + self.assertRaises(DeprecationWarning, struct.unpack, f, b) |
| 1015 | + with self.assertWarns(DeprecationWarning): |
| 1016 | + round_trip = struct.unpack(f, b)[0] |
| 1017 | + self.assertComplexesAreIdentical(z, round_trip) |
1006 | 1018 |
|
1007 | 1019 | @unittest.skipIf( |
1008 | 1020 | support.is_android or support.is_apple_mobile, |
|
0 commit comments