tests: Add more tests to improve coverage, mostly testing exceptions.
This commit is contained in:
@@ -123,4 +123,74 @@ if full_tests:
|
||||
for str in ('', 'a', 'bcd', 'This is a test with a longer string'):
|
||||
test_fmt(conv, fill, alignment, '', '', width, '', 's', str)
|
||||
|
||||
# TODO Add tests for erroneous format strings.
|
||||
# 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')
|
||||
|
||||
try:
|
||||
'abc{!d}'.format('1')
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
try:
|
||||
'{abc'.format('zzzz')
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
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')
|
||||
|
||||
Reference in New Issue
Block a user