Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_b2.py @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | c00fae380dc7 |
| children | 6118ca51404d |
| rev | line source |
|---|---|
| 653 | 1 # Python test set -- part 4b, built-in functions n-z |
| 2 | |
| 3 from test_support import * | |
| 4 | |
| 5 print 'oct' | |
| 6 if oct(100) != '0144': raise TestFailed, 'oct(100)' | |
| 7 if oct(100L) != '0144L': raise TestFailed, 'oct(100L)' | |
| 8 if oct(-100) != '-0144': raise TestFailed, 'oct(-100)' | |
| 9 if oct(-100L) != '-0144L': raise TestFailed, 'oct(-100L)' | |
| 10 | |
| 11 print 'open' | |
| 12 # NB the first 4 lines are also used to test input and raw_input, below | |
| 13 fp = open(TESTFN, 'w') | |
| 14 try: | |
| 15 fp.write('1+1\n') | |
| 16 fp.write('1+1\n') | |
| 17 fp.write('The quick brown fox jumps over the lazy dog') | |
| 18 fp.write('.\n') | |
| 19 fp.write('Dear John\n') | |
| 20 fp.write('XXX'*100) | |
| 21 fp.write('YYY'*100) | |
| 22 finally: | |
| 23 fp.close() | |
| 24 # | |
| 25 fp = open(TESTFN, 'r') | |
| 26 try: | |
| 27 if fp.readline(4) <> '1+1\n': raise TestFailed, 'readline(4) # exact' | |
| 28 if fp.readline(4) <> '1+1\n': raise TestFailed, 'readline(4) # exact' | |
| 29 if fp.readline() <> 'The quick brown fox jumps over the lazy dog.\n': | |
| 30 raise TestFailed, 'readline() # default' | |
| 31 if fp.readline(4) <> 'Dear': raise TestFailed, 'readline(4) # short' | |
| 32 if fp.readline(100) <> ' John\n': raise TestFailed, 'readline(100)' | |
| 33 if fp.read(300) <> 'XXX'*100: raise TestFailed, 'read(300)' | |
| 34 if fp.read(1000) <> 'YYY'*100: raise TestFailed, 'read(1000) # truncate' | |
| 35 finally: | |
| 36 fp.close() | |
| 37 | |
| 38 print 'ord' | |
| 39 if ord(' ') <> 32: raise TestFailed, 'ord(\' \')' | |
| 40 if ord('A') <> 65: raise TestFailed, 'ord(\'A\')' | |
| 41 if ord('a') <> 97: raise TestFailed, 'ord(\'a\')' | |
| 42 | |
| 43 print 'pow' | |
| 44 if pow(0,0) <> 1: raise TestFailed, 'pow(0,0)' | |
| 45 if pow(0,1) <> 0: raise TestFailed, 'pow(0,1)' | |
| 46 if pow(1,0) <> 1: raise TestFailed, 'pow(1,0)' | |
| 47 if pow(1,1) <> 1: raise TestFailed, 'pow(1,1)' | |
| 48 # | |
| 49 if pow(2,0) <> 1: raise TestFailed, 'pow(2,0)' | |
| 50 if pow(2,10) <> 1024: raise TestFailed, 'pow(2,10)' | |
| 51 if pow(2,20) <> 1024*1024: raise TestFailed, 'pow(2,20)' | |
| 52 if pow(2,30) <> 1024*1024*1024: raise TestFailed, 'pow(2,30)' | |
| 53 # | |
| 54 if pow(-2,0) <> 1: raise TestFailed, 'pow(-2,0)' | |
| 55 if pow(-2,1) <> -2: raise TestFailed, 'pow(-2,1)' | |
| 56 if pow(-2,2) <> 4: raise TestFailed, 'pow(-2,2)' | |
| 57 if pow(-2,3) <> -8: raise TestFailed, 'pow(-2,3)' | |
| 58 # | |
| 59 if pow(0L,0) <> 1: raise TestFailed, 'pow(0L,0)' | |
| 60 if pow(0L,1) <> 0: raise TestFailed, 'pow(0L,1)' | |
| 61 if pow(1L,0) <> 1: raise TestFailed, 'pow(1L,0)' | |
| 62 if pow(1L,1) <> 1: raise TestFailed, 'pow(1L,1)' | |
| 63 # | |
| 64 if pow(2L,0) <> 1: raise TestFailed, 'pow(2L,0)' | |
| 65 if pow(2L,10) <> 1024: raise TestFailed, 'pow(2L,10)' | |
| 66 if pow(2L,20) <> 1024*1024: raise TestFailed, 'pow(2L,20)' | |
| 67 if pow(2L,30) <> 1024*1024*1024: raise TestFailed, 'pow(2L,30)' | |
| 68 # | |
| 69 if pow(-2L,0) <> 1: raise TestFailed, 'pow(-2L,0)' | |
| 70 if pow(-2L,1) <> -2: raise TestFailed, 'pow(-2L,1)' | |
| 71 if pow(-2L,2) <> 4: raise TestFailed, 'pow(-2L,2)' | |
| 72 if pow(-2L,3) <> -8: raise TestFailed, 'pow(-2L,3)' | |
| 73 # | |
|
1197
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
74 if fcmp(pow(0.,0), 1.): raise TestFailed, 'pow(0.,0)' |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
75 if fcmp(pow(0.,1), 0.): raise TestFailed, 'pow(0.,1)' |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
76 if fcmp(pow(1.,0), 1.): raise TestFailed, 'pow(1.,0)' |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
77 if fcmp(pow(1.,1), 1.): raise TestFailed, 'pow(1.,1)' |
| 653 | 78 # |
|
1197
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
79 if fcmp(pow(2.,0), 1.): raise TestFailed, 'pow(2.,0)' |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
80 if fcmp(pow(2.,10), 1024.): raise TestFailed, 'pow(2.,10)' |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
81 if fcmp(pow(2.,20), 1024.*1024.): raise TestFailed, 'pow(2.,20)' |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
82 if fcmp(pow(2.,30), 1024.*1024.*1024.): raise TestFailed, 'pow(2.,30)' |
| 653 | 83 # |
| 84 # XXX These don't work -- negative float to the float power... | |
|
1197
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
85 #if fcmp(pow(-2.,0), 1.): raise TestFailed, 'pow(-2.,0)' |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
86 #if fcmp(pow(-2.,1), -2.): raise TestFailed, 'pow(-2.,1)' |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
87 #if fcmp(pow(-2.,2), 4.): raise TestFailed, 'pow(-2.,2)' |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
88 #if fcmp(pow(-2.,3), -8.): raise TestFailed, 'pow(-2.,3)' |
|
1998
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
89 # |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
90 for x in 2, 2L, 2.0: |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
91 for y in 10, 10L, 10.0: |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
92 for z in 1000, 1000L, 1000.0: |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
93 if fcmp(pow(x, y, z), 24.0): |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
94 raise TestFailed, 'pow(%s, %s, %s)' % (x, y, z) |
| 653 | 95 |
| 96 print 'range' | |
| 97 if range(3) <> [0, 1, 2]: raise TestFailed, 'range(3)' | |
| 98 if range(1, 5) <> [1, 2, 3, 4]: raise TestFailed, 'range(1, 5)' | |
| 99 if range(0) <> []: raise TestFailed, 'range(0)' | |
| 100 if range(-3) <> []: raise TestFailed, 'range(-3)' | |
| 101 if range(1, 10, 3) <> [1, 4, 7]: raise TestFailed, 'range(1, 10, 3)' | |
| 102 if range(5, -5, -3) <> [5, 2, -1, -4]: raise TestFailed, 'range(5, -5, -3)' | |
| 103 | |
| 104 print 'input and raw_input' | |
| 105 import sys | |
| 106 fp = open(TESTFN, 'r') | |
| 107 savestdin = sys.stdin | |
| 108 try: | |
| 109 sys.stdin = fp | |
| 110 if input() <> 2: raise TestFailed, 'input()' | |
| 111 if input('testing\n') <> 2: raise TestFailed, 'input()' | |
| 112 if raw_input() <> 'The quick brown fox jumps over the lazy dog.': | |
| 113 raise TestFailed, 'raw_input()' | |
| 114 if raw_input('testing\n') <> 'Dear John': | |
| 115 raise TestFailed, 'raw_input(\'testing\\n\')' | |
| 116 finally: | |
| 117 sys.stdin = savestdin | |
| 118 fp.close() | |
| 119 | |
|
1403
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1260
diff
changeset
|
120 print 'reduce' |
|
1416
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
121 if reduce(lambda x, y: x+y, ['a', 'b', 'c'], '') <> 'abc': |
|
1403
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1260
diff
changeset
|
122 raise TestFailed, 'reduce(): implode a string' |
|
1416
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
123 if reduce(lambda x, y: x+y, |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
124 [['a', 'c'], [], ['d', 'w']], []) <> ['a','c','d','w']: |
|
1403
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1260
diff
changeset
|
125 raise TestFailed, 'reduce(): append' |
|
1416
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
126 if reduce(lambda x, y: x*y, range(2,8), 1) <> 5040: |
|
1403
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1260
diff
changeset
|
127 raise TestFailed, 'reduce(): compute 7!' |
|
1416
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
128 if reduce(lambda x, y: x*y, range(2,21), 1L) <> 2432902008176640000L: |
|
1403
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1260
diff
changeset
|
129 raise TestFailed, 'reduce(): compute 20!, use long' |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
130 class Squares: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
131 def __init__(self, max): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
132 self.max = max |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
133 self.sofar = [] |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
134 def __len__(self): return len(self.sofar) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
135 def __getitem__(self, i): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
136 if not 0 <= i < self.max: raise IndexError |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
137 n = len(self.sofar) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
138 while n <= i: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
139 self.sofar.append(n*n) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
140 n = n+1 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
141 return self.sofar[i] |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
142 if reduce(lambda x, y: x+y, Squares(10)) != 285: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
143 raise TestFailed, 'reduce(<+>, Squares(10))' |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
144 if reduce(lambda x, y: x+y, Squares(10), 0) != 285: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
145 raise TestFailed, 'reduce(<+>, Squares(10), 0)' |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
146 if reduce(lambda x, y: x+y, Squares(0), 0) != 0: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
147 raise TestFailed, 'reduce(<+>, Squares(0), 0)' |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
148 |
|
1403
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1260
diff
changeset
|
149 |
| 653 | 150 print 'reload' |
|
2046
1ce3dbeeb890
Test new __import__ module, test reload of built-in module, test
Guido van Rossum <guido@python.org>
parents:
1998
diff
changeset
|
151 import marshal |
|
1ce3dbeeb890
Test new __import__ module, test reload of built-in module, test
Guido van Rossum <guido@python.org>
parents:
1998
diff
changeset
|
152 reload(marshal) |
| 653 | 153 import string |
| 154 reload(string) | |
|
1998
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
155 import sys |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
156 try: reload(sys) |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
157 except ImportError: pass |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
158 else: raise TestFailed, 'reload(sys) should fail' |
| 653 | 159 |
|
1097
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
160 print 'repr' |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
161 if repr('') <> '\'\'': raise TestFailed, 'repr(\'\')' |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
162 if repr(0) <> '0': raise TestFailed, 'repr(0)' |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
163 if repr(0L) <> '0L': raise TestFailed, 'repr(0L)' |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
164 if repr(()) <> '()': raise TestFailed, 'repr(())' |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
165 if repr([]) <> '[]': raise TestFailed, 'repr([])' |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
166 if repr({}) <> '{}': raise TestFailed, 'repr({})' |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
167 |
|
1260
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
168 print 'round' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
169 if round(0.0) <> 0.0: raise TestFailed, 'round(0.0)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
170 if round(1.0) <> 1.0: raise TestFailed, 'round(1.0)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
171 if round(10.0) <> 10.0: raise TestFailed, 'round(10.0)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
172 if round(1000000000.0) <> 1000000000.0: |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
173 raise TestFailed, 'round(1000000000.0)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
174 if round(1e20) <> 1e20: raise TestFailed, 'round(1e20)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
175 |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
176 if round(-1.0) <> -1.0: raise TestFailed, 'round(-1.0)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
177 if round(-10.0) <> -10.0: raise TestFailed, 'round(-10.0)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
178 if round(-1000000000.0) <> -1000000000.0: |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
179 raise TestFailed, 'round(-1000000000.0)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
180 if round(-1e20) <> -1e20: raise TestFailed, 'round(-1e20)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
181 |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
182 if round(0.1) <> 0.0: raise TestFailed, 'round(0.0)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
183 if round(1.1) <> 1.0: raise TestFailed, 'round(1.0)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
184 if round(10.1) <> 10.0: raise TestFailed, 'round(10.0)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
185 if round(1000000000.1) <> 1000000000.0: |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
186 raise TestFailed, 'round(1000000000.0)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
187 |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
188 if round(-1.1) <> -1.0: raise TestFailed, 'round(-1.0)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
189 if round(-10.1) <> -10.0: raise TestFailed, 'round(-10.0)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
190 if round(-1000000000.1) <> -1000000000.0: |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
191 raise TestFailed, 'round(-1000000000.0)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
192 |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
193 if round(0.9) <> 1.0: raise TestFailed, 'round(0.9)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
194 if round(9.9) <> 10.0: raise TestFailed, 'round(9.9)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
195 if round(999999999.9) <> 1000000000.0: |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
196 raise TestFailed, 'round(999999999.9)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
197 |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
198 if round(-0.9) <> -1.0: raise TestFailed, 'round(-0.9)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
199 if round(-9.9) <> -10.0: raise TestFailed, 'round(-9.9)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
200 if round(-999999999.9) <> -1000000000.0: |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
201 raise TestFailed, 'round(-999999999.9)' |
|
b120cdd30fbc
* Fix bug in tzparse.py for DST timezone
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
202 |
| 653 | 203 print 'setattr' |
| 204 import sys | |
|
1998
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
205 setattr(sys, 'spam', 1) |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
206 if sys.spam != 1: raise TestFailed, 'setattr(sys, \'spam\', 1)' |
| 653 | 207 |
|
1097
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
208 print 'str' |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
209 if str('') <> '': raise TestFailed, 'str(\'\')' |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
210 if str(0) <> '0': raise TestFailed, 'str(0)' |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
211 if str(0L) <> '0L': raise TestFailed, 'str(0L)' |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
212 if str(()) <> '()': raise TestFailed, 'str(())' |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
213 if str([]) <> '[]': raise TestFailed, 'str([])' |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
214 if str({}) <> '{}': raise TestFailed, 'str({})' |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
215 |
|
1998
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
216 print 'tuple' |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
217 if tuple(()) <> (): raise TestFailed, 'tuple(())' |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
218 if tuple((0, 1, 2, 3)) <> (0, 1, 2, 3): raise TestFailed, 'tuple((0, 1, 2, 3))' |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
219 if tuple([]) <> (): raise TestFailed, 'tuple([])' |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
220 if tuple([0, 1, 2, 3]) <> (0, 1, 2, 3): raise TestFailed, 'tuple([0, 1, 2, 3])' |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
221 if tuple('') <> (): raise TestFailed, 'tuple('')' |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
222 if tuple('spam') <> ('s', 'p', 'a', 'm'): raise TestFailed, "tuple('spam')" |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
223 |
| 653 | 224 print 'type' |
| 225 if type('') <> type('123') or type('') == type(()): | |
| 226 raise TestFailed, 'type()' | |
| 227 | |
|
1998
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
228 print 'vars' |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
229 a = b = None |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
230 a = vars().keys() |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
231 b = dir() |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
232 a.sort() |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
233 b.sort() |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
234 if a <> b: raise TestFailed, 'vars()' |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
235 import sys |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
236 a = vars(sys).keys() |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
237 b = dir(sys) |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
238 a.sort() |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
239 b.sort() |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
240 if a <> b: raise TestFailed, 'vars(sys)' |
|
2969
c00fae380dc7
test for specific bug in vars()
Guido van Rossum <guido@python.org>
parents:
2046
diff
changeset
|
241 def f0(): |
|
c00fae380dc7
test for specific bug in vars()
Guido van Rossum <guido@python.org>
parents:
2046
diff
changeset
|
242 if vars() != {}: raise TestFailed, 'vars() in f0()' |
|
c00fae380dc7
test for specific bug in vars()
Guido van Rossum <guido@python.org>
parents:
2046
diff
changeset
|
243 f0() |
|
c00fae380dc7
test for specific bug in vars()
Guido van Rossum <guido@python.org>
parents:
2046
diff
changeset
|
244 def f2(): |
|
c00fae380dc7
test for specific bug in vars()
Guido van Rossum <guido@python.org>
parents:
2046
diff
changeset
|
245 f0() |
|
c00fae380dc7
test for specific bug in vars()
Guido van Rossum <guido@python.org>
parents:
2046
diff
changeset
|
246 a = 1 |
|
c00fae380dc7
test for specific bug in vars()
Guido van Rossum <guido@python.org>
parents:
2046
diff
changeset
|
247 b = 2 |
|
c00fae380dc7
test for specific bug in vars()
Guido van Rossum <guido@python.org>
parents:
2046
diff
changeset
|
248 if vars() != {'a': a, 'b': b}: raise TestFailed, 'vars() in f2()' |
|
c00fae380dc7
test for specific bug in vars()
Guido van Rossum <guido@python.org>
parents:
2046
diff
changeset
|
249 f2() |
|
1998
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
250 |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
251 print 'xrange' |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
252 if tuple(xrange(10)) <> tuple(range(10)): raise TestFailed, 'xrange(10)' |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
253 if tuple(xrange(5,10)) <> tuple(range(5,10)): raise TestFailed, 'xrange(5,10)' |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
254 if tuple(xrange(0,10,2)) <> tuple(range(0,10,2)): |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
255 raise TestFailed, 'xrange(0,10,2)' |
|
cf4d8862f19b
more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
256 |
| 653 | 257 |
| 258 # Epilogue -- unlink the temp file | |
| 259 | |
| 260 unlink(TESTFN) |
