Skip to content

Commit 7adc2e0

Browse files
committed
Turn off full tests in string-format.py
Add some basic coverage tests
1 parent 51413c8 commit 7adc2e0

1 file changed

Lines changed: 65 additions & 7 deletions

File tree

tests/basics/string-format.py

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Change the following to True to get a much more comprehensive set of tests
2+
# to run, albeit, which take considerably longer.
3+
4+
full_tests = False
5+
16
def test(fmt, *args):
27
print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<')
38

@@ -6,10 +11,63 @@ def test(fmt, *args):
611
test("{1}-{0}", 1, [4, 5])
712
test("{:x}", 1)
813
test("{!r}", 2)
9-
test("{1}-{0}", 1, [4, 5])
1014
test("{:x}", 0x10)
1115
test("{!r}", "foo")
1216
test("{!s}", "foo")
17+
test("{0!r:>10s} {0!s:>10s}", "foo")
18+
19+
test("{:4b}", 10)
20+
test("{:4c}", 48)
21+
test("{:4d}", 123)
22+
test("{:4n}", 123)
23+
test("{:4o}", 123)
24+
test("{:4x}", 123)
25+
test("{:4X}", 123)
26+
27+
test("{:#4b}", 10)
28+
test("{:#4o}", 123)
29+
test("{:#4x}", 123)
30+
test("{:#4X}", 123)
31+
32+
test("{:<6s}", "ab")
33+
test("{:>6s}", "ab")
34+
test("{:^6s}", "ab")
35+
36+
test("{: <6d}", 123)
37+
test("{: <6d}", -123)
38+
test("{:0<6d}", 123)
39+
test("{:0<6d}", -123)
40+
test("{:@<6d}", 123)
41+
test("{:@<6d}", -123)
42+
43+
test("{:@< 6d}", 123)
44+
test("{:@< 6d}", -123)
45+
test("{:@<+6d}", 123)
46+
test("{:@<+6d}", -123)
47+
test("{:@<-6d}", 123)
48+
test("{:@<-6d}", -123)
49+
50+
test("{:@>6d}", -123)
51+
test("{:@<6d}", -123)
52+
test("{:@=6d}", -123)
53+
test("{:06d}", -123)
54+
55+
test("{:10.4e}", 123.456)
56+
test("{:10.4e}", -123.456)
57+
test("{:10.4f}", 123.456)
58+
test("{:10.4f}", -123.456)
59+
test("{:10.4g}", 123.456)
60+
test("{:10.4g}", -123.456)
61+
62+
test("{:10.4E}", 123.456)
63+
test("{:10.4E}", -123.456)
64+
test("{:10.4F}", 123.456)
65+
test("{:10.4F}", -123.456)
66+
test("{:10.4G}", 123.456)
67+
test("{:10.4G}", -123.456)
68+
69+
# The following fails right now
70+
#test("{:10.1}", 0.0)
1371

1472
def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
1573
fmt = '{'
@@ -44,7 +102,7 @@ def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
44102
int_nums = (-1234, -123, -12, -1, 0, 1, 12, 123, 1234, True, False)
45103
int_nums2 = (-12, -1, 0, 1, 12, True, False)
46104

47-
if True:
105+
if full_tests:
48106
for type in ('', 'b', 'd', 'o', 'x', 'X'):
49107
for width in ('', '1', '3', '5', '7'):
50108
for alignment in ('', '<', '>', '=', '^'):
@@ -54,13 +112,13 @@ def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
54112
for num in int_nums:
55113
test_fmt('', fill, alignment, sign, prefix, width, '', type, num)
56114

57-
if True:
115+
if full_tests:
58116
for width in ('', '1', '2'):
59117
for alignment in ('', '<', '>', '^'):
60118
for fill in ('', ' ', '0', '@'):
61119
test_fmt('', fill, alignment, '', '', width, '', 'c', 48)
62120

63-
if True:
121+
if full_tests:
64122
for conv in ('', 'r', 's'):
65123
for width in ('', '1', '4', '10'):
66124
for alignment in ('', '<', '>', '^'):
@@ -76,7 +134,7 @@ def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
76134
-1.23456e8, -1.23456e7, -1.23456e6, -1.23456e5, -1.23456e4, -1.23456e3, -1.23456e2, -1.23456e1, -1.23456e0,
77135
-1.23456e-1, -1.23456e-2, -1.23456e-3, -1.23456e-4, -1.23456e-5, -1.23456e-6, -1.23456e-7, -1.23456e-8)
78136

79-
if True:
137+
if full_tests:
80138
for type in ('e', 'E', 'g', 'G', 'n'):
81139
for width in ('', '4', '6', '8', '10'):
82140
for alignment in ('', '<', '>', '=', '^'):
@@ -94,7 +152,7 @@ def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
94152
-0.0001, -0.001, -0.01, -0.1, -1.0, -10.0,
95153
-0.0012, -0.0123, -0.1234, -1.23459, -12.3456)
96154

97-
if True:
155+
if full_tests:
98156
for type in ('f', 'F'):
99157
for width in ('', '4', '6', '8', '10'):
100158
for alignment in ('', '<', '>', '=', '^'):
@@ -114,7 +172,7 @@ def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
114172
pct_nums1 = (0.1, 0.58, 0.99, -0.1, -0.58, -0.99)
115173
pct_nums2 = (True, False, 1, 0, -1)
116174

117-
if True:
175+
if full_tests:
118176
type = '%'
119177
for width in ('', '4', '6', '8', '10'):
120178
for alignment in ('', '<', '>', '=', '^'):

0 commit comments

Comments
 (0)