@@ -60,26 +60,6 @@ def test(fmt, *args):
6060test ("{:@=6d}" , - 123 )
6161test ("{:06d}" , - 123 )
6262
63- test ("{:10.4e}" , 123.456 )
64- test ("{:10.4e}" , - 123.456 )
65- test ("{:10.4f}" , 123.456 )
66- test ("{:10.4f}" , - 123.456 )
67- test ("{:10.4g}" , 123.456 )
68- test ("{:10.4g}" , - 123.456 )
69- test ("{:e}" , 100 )
70- test ("{:f}" , 200 )
71- test ("{:g}" , 300 )
72-
73- test ("{:10.4E}" , 123.456 )
74- test ("{:10.4E}" , - 123.456 )
75- test ("{:10.4F}" , 123.456 )
76- test ("{:10.4F}" , - 123.456 )
77- test ("{:10.4G}" , 123.456 )
78- test ("{:10.4G}" , - 123.456 )
79-
80- # The following fails right now
81- #test("{:10.1}", 0.0)
82-
8363def test_fmt (conv , fill , alignment , sign , prefix , width , precision , type , arg ):
8464 fmt = '{'
8565 if conv :
@@ -137,71 +117,4 @@ def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
137117 for str in ('' , 'a' , 'bcd' , 'This is a test with a longer string' ):
138118 test_fmt (conv , fill , alignment , '' , '' , width , '' , 's' , str )
139119
140- eg_nums = (0.0 , - 0.0 , 0.1 , 1.234 , 12.3459 , 1.23456789 , 123456789.0 , - 0.0 ,
141- - 0.1 , - 1.234 , - 12.3459 , 1e4 , 1e-4 , 1e5 , 1e-5 , 1e6 , 1e-6 , 1e10 ,
142- 1e37 , - 1e37 , 1e-37 , - 1e-37 ,
143- 1.23456e8 , 1.23456e7 , 1.23456e6 , 1.23456e5 , 1.23456e4 , 1.23456e3 , 1.23456e2 , 1.23456e1 , 1.23456e0 ,
144- 1.23456e-1 , 1.23456e-2 , 1.23456e-3 , 1.23456e-4 , 1.23456e-5 , 1.23456e-6 , 1.23456e-7 , 1.23456e-8 ,
145- - 1.23456e8 , - 1.23456e7 , - 1.23456e6 , - 1.23456e5 , - 1.23456e4 , - 1.23456e3 , - 1.23456e2 , - 1.23456e1 , - 1.23456e0 ,
146- - 1.23456e-1 , - 1.23456e-2 , - 1.23456e-3 , - 1.23456e-4 , - 1.23456e-5 , - 1.23456e-6 , - 1.23456e-7 , - 1.23456e-8 )
147-
148- if full_tests :
149- for type in ('e' , 'E' , 'g' , 'G' , 'n' ):
150- for width in ('' , '4' , '6' , '8' , '10' ):
151- for alignment in ('' , '<' , '>' , '=' , '^' ):
152- for fill in ('' , '@' , '0' , ' ' ):
153- for sign in ('' , '+' , '-' , ' ' ):
154- for prec in ('' , '1' , '3' , '6' ):
155- for num in eg_nums :
156- test_fmt ('' , fill , alignment , sign , '' , width , prec , type , num )
157-
158- # Note: We use 1.23459 rather than 1.2345 because '{:3f}'.format(1.2345)
159- # rounds differently than print("%.3f", 1.2345);
160-
161- f_nums = (0.0 , - 0.0 , 0.0001 , 0.001 , 0.01 , 0.1 , 1.0 , 10.0 ,
162- 0.0012 , 0.0123 , 0.1234 , 1.23459 , 12.3456 ,
163- - 0.0001 , - 0.001 , - 0.01 , - 0.1 , - 1.0 , - 10.0 ,
164- - 0.0012 , - 0.0123 , - 0.1234 , - 1.23459 , - 12.3456 )
165-
166- if full_tests :
167- for type in ('f' , 'F' ):
168- for width in ('' , '4' , '6' , '8' , '10' ):
169- for alignment in ('' , '<' , '>' , '=' , '^' ):
170- for fill in ('' , ' ' , '0' , '@' ):
171- for sign in ('' , '+' , '-' , ' ' ):
172- # An empty precision defaults to 6, but when uPy is
173- # configured to use a float, we can only use a
174- # precision of 6 with numbers less than 10 and still
175- # get results that compare to CPython (which uses
176- # long doubles).
177- for prec in ('1' , '2' , '3' ):
178- for num in f_nums :
179- test_fmt ('' , fill , alignment , sign , '' , width , prec , type , num )
180- for num in int_nums2 :
181- test_fmt ('' , fill , alignment , sign , '' , width , '' , type , num )
182-
183- pct_nums1 = (0.1 , 0.58 , 0.99 , - 0.1 , - 0.58 , - 0.99 )
184- pct_nums2 = (True , False , 1 , 0 , - 1 )
185-
186- if full_tests :
187- type = '%'
188- for width in ('' , '4' , '6' , '8' , '10' ):
189- for alignment in ('' , '<' , '>' , '=' , '^' ):
190- for fill in ('' , ' ' , '0' , '@' ):
191- for sign in ('' , '+' , '-' , ' ' ):
192- # An empty precision defaults to 6, but when uPy is
193- # configured to use a float, we can only use a
194- # precision of 6 with numbers less than 10 and still
195- # get results that compare to CPython (which uses
196- # long doubles).
197- for prec in ('1' , '2' , '3' ):
198- for num in pct_nums1 :
199- test_fmt ('' , fill , alignment , sign , '' , width , prec , type , num )
200- for num in pct_nums2 :
201- test_fmt ('' , fill , alignment , sign , '' , width , '' , type , num )
202-
203- # We don't currently test a type of '' with floats (see the detailed comment
204- # in objstr.c)
205-
206120# TODO Add tests for erroneous format strings.
207-
0 commit comments