summaryrefslogtreecommitdiff
path: root/tests/basics/string_format.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-03-15 13:07:41 +0000
committerDamien George <damien.p.george@gmail.com>2016-03-15 13:07:41 +0000
commitab69ed7dac1bf0ef36238b6289d436e9932180bc (patch)
treee20c26cc428d26d056097cbfc11a49bb0f178ec1 /tests/basics/string_format.py
parent9996adc37d3f518a30e28cbdfead71a5019e6a60 (diff)
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.
Diffstat (limited to 'tests/basics/string_format.py')
-rw-r--r--tests/basics/string_format.py153
1 files changed, 1 insertions, 152 deletions
diff --git a/tests/basics/string_format.py b/tests/basics/string_format.py
index e07f0d953..8b2592406 100644
--- a/tests/basics/string_format.py
+++ b/tests/basics/string_format.py
@@ -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')