1def test(fmt, *args):
2    print("{:8s}".format(fmt) + ">" + fmt.format(*args) + "<")
3
4
5test("{:10.4}", 123.456)
6test("{:10.4e}", 123.456)
7test("{:10.4e}", -123.456)
8test("{:10.4f}", 123.456)
9test("{:10.4f}", -123.456)
10test("{:10.4g}", 123.456)
11test("{:10.4g}", -123.456)
12test("{:10.4n}", 123.456)
13test("{:e}", 100)
14test("{:f}", 200)
15test("{:g}", 300)
16
17test("{:10.4E}", 123.456)
18test("{:10.4E}", -123.456)
19test("{:10.4F}", 123.456)
20test("{:10.4F}", -123.456)
21test("{:10.4G}", 123.456)
22test("{:10.4G}", -123.456)
23
24test("{:06e}", float("inf"))
25test("{:06e}", float("-inf"))
26test("{:06e}", float("nan"))
27
28test("{:f}", False)
29test("{:f}", True)
30
31# The following fails right now
32# test("{:10.1}", 0.0)
33
34print("%.0f" % (1.750000 % 0.08333333333))
35# Below isn't compatible with single-precision float
36# print("%.1f" % (1.750000 % 0.08333333333))
37# print("%.2f" % (1.750000 % 0.08333333333))
38# print("%.12f" % (1.750000 % 0.08333333333))
39
40# tests for errors in format string
41
42try:
43    "{:10.1b}".format(0.0)
44except ValueError:
45    print("ValueError")
46