summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_struct.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-04-06 15:19:40 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-04-06 15:19:40 (GMT)
commite9a5a549e41fee42bdcab34024d52fdf0620948c (patch)
tree7ea8db1fc82e9c7d9054b02a0184492f468623ae /Lib/test/test_struct.py
parentf6224e799c69220ba06c3fde9c300a23fab3f2ce (diff)
downloadcpython-e9a5a549e41fee42bdcab34024d52fdf0620948c.zip
cpython-e9a5a549e41fee42bdcab34024d52fdf0620948c.tar.gz
cpython-e9a5a549e41fee42bdcab34024d52fdf0620948c.tar.bz2
Fix incorrect stacklevel for struct warnings. (Partial backport of r78690).
Diffstat (limited to 'Lib/test/test_struct.py')
-rw-r--r--Lib/test/test_struct.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index cda7dee..ad754df 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -2,6 +2,7 @@ import array
import unittest
import struct
import warnings
+import inspect
warnings.filterwarnings("ignore", "struct integer overflow masking is deprecated",
DeprecationWarning)
@@ -106,6 +107,29 @@ class StructTest(unittest.TestCase):
self.assertRaises(struct.error, struct.unpack, 'iii', s)
self.assertRaises(struct.error, struct.unpack, 'i', s)
+ def test_warnings_stacklevel(self):
+ # Python versions between 2.6 and 2.6.5 were producing
+ # warning messages at the wrong stacklevel.
+ def inner(fn, *args):
+ return inspect.currentframe().f_lineno, fn(*args)
+
+ def check_warning_stacklevel(fn, *args):
+ with warnings.catch_warnings(record=True) as w:
+ # "always" to make sure __warningregistry__ isn't affected
+ warnings.simplefilter("always")
+ lineno, result = inner(fn, *args)
+ for warn in w:
+ self.assertEqual(warn.lineno, lineno)
+
+ # out of range warnings
+ check_warning_stacklevel(struct.pack, '<L', -1)
+ check_warning_stacklevel(struct.pack, 'L', -1)
+ check_warning_stacklevel(struct.pack, '<h', 65536)
+ check_warning_stacklevel(struct.pack, '<l', 2**100)
+
+ # float warnings
+ check_warning_stacklevel(struct.pack, 'L', 3.1)
+
def test_transitiveness(self):
c = 'a'
b = 1