Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_format.py @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | e93f5c385ff4 |
| children | aa0d2d51fbde |
| rev | line source |
|---|---|
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
17450
diff
changeset
|
1 from test_support import verbose, have_unicode |
|
16516
af88465999c7
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
15977
diff
changeset
|
2 import sys |
|
13194
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3 |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
4 # test string formatting operator (I am not sure if this is being tested |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
5 # elsewhere but, surely, some of the given cases are *not* tested because |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
6 # they crash python) |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
7 # test on unicode strings as well |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
8 |
|
14713
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
9 overflowok = 1 |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
10 |
|
13194
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
11 def testformat(formatstr, args, output=None): |
|
14713
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
12 if verbose: |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
13 if output: |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
14 print "%s %% %s =? %s ..." %\ |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
15 (repr(formatstr), repr(args), repr(output)), |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
16 else: |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
17 print "%s %% %s works? ..." % (repr(formatstr), repr(args)), |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
18 try: |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
19 result = formatstr % args |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
20 except OverflowError: |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
21 if not overflowok: |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
22 raise |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
23 if verbose: |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
24 print 'overflow (this is fine)' |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
25 else: |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
26 if output and result != output: |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
27 if verbose: |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
28 print 'no' |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
29 print "%s %% %s == %s != %s" %\ |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
30 (repr(formatstr), repr(args), repr(result), repr(output)) |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
31 else: |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
32 if verbose: |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
33 print 'yes' |
|
13194
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
34 |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
35 def testboth(formatstr, *args): |
|
14713
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
36 testformat(formatstr, *args) |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
17450
diff
changeset
|
37 if have_unicode: |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
17450
diff
changeset
|
38 testformat(unicode(formatstr), *args) |
|
14713
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
39 |
|
13194
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
40 |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
41 testboth("%.1d", (1,), "1") |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
42 testboth("%.*d", (sys.maxint,1)) # expect overflow |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
43 testboth("%.100d", (1,), '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001') |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
44 testboth("%#.117x", (1,), '0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001') |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
45 testboth("%#.118x", (1,), '0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001') |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
46 |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
47 testboth("%f", (1.0,), "1.000000") |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
48 # these are trying to test the limits of the internal magic-number-length |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
49 # formatting buffer, if that number changes then these tests are less |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
50 # effective |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
51 testboth("%#.*g", (109, -1.e+49/3.)) |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
52 testboth("%#.*g", (110, -1.e+49/3.)) |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
53 testboth("%#.*g", (110, -1.e+100/3.)) |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
54 |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
55 # test some ridiculously large precision, expect overflow |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
56 testboth('%12.*f', (123456, 1.0)) |
|
753af62ab8a1
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
57 |
|
14713
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
58 # Formatting of long integers. Overflow is not ok |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
59 overflowok = 0 |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
60 testboth("%x", 10L, "a") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
61 testboth("%x", 100000000000L, "174876e800") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
62 testboth("%o", 10L, "12") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
63 testboth("%o", 100000000000L, "1351035564000") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
64 testboth("%d", 10L, "10") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
65 testboth("%d", 100000000000L, "100000000000") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
66 |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
67 big = 123456789012345678901234567890L |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
68 testboth("%d", big, "123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
69 testboth("%d", -big, "-123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
70 testboth("%5d", -big, "-123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
71 testboth("%31d", -big, "-123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
72 testboth("%32d", -big, " -123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
73 testboth("%-32d", -big, "-123456789012345678901234567890 ") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
74 testboth("%032d", -big, "-0123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
75 testboth("%-032d", -big, "-123456789012345678901234567890 ") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
76 testboth("%034d", -big, "-000123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
77 testboth("%034d", big, "0000123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
78 testboth("%0+34d", big, "+000123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
79 testboth("%+34d", big, " +123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
80 testboth("%34d", big, " 123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
81 testboth("%.2d", big, "123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
82 testboth("%.30d", big, "123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
83 testboth("%.31d", big, "0123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
84 testboth("%32.31d", big, " 0123456789012345678901234567890") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
85 |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
86 big = 0x1234567890abcdef12345L # 21 hex digits |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
87 testboth("%x", big, "1234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
88 testboth("%x", -big, "-1234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
89 testboth("%5x", -big, "-1234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
90 testboth("%22x", -big, "-1234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
91 testboth("%23x", -big, " -1234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
92 testboth("%-23x", -big, "-1234567890abcdef12345 ") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
93 testboth("%023x", -big, "-01234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
94 testboth("%-023x", -big, "-1234567890abcdef12345 ") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
95 testboth("%025x", -big, "-0001234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
96 testboth("%025x", big, "00001234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
97 testboth("%0+25x", big, "+0001234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
98 testboth("%+25x", big, " +1234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
99 testboth("%25x", big, " 1234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
100 testboth("%.2x", big, "1234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
101 testboth("%.21x", big, "1234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
102 testboth("%.22x", big, "01234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
103 testboth("%23.22x", big, " 01234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
104 testboth("%-23.22x", big, "01234567890abcdef12345 ") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
105 testboth("%X", big, "1234567890ABCDEF12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
106 testboth("%#X", big, "0X1234567890ABCDEF12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
107 testboth("%#x", big, "0x1234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
108 testboth("%#x", -big, "-0x1234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
109 testboth("%#.23x", -big, "-0x001234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
110 testboth("%#+.23x", big, "+0x001234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
111 testboth("%# .23x", big, " 0x001234567890abcdef12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
112 testboth("%#+.23X", big, "+0X001234567890ABCDEF12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
113 testboth("%#-+.23X", big, "+0X001234567890ABCDEF12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
114 testboth("%#-+26.23X", big, "+0X001234567890ABCDEF12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
115 testboth("%#-+27.23X", big, "+0X001234567890ABCDEF12345 ") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
116 testboth("%#+27.23X", big, " +0X001234567890ABCDEF12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
117 # next one gets two leading zeroes from precision, and another from the |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
118 # 0 flag and the width |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
119 testboth("%#+027.23X", big, "+0X0001234567890ABCDEF12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
120 # same, except no 0 flag |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
121 testboth("%#+27.23X", big, " +0X001234567890ABCDEF12345") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
122 |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
123 big = 012345670123456701234567012345670L # 32 octal digits |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
124 testboth("%o", big, "12345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
125 testboth("%o", -big, "-12345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
126 testboth("%5o", -big, "-12345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
127 testboth("%33o", -big, "-12345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
128 testboth("%34o", -big, " -12345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
129 testboth("%-34o", -big, "-12345670123456701234567012345670 ") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
130 testboth("%034o", -big, "-012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
131 testboth("%-034o", -big, "-12345670123456701234567012345670 ") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
132 testboth("%036o", -big, "-00012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
133 testboth("%036o", big, "000012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
134 testboth("%0+36o", big, "+00012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
135 testboth("%+36o", big, " +12345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
136 testboth("%36o", big, " 12345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
137 testboth("%.2o", big, "12345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
138 testboth("%.32o", big, "12345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
139 testboth("%.33o", big, "012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
140 testboth("%34.33o", big, " 012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
141 testboth("%-34.33o", big, "012345670123456701234567012345670 ") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
142 testboth("%o", big, "12345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
143 testboth("%#o", big, "012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
144 testboth("%#o", -big, "-012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
145 testboth("%#.34o", -big, "-0012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
146 testboth("%#+.34o", big, "+0012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
147 testboth("%# .34o", big, " 0012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
148 testboth("%#+.34o", big, "+0012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
149 testboth("%#-+.34o", big, "+0012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
150 testboth("%#-+37.34o", big, "+0012345670123456701234567012345670 ") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
151 testboth("%#+37.34o", big, " +0012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
152 # next one gets one leading zero from precision |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
153 testboth("%.33o", big, "012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
154 # base marker shouldn't change that, since "0" is redundant |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
155 testboth("%#.33o", big, "012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
156 # but reduce precision, and base marker should add a zero |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
157 testboth("%#.32o", big, "012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
158 # one leading zero from precision, and another from "0" flag & width |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
159 testboth("%034.33o", big, "0012345670123456701234567012345670") |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
160 # base marker shouldn't change that |
|
58b832b8745e
Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents:
13194
diff
changeset
|
161 testboth("%0#34.33o", big, "0012345670123456701234567012345670") |
|
15455
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
162 |
|
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
163 # Some small ints, in both Python int and long flavors). |
|
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
164 testboth("%d", 42, "42") |
|
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
165 testboth("%d", -42, "-42") |
|
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
166 testboth("%d", 42L, "42") |
|
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
167 testboth("%d", -42L, "-42") |
|
17425
8ec7f656f808
Fix for SF bug #415514: "%#x" % 0 caused assertion failure/abort.
Tim Peters <tim.peters@gmail.com>
parents:
16516
diff
changeset
|
168 testboth("%#x", 1, "0x1") |
|
8ec7f656f808
Fix for SF bug #415514: "%#x" % 0 caused assertion failure/abort.
Tim Peters <tim.peters@gmail.com>
parents:
16516
diff
changeset
|
169 testboth("%#x", 1L, "0x1") |
|
8ec7f656f808
Fix for SF bug #415514: "%#x" % 0 caused assertion failure/abort.
Tim Peters <tim.peters@gmail.com>
parents:
16516
diff
changeset
|
170 testboth("%#X", 1, "0X1") |
|
8ec7f656f808
Fix for SF bug #415514: "%#x" % 0 caused assertion failure/abort.
Tim Peters <tim.peters@gmail.com>
parents:
16516
diff
changeset
|
171 testboth("%#X", 1L, "0X1") |
|
8ec7f656f808
Fix for SF bug #415514: "%#x" % 0 caused assertion failure/abort.
Tim Peters <tim.peters@gmail.com>
parents:
16516
diff
changeset
|
172 testboth("%#o", 1, "01") |
|
8ec7f656f808
Fix for SF bug #415514: "%#x" % 0 caused assertion failure/abort.
Tim Peters <tim.peters@gmail.com>
parents:
16516
diff
changeset
|
173 testboth("%#o", 1L, "01") |
|
8ec7f656f808
Fix for SF bug #415514: "%#x" % 0 caused assertion failure/abort.
Tim Peters <tim.peters@gmail.com>
parents:
16516
diff
changeset
|
174 testboth("%#o", 0, "0") |
|
8ec7f656f808
Fix for SF bug #415514: "%#x" % 0 caused assertion failure/abort.
Tim Peters <tim.peters@gmail.com>
parents:
16516
diff
changeset
|
175 testboth("%#o", 0L, "0") |
|
8ec7f656f808
Fix for SF bug #415514: "%#x" % 0 caused assertion failure/abort.
Tim Peters <tim.peters@gmail.com>
parents:
16516
diff
changeset
|
176 testboth("%o", 0, "0") |
|
8ec7f656f808
Fix for SF bug #415514: "%#x" % 0 caused assertion failure/abort.
Tim Peters <tim.peters@gmail.com>
parents:
16516
diff
changeset
|
177 testboth("%o", 0L, "0") |
|
8ec7f656f808
Fix for SF bug #415514: "%#x" % 0 caused assertion failure/abort.
Tim Peters <tim.peters@gmail.com>
parents:
16516
diff
changeset
|
178 testboth("%d", 0, "0") |
|
8ec7f656f808
Fix for SF bug #415514: "%#x" % 0 caused assertion failure/abort.
Tim Peters <tim.peters@gmail.com>
parents:
16516
diff
changeset
|
179 testboth("%d", 0L, "0") |
|
17450
f74f5aafdc7e
Bug 415514 reported that e.g.
Tim Peters <tim.peters@gmail.com>
parents:
17425
diff
changeset
|
180 testboth("%#x", 0, "0x0") |
|
f74f5aafdc7e
Bug 415514 reported that e.g.
Tim Peters <tim.peters@gmail.com>
parents:
17425
diff
changeset
|
181 testboth("%#x", 0L, "0x0") |
|
f74f5aafdc7e
Bug 415514 reported that e.g.
Tim Peters <tim.peters@gmail.com>
parents:
17425
diff
changeset
|
182 testboth("%#X", 0, "0X0") |
|
f74f5aafdc7e
Bug 415514 reported that e.g.
Tim Peters <tim.peters@gmail.com>
parents:
17425
diff
changeset
|
183 testboth("%#X", 0L, "0X0") |
|
15455
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
184 |
|
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
185 testboth("%x", 0x42, "42") |
|
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
186 # testboth("%x", -0x42, "ffffffbe") # Alas, that's specific to 32-bit machines |
|
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
187 testboth("%x", 0x42L, "42") |
|
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
188 testboth("%x", -0x42L, "-42") |
|
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
189 |
|
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
190 testboth("%o", 042, "42") |
|
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
191 # testboth("%o", -042, "37777777736") # Alas, that's specific to 32-bit machines |
|
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
192 testboth("%o", 042L, "42") |
|
d0146d128897
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
Tim Peters <tim.peters@gmail.com>
parents:
14713
diff
changeset
|
193 testboth("%o", -042L, "-42") |
|
15580
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
194 |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
195 # Test exception for unknown format characters |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
196 if verbose: |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
197 print 'Testing exceptions' |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
198 |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
199 def test_exc(formatstr, args, exception, excmsg): |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
200 try: |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
201 testformat(formatstr, args) |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
202 except exception, exc: |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
203 if str(exc) == excmsg: |
|
15966
e59b835ad89a
a bold attempt to fix things broken by MAL's verify patch: import
Fredrik Lundh <fredrik@pythonware.com>
parents:
15957
diff
changeset
|
204 if verbose: |
|
15580
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
205 print "yes" |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
206 else: |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
207 if verbose: print 'no' |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
208 print 'Unexpected ', exception, ':', repr(str(exc)) |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
209 except: |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
210 if verbose: print 'no' |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
211 print 'Unexpected exception' |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
212 raise |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
213 |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
214 test_exc('abc %a', 1, ValueError, |
|
668166a50c70
Add test case for error message raised by bad % format character
Andrew M. Kuchling <amk@amk.ca>
parents:
15455
diff
changeset
|
215 "unsupported format character 'a' (0x61) at index 5") |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
17450
diff
changeset
|
216 if have_unicode: |
|
19354
e93f5c385ff4
Use raw-unicode-escape for the tests that require it.
Martin v. Löwis <martin@v.loewis.de>
parents:
19343
diff
changeset
|
217 test_exc(unicode('abc %\u3000','raw-unicode-escape'), 1, ValueError, |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
17450
diff
changeset
|
218 "unsupported format character '?' (0x3000) at index 5") |
