mirror of
https://github.com/micropython/micropython.git
synced 2025-08-24 19:40:35 +02:00
tests: Split large tests into smaller files, to run with a small heap.
All tests in basics/ directory can now run and pass using 64-bit unix port with only a 16k heap (./run-tests --heapsize 16k). Tests in this directory should remain small so they can be used for ports with a small heap.
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
# Change the following to True to get a much more comprehensive set of tests
|
||||
# to run, albeit, which take considerably longer.
|
||||
|
||||
full_tests = False
|
||||
# basic functionality test for {} format string
|
||||
|
||||
def test(fmt, *args):
|
||||
print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<')
|
||||
@@ -77,151 +74,3 @@ print("{text:{align}{width}}".format(text="foo", align=">", width=30))
|
||||
print("{foo}/foo".format(foo="bar"))
|
||||
print("{}".format(123, foo="bar"))
|
||||
print("{}-{foo}".format(123, foo="bar"))
|
||||
|
||||
def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
|
||||
fmt = '{'
|
||||
if conv:
|
||||
fmt += '!'
|
||||
fmt += conv
|
||||
fmt += ':'
|
||||
if alignment:
|
||||
fmt += fill
|
||||
fmt += alignment
|
||||
fmt += sign
|
||||
fmt += prefix
|
||||
fmt += width
|
||||
if precision:
|
||||
fmt += '.'
|
||||
fmt += precision
|
||||
fmt += type
|
||||
fmt += '}'
|
||||
test(fmt, arg)
|
||||
if fill == '0' and alignment == '=':
|
||||
fmt = '{:'
|
||||
fmt += sign
|
||||
fmt += prefix
|
||||
fmt += width
|
||||
if precision:
|
||||
fmt += '.'
|
||||
fmt += precision
|
||||
fmt += type
|
||||
fmt += '}'
|
||||
test(fmt, arg)
|
||||
|
||||
int_nums = (-1234, -123, -12, -1, 0, 1, 12, 123, 1234, True, False)
|
||||
int_nums2 = (-12, -1, 0, 1, 12, True, False)
|
||||
|
||||
if full_tests:
|
||||
for type in ('', 'b', 'd', 'o', 'x', 'X'):
|
||||
for width in ('', '1', '3', '5', '7'):
|
||||
for alignment in ('', '<', '>', '=', '^'):
|
||||
for fill in ('', ' ', '0', '@'):
|
||||
for sign in ('', '+', '-', ' '):
|
||||
for prefix in ('', '#'):
|
||||
for num in int_nums:
|
||||
test_fmt('', fill, alignment, sign, prefix, width, '', type, num)
|
||||
|
||||
if full_tests:
|
||||
for width in ('', '1', '2'):
|
||||
for alignment in ('', '<', '>', '^'):
|
||||
for fill in ('', ' ', '0', '@'):
|
||||
test_fmt('', fill, alignment, '', '', width, '', 'c', 48)
|
||||
|
||||
if full_tests:
|
||||
for conv in ('', 'r', 's'):
|
||||
for width in ('', '1', '4', '10'):
|
||||
for alignment in ('', '<', '>', '^'):
|
||||
for fill in ('', ' ', '0', '@'):
|
||||
for str in ('', 'a', 'bcd', 'This is a test with a longer string'):
|
||||
test_fmt(conv, fill, alignment, '', '', width, '', 's', str)
|
||||
|
||||
# tests for errors in format string
|
||||
|
||||
try:
|
||||
'{0:0}'.format('zzz')
|
||||
except (ValueError):
|
||||
print('ValueError')
|
||||
|
||||
try:
|
||||
'{1:}'.format(1)
|
||||
except IndexError:
|
||||
print('IndexError')
|
||||
|
||||
try:
|
||||
'}'.format('zzzz')
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
# end of format parsing conversion specifier
|
||||
try:
|
||||
'{!'.format('a')
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
# unknown conversion specifier
|
||||
try:
|
||||
'abc{!d}'.format('1')
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
try:
|
||||
'{abc'.format('zzzz')
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
# expected ':' after specifier
|
||||
try:
|
||||
'{!s :}'.format(2)
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
try:
|
||||
'{}{0}'.format(1, 2)
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
try:
|
||||
'{1:}'.format(1)
|
||||
except IndexError:
|
||||
print('IndexError')
|
||||
|
||||
try:
|
||||
'{ 0 :*^10}'.format(12)
|
||||
except KeyError:
|
||||
print('KeyError')
|
||||
|
||||
try:
|
||||
'{0}{}'.format(1)
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
try:
|
||||
'{}{}'.format(1)
|
||||
except IndexError:
|
||||
print('IndexError')
|
||||
|
||||
try:
|
||||
'{0:+s}'.format('1')
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
try:
|
||||
'{0:+c}'.format(1)
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
try:
|
||||
'{0:s}'.format(1)
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
try:
|
||||
'{:*"1"}'.format('zz')
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
# unknown format code for str arg
|
||||
try:
|
||||
'{:X}'.format('zz')
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
Reference in New Issue
Block a user