summaryrefslogtreecommitdiffstats
path: root/Lib/test/string_tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/string_tests.py')
-rw-r--r--Lib/test/string_tests.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index 837c1e8..0479601 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -5,7 +5,6 @@ Common tests shared by test_str, test_unicode, test_userstring and test_string.
import unittest, string, sys, struct
from test import test_support
from UserList import UserList
-import _testcapi
class Sequence:
def __init__(self, seq='wxyz'): self.seq = seq
@@ -1114,27 +1113,31 @@ class MixinStrUnicodeUserStringTest:
self.checkraises(TypeError, '%10.*f', '__mod__', ('foo', 42.))
self.checkraises(ValueError, '%10', '__mod__', (42,))
- width = int(_testcapi.PY_SSIZE_T_MAX + 1)
+ class X(object): pass
+ self.checkraises(TypeError, 'abc', '__mod__', X())
+ class X(Exception):
+ def __getitem__(self, k):
+ return k
+ self.checkequal('melon apple', '%(melon)s %(apple)s', '__mod__', X())
+
+ @test_support.cpython_only
+ def test_formatting_c_limits(self):
+ from _testcapi import PY_SSIZE_T_MAX, INT_MAX, UINT_MAX
+ SIZE_MAX = (1 << (PY_SSIZE_T_MAX.bit_length() + 1)) - 1
+ width = int(PY_SSIZE_T_MAX + 1)
if width <= sys.maxint:
self.checkraises(OverflowError, '%*s', '__mod__', (width, ''))
- prec = int(_testcapi.INT_MAX + 1)
+ prec = int(INT_MAX + 1)
if prec <= sys.maxint:
self.checkraises(OverflowError, '%.*f', '__mod__', (prec, 1. / 7))
# Issue 15989
- width = int(1 << (_testcapi.PY_SSIZE_T_MAX.bit_length() + 1))
+ width = int(SIZE_MAX + 1)
if width <= sys.maxint:
self.checkraises(OverflowError, '%*s', '__mod__', (width, ''))
- prec = int(_testcapi.UINT_MAX + 1)
+ prec = int(UINT_MAX + 1)
if prec <= sys.maxint:
self.checkraises(OverflowError, '%.*f', '__mod__', (prec, 1. / 7))
- class X(object): pass
- self.checkraises(TypeError, 'abc', '__mod__', X())
- class X(Exception):
- def __getitem__(self, k):
- return k
- self.checkequal('melon apple', '%(melon)s %(apple)s', '__mod__', X())
-
def test_floatformatting(self):
# float formatting
for prec in xrange(100):