1 from test
.test_support
import verbose
, TestFailed
4 print "Testing whether compiler catches assignment to __debug__"
7 compile('__debug__ = 1', '?', 'single')
12 prev
= __builtin__
.__debug
__
13 setattr(__builtin__
, '__debug__', 'sure')
14 setattr(__builtin__
, '__debug__', prev
)
17 print 'Running tests on argument handling'
20 exec 'def f(a, a): pass'
21 raise TestFailed
, "duplicate arguments"
26 print "compiling string with syntax error"
29 compile("1+*3", "filename", "exec")
30 except SyntaxError, detail
:
31 if not detail
.filename
== "filename":
32 raise TestFailed
, "expected 'filename', got %r" % detail
.filename
35 exec 'def f(a = 0, a = 1): pass'
36 raise TestFailed
, "duplicate keyword arguments"
41 exec 'def f(a): global a; a = 1'
42 raise TestFailed
, "variable is global and local"
47 print "testing complex args"
49 def comp_args((a
, b
)):
54 def comp_args((a
, b
)=(3, 4)):
60 def comp_args(a
, (b
, c
)):
65 def comp_args(a
=2, (b
, c
)=(3, 4)):
72 exec 'def f(a=1, (b, c)): pass'
73 raise TestFailed
, "non-default args after default"
78 print "testing bad float literals"
83 raise TestFailed("%r accepted" % s
)
90 expect_error("3-4e/21")
93 print "testing compile() of indented block w/o trailing newline"
99 compile(s
, "<string>", "exec")
103 print "testing literals with leading zeroes"
105 def expect_same(test_source
, expected
):
106 got
= eval(test_source
)
108 raise TestFailed("eval(%r) gave %r, but expected %r" %
109 (test_source
, got
, expected
))
111 expect_error("077787")
115 expect_same("0777", 511)
116 expect_same("0777L", 511)
117 expect_same("000777", 511)
118 expect_same("0xff", 255)
119 expect_same("0xffL", 255)
120 expect_same("0XfF", 255)
121 expect_same("0777.", 777)
122 expect_same("0777.0", 777)
123 expect_same("000000000000000000000000000000000000000000000000000777e0", 777)
124 expect_same("0777e1", 7770)
125 expect_same("0e0", 0)
126 expect_same("0000E-012", 0)
127 expect_same("09.5", 9.5)
128 expect_same("0777j", 777j
)
129 expect_same("00j", 0j
)
130 expect_same("00.0", 0)
131 expect_same("0e3", 0)
132 expect_same("090000000000000.", 90000000000000.)
133 expect_same("090000000000000.0000000000000000000000", 90000000000000.)
134 expect_same("090000000000000e0", 90000000000000.)
135 expect_same("090000000000000e-0", 90000000000000.)
136 expect_same("090000000000000j", 90000000000000j
)
137 expect_error("090000000000000") # plain octal literal w/ decimal digit
138 expect_error("080000000000000") # plain octal literal w/ decimal digit
139 expect_error("000000000000009") # plain octal literal w/ decimal digit
140 expect_error("000000000000008") # plain octal literal w/ decimal digit
141 expect_same("000000000000007", 7)
142 expect_same("000000000000008.", 8.)
143 expect_same("000000000000009.", 9.)
145 # Verify treatment of unary minus on negative numbers SF bug #660455
147 warnings
.filterwarnings("ignore", "hex/oct constants", FutureWarning
)
148 warnings
.filterwarnings("ignore", "hex.* of negative int", FutureWarning
)
149 # XXX Of course the following test will have to be changed in Python 2.4
150 # This test is in a <string> so the filterwarnings() can affect it
152 all_one_bits
= '0xffffffff'
153 if sys
.maxint
!= 2147483647:
154 all_one_bits
= '0xffffffffffffffff'
156 expect_same(all_one_bits, -1)
157 expect_same("-" + all_one_bits, 1)