tests/stress: Add test for maximum length limit of qstrs.

pull/1/head
Damien George 2019-11-22 16:18:25 +11:00
parent bc129f1b84
commit 1675b98e74
2 changed files with 128 additions and 0 deletions

View File

@ -0,0 +1,85 @@
# Test interning qstrs that go over the limit of the maximum qstr length
# (which is 255 bytes for the default configuration)
def make_id(n, base='a'):
return ''.join(chr(ord(base) + i % 26) for i in range(n))
# identifiers in parser
for l in range(254, 259):
g = {}
var = make_id(l)
try:
exec(var + '=1', g)
except RuntimeError:
print('RuntimeError', l)
continue
print(var in g)
# calling a function with kwarg
def f(**k):
print(k)
for l in range(254, 259):
try:
exec('f({}=1)'.format(make_id(l)))
except RuntimeError:
print('RuntimeError', l)
# type construction
for l in range(254, 259):
id = make_id(l)
try:
print(type(id, (), {}).__name__)
except RuntimeError:
print('RuntimeError', l)
# hasattr, setattr, getattr
class A:
pass
for l in range(254, 259):
id = make_id(l)
a = A()
try:
setattr(a, id, 123)
except RuntimeError:
print('RuntimeError', l)
try:
print(hasattr(a, id), getattr(a, id))
except RuntimeError:
print('RuntimeError', l)
# format with keys
for l in range(254, 259):
id = make_id(l)
try:
print(('{' + id + '}').format(**{id: l}))
except RuntimeError:
print('RuntimeError', l)
# modulo format with keys
for l in range(254, 259):
id = make_id(l)
try:
print(('%(' + id + ')d') % {id: l})
except RuntimeError:
print('RuntimeError', l)
# import module
# (different OS's have different results so only print those that are consistent)
for l in range(150, 259):
try:
__import__(make_id(l))
except ImportError:
if l < 152:
print('ok', l)
except RuntimeError:
if l > 255:
print('RuntimeError', l)
# import package
for l in range(125, 130):
try:
exec('import ' + make_id(l) + '.' + make_id(l, 'A'))
except ImportError:
print('ok', l)
except RuntimeError:
print('RuntimeError', l)

View File

@ -0,0 +1,43 @@
True
True
RuntimeError 256
RuntimeError 257
RuntimeError 258
{'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst': 1}
{'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu': 1}
RuntimeError 256
RuntimeError 257
RuntimeError 258
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu
RuntimeError 256
RuntimeError 257
RuntimeError 258
True 123
True 123
RuntimeError 256
RuntimeError 256
RuntimeError 257
RuntimeError 257
RuntimeError 258
RuntimeError 258
254
255
RuntimeError 256
RuntimeError 257
RuntimeError 258
254
255
RuntimeError 256
RuntimeError 257
RuntimeError 258
ok 150
ok 151
RuntimeError 256
RuntimeError 257
RuntimeError 258
ok 125
ok 126
ok 127
RuntimeError 128
RuntimeError 129