diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-11-15 11:22:27 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-11-15 11:22:27 (GMT) |
commit | 42826566f5da776c729f65f6b6ab425c738a8bfa (patch) | |
tree | 118bc5fb0e2f13aceca7579544d80c2dd8fe9a77 /Lib/test/test_sys.py | |
parent | 7aaa67eb0d53e4347d2022279d5f55be3da8afa2 (diff) | |
parent | 030e92d1a51c2caef0c23a74e65f0aaff002158f (diff) | |
download | cpython-42826566f5da776c729f65f6b6ab425c738a8bfa.zip cpython-42826566f5da776c729f65f6b6ab425c738a8bfa.tar.gz cpython-42826566f5da776c729f65f6b6ab425c738a8bfa.tar.bz2 |
Issue #22193: Fixed integer overflow error in sys.getsizeof().
Fixed an error in _PySys_GetSizeOf declaration.
Diffstat (limited to 'Lib/test/test_sys.py')
-rw-r--r-- | Lib/test/test_sys.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 93bb0ef..9ac105f 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -770,6 +770,37 @@ class SizeofTest(unittest.TestCase): # but lists are self.assertEqual(sys.getsizeof([]), vsize('Pn') + gc_header_size) + def test_errors(self): + class BadSizeof: + def __sizeof__(self): + raise ValueError + self.assertRaises(ValueError, sys.getsizeof, BadSizeof()) + + class InvalidSizeof: + def __sizeof__(self): + return None + self.assertRaises(TypeError, sys.getsizeof, InvalidSizeof()) + sentinel = ["sentinel"] + self.assertIs(sys.getsizeof(InvalidSizeof(), sentinel), sentinel) + + class FloatSizeof: + def __sizeof__(self): + return 4.5 + self.assertRaises(TypeError, sys.getsizeof, FloatSizeof()) + self.assertIs(sys.getsizeof(FloatSizeof(), sentinel), sentinel) + + class OverflowSizeof(int): + def __sizeof__(self): + return int(self) + self.assertEqual(sys.getsizeof(OverflowSizeof(sys.maxsize)), + sys.maxsize + self.gc_headsize) + with self.assertRaises(OverflowError): + sys.getsizeof(OverflowSizeof(sys.maxsize + 1)) + with self.assertRaises(ValueError): + sys.getsizeof(OverflowSizeof(-1)) + with self.assertRaises((ValueError, OverflowError)): + sys.getsizeof(OverflowSizeof(-sys.maxsize - 1)) + def test_default(self): size = test.support.calcvobjsize self.assertEqual(sys.getsizeof(True), size('') + self.longdigit) |