1
- -- Test cases for type checking mypy programs using full stubs and running
2
- -- using CPython (Python 2 mode).
1
+ -- Test cases for type checking mypy programs using full stubs
3
2
--
4
3
-- These are mostly regression tests -- no attempt is made to make these
5
4
-- complete.
@@ -22,46 +21,32 @@ print x
22
21
x = u'foo'
23
22
print repr(x)
24
23
[out]
25
- xyz
26
- u'foo'
27
24
28
25
[case testXrangeAndRange_python2]
29
26
for i in xrange(2):
30
27
print i
31
28
for i in range(3):
32
29
print i
33
30
[out]
34
- 0
35
- 1
36
- 0
37
- 1
38
- 2
39
31
40
32
[case testIterator_python2]
41
33
import typing, sys
42
34
x = iter('bar')
43
35
print x.next(), x.next()
44
36
[out]
45
- b a
46
37
47
38
[case testEncodeAndDecode_python2]
48
39
print 'a'.encode('latin1')
49
40
print 'b'.decode('latin1')
50
41
print u'c'.encode('latin1')
51
42
print u'd'.decode('latin1')
52
43
[out]
53
- a
54
- b
55
- c
56
- d
57
44
58
45
[case testHasKey_python2]
59
46
d = {1: 'x'}
60
47
print d.has_key(1)
61
48
print d.has_key(2)
62
49
[out]
63
- True
64
- False
65
50
66
51
[case testIntegerDivision_python2]
67
52
x = 1 / 2
@@ -86,8 +71,6 @@ def f(x): # type: (AnyStr) -> AnyStr
86
71
print f('')
87
72
print f(u'')
88
73
[out]
89
- foo
90
- zar
91
74
92
75
[case testGenericPatterns_python2]
93
76
from typing import Pattern
@@ -98,7 +81,6 @@ b = None # type: Pattern[str]
98
81
b = re.compile('foo*')
99
82
print(p.match(u'fooo').group(0))
100
83
[out]
101
- fooo
102
84
103
85
[case testGenericMatch_python2]
104
86
from typing import Match
@@ -107,26 +89,22 @@ def f(m): # type: (Match[str]) -> None
107
89
print(m.group(0))
108
90
f(re.match('x*', 'xxy'))
109
91
[out]
110
- xx
111
92
112
93
[case testVariableLengthTuple_python2]
113
94
from typing import Tuple, cast
114
95
x = cast(Tuple[int, ...], ())
115
96
print(x)
116
97
[out]
117
- ()
118
98
119
99
[case testFromFuturePrintFunction_python2]
120
100
from __future__ import print_function
121
101
print('a', 'b')
122
102
[out]
123
- a b
124
103
125
104
[case testFromFutureImportUnicodeLiterals_python2]
126
105
from __future__ import unicode_literals
127
106
print '>', ['a', b'b', u'c']
128
107
[out]
129
- > [u'a', 'b', u'c']
130
108
131
109
[case testUnicodeLiteralsKwargs_python2]
132
110
from __future__ import unicode_literals
@@ -182,7 +160,6 @@ def f(a): # type: (Sequence[T]) -> None
182
160
print a
183
161
f(tuple())
184
162
[out]
185
- ()
186
163
187
164
[case testReadOnlyProperty_python2]
188
165
import typing
@@ -192,7 +169,6 @@ class A:
192
169
return 1
193
170
print(A().foo + 2)
194
171
[out]
195
- 3
196
172
197
173
[case testIOTypes_python2]
198
174
from typing import IO, TextIO, BinaryIO, Any
@@ -219,7 +195,6 @@ if 1 == 2: # Don't want to run the code below, since it would create a file.
219
195
f.close()
220
196
print('ok')
221
197
[out]
222
- ok
223
198
224
199
[case testStringIO_python2]
225
200
import typing
@@ -228,7 +203,6 @@ c = io.StringIO()
228
203
c.write(u'\x89')
229
204
print(repr(c.getvalue()))
230
205
[out]
231
- u'\x89'
232
206
233
207
[case testBytesIO_python2]
234
208
import typing
@@ -237,7 +211,6 @@ c = io.BytesIO()
237
211
c.write('\x89')
238
212
print(repr(c.getvalue()))
239
213
[out]
240
- '\x89'
241
214
242
215
[case testTextIOWrapper_python2]
243
216
import typing
@@ -246,7 +219,6 @@ b = io.BytesIO(u'\xab'.encode('utf8'))
246
219
w = io.TextIOWrapper(b, encoding='utf8')
247
220
print(repr(w.read()))
248
221
[out]
249
- u'\xab'
250
222
251
223
[case testIoOpen_python2]
252
224
import typing
@@ -257,7 +229,6 @@ if 1 == 2: # Only type check, do not execute
257
229
f.close()
258
230
print 'ok'
259
231
[out]
260
- ok
261
232
262
233
[case testUnionType_python2]
263
234
from typing import Union
@@ -269,8 +240,6 @@ def f(x): # type: (Union[int, str]) -> str
269
240
print f(12)
270
241
print f('ab')
271
242
[out]
272
- 12
273
- ab
274
243
275
244
[case testStrAdd_python2]
276
245
import typing
@@ -301,7 +270,6 @@ X = namedtuple('X', ['a', 'b'])
301
270
x = X(a=1, b='s')
302
271
print x.a, x.b
303
272
[out]
304
- 1 s
305
273
306
274
[case testNamedTupleError_python2]
307
275
import typing
@@ -328,9 +296,6 @@ print 5 + 8j
328
296
print 3j * 2.0
329
297
print 4j / 2.0
330
298
[out]
331
- (5+8j)
332
- 6j
333
- 2j
334
299
335
300
[case testNamedTupleWithTypes_python2]
336
301
from typing import NamedTuple
@@ -341,9 +306,6 @@ a, b = n
341
306
print a, b
342
307
print n[0]
343
308
[out]
344
- N(a=1, b='x')
345
- 1 x
346
- 1
347
309
348
310
[case testUnionTypeAlias_python2]
349
311
from typing import Union
@@ -363,7 +325,6 @@ class A(object):
363
325
__metaclass__ = MyType
364
326
print(type(A()).__name__)
365
327
[out]
366
- Ax
367
328
368
329
[case testSequenceIndexAndCount_python2]
369
330
from typing import Sequence
@@ -372,8 +333,6 @@ def f(x): # type: (Sequence[int]) -> None
372
333
print(x.count(1))
373
334
f([0, 0, 1, 1, 1])
374
335
[out]
375
- 2
376
- 3
377
336
378
337
[case testOptional_python2]
379
338
from typing import Optional
@@ -419,7 +378,6 @@ class B(A):
419
378
b = B()
420
379
print b.x + 1
421
380
[out]
422
- 4
423
381
424
382
[case testReModuleBytesPython2]
425
383
# Regression tests for various overloads in the re module -- bytes version
0 commit comments