Repository navigation
Expand file tree
/
Copy pathtest_help.py
More file actions
481 lines (381 loc) · 12.2 KB
/
Copy pathtest_help.py
File metadata and controls
481 lines (381 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
#####################################################################################
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# This source code is subject to terms and conditions of the Apache License, Version 2.0. A
# copy of the license can be found in the License.html file at the root of this distribution. If
# you cannot locate the Apache License, Version 2.0, please send an email to
# [email protected]. By using this source code in any fashion, you are agreeing to be bound
# by the terms of the Apache License, Version 2.0.
#
# You must not remove this notice, or any other, from this software.
#
#
#####################################################################################
from iptest.assert_util import *
import sys
class stdout_reader:
def __init__(self):
self.text = ''
def write(self, text):
self.text += text
@skip('win32')
def test_z_cli_tests(): # runs last to prevent tainting the module w/ CLR names
import clr
import System
load_iron_python_test()
from IronPythonTest import WriteOnly
sys.stdout = stdout_reader()
help(WriteOnly)
if is_silverlight==False:
help(System.IO.Compression)
help(System.Int64)
sys.stdout = sys.__stdout__
sys.stdout = stdout_reader()
help(System.String.Format)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('Format(format: str, arg0: object) -> str') != -1)
sys.stdout = stdout_reader()
help('u.u'.Split('u'))
x = sys.stdout.text
sys.stdout = sys.__stdout__
if not is_silverlight:
# requires std lib
Assert('Help on Array[str] object' in x)
if not is_net40: #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=24508
Assert('Clear(...)' in x)
#http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=4190
from System.IO import MemoryStream
try:
sys.stdout = stdout_reader()
help(MemoryStream.Write)
x_class = sys.stdout.text
finally:
sys.stdout = sys.__stdout__
try:
sys.stdout = stdout_reader()
help(MemoryStream().Write)
x_instance = sys.stdout.text
finally:
sys.stdout = sys.__stdout__
if not is_silverlight:
AreEqual(x_class, x_instance.replace("built-in function Write", "method_descriptor"))
else:
AreEqual(x_class.replace(" |", "|"),
x_instance.replace("built-in function", "method-descriptor").replace(" |", "|"))
#http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=11883
AreEqual(dir(System).count('Action'), 1)
try:
sys.stdout = stdout_reader()
help(System.Action)
finally:
sys.stdout = sys.__stdout__
AreEqual(dir(System).count('Action'), 1)
def test_module():
import time
sys.stdout = stdout_reader()
help(time)
x = sys.stdout.text
sys.stdout = sys.__stdout__
if is_silverlight==False:
Assert(x.find('clock(...)') != -1) # should have help for our stuff
Assert(x.find('unichr(...)') == -1) # shouldn't have bulit-in help
Assert(x.find('AscTime') == -1) # shouldn't display CLI names
Assert(x.find('static') == -1) # methods shouldn't be displayed as static
def test_userfunction():
def foo():
"""my help is useful"""
sys.stdout = stdout_reader()
help(foo)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('my help is useful') != -1)
def test_splat():
def foo(*args): pass
sys.stdout = stdout_reader()
help(foo)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('foo(*args)') != -1)
if not is_silverlight:
Assert(x.find('Help on function foo in module __main__:') != -1)
def foo(**kwargs): pass
sys.stdout = stdout_reader()
help(foo)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('foo(**kwargs)') != -1)
def foo(*args, **kwargs): pass
sys.stdout = stdout_reader()
help(foo)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('foo(*args, **kwargs)') != -1)
def foo(a, *args): pass
sys.stdout = stdout_reader()
help(foo)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('foo(a, *args)') != -1)
def foo(a, *args, **kwargs): pass
sys.stdout = stdout_reader()
help(foo)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('foo(a, *args, **kwargs)') != -1)
def foo(a=7): pass
sys.stdout = stdout_reader()
help(foo)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('foo(a=7') != -1)
def foo(a=[3]): a.append(7)
sys.stdout = stdout_reader()
help(foo)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('foo(a=[3]') != -1)
foo()
sys.stdout = stdout_reader()
help(foo)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('foo(a=[3, 7]') != -1)
def test_builtinfunction():
sys.stdout = stdout_reader()
help(abs)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('Return the absolute value of the argument') != -1)
def test_user_class():
class foo(object):
"""this documentation is going to make the world a better place"""
sys.stdout = stdout_reader()
class TClass(object):
'''
Some TClass doc...
'''
def __init__(self, p1, *args, **argkw):
'''
Some constructor doc...
p1 does something
args does something
argkw does something
'''
self.member = 1
def plainMethod(self):
'''
Doc here
'''
pass
def plainMethodEmpty(self):
'''
'''
pass
def plainMethodNone(self):
pass
help(foo)
#sanity checks. just make sure no execeptions
#are thrown
help(TClass)
help(TClass.__init__)
help(TClass.plainMethod)
help(TClass.plainMethodEmpty)
help(TClass.plainMethodNone)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('this documentation is going to make the world a better place') != -1)
def test_methoddescriptor():
sys.stdout = stdout_reader()
help(list.append)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('append(...)') != -1)
def test_oldstyle_class():
class foo:
"""the slow lazy fox jumped over the quick brown dog..."""
sys.stdout = stdout_reader()
help(foo)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('the slow lazy fox jumped over the quick brown dog...') != -1)
def test_nodoc():
sys.stdout = stdout_reader()
class foo(object): pass
help(foo)
sys.stdout = sys.__stdout__
sys.stdout = stdout_reader()
class foo: pass
help(foo)
sys.stdout = sys.__stdout__
sys.stdout = stdout_reader()
def foo(): pass
help(foo)
sys.stdout = sys.__stdout__
def test_help_instance():
class foo(object):
"""my documentation"""
a = foo()
sys.stdout = stdout_reader()
help(a)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('my documentation') != -1)
def test_str():
sys.stdout = stdout_reader()
help('abs')
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find('Return the absolute value of the argument.') != -1)
def run_help(o):
sys.stdout = stdout_reader()
help(o)
x = sys.stdout.text
sys.stdout = sys.__stdout__
return x
def test_user_function():
def f(): pass
out = run_help(f)
Assert(out.find('f()') != -1)
if is_silverlight==False:
Assert(out.find('in module __main__:') != -1)
# list
def f(*args): pass
out = run_help(f)
Assert(out.find('f(*args)') != -1)
# kw dict
def f(**kw): pass
out = run_help(f)
Assert(out.find('f(**kw)') != -1)
# list & kw dict
def f(*args, **kwargs): pass
out = run_help(f)
Assert(out.find('f(*args, **kwargs)') != -1)
# default
def f(abc = 3): pass
out = run_help(f)
Assert(out.find('f(abc=3)') != -1)
# mutating default value
def f(a = [42]):
a.append(23)
out = run_help(f)
Assert(out.find('f(a=[42])') != -1)
f()
out = run_help(f)
Assert(out.find('f(a=[42, 23])') != -1)
# str vs repr
class foo(object):
def __repr__(self): return 'abc'
def __str__(self): return 'def'
def f(a = foo()): pass
out = run_help(f)
Assert(out.find('f(a=abc)') != -1)
def test_user_method():
class x:
def f(): pass
out = run_help(x.f)
Assert(out.find('f()') != -1)
if is_silverlight==False:
Assert(out.find('in module __main__:') != -1)
# list
class x:
def f(*args): pass
out = run_help(x.f)
Assert(out.find('f(*args)') != -1)
# kw dict
class x:
def f(**kw): pass
out = run_help(x.f)
Assert(out.find('f(**kw)') != -1)
# list & kw dict
class x:
def f(*args, **kwargs): pass
out = run_help(x.f)
Assert(out.find('f(*args, **kwargs)') != -1)
# default
class x:
def f(abc = 3): pass
out = run_help(x.f)
Assert(out.find('f(abc=3)') != -1)
# str vs repr
class foo(object):
def __repr__(self): return 'abc'
def __str__(self): return 'def'
class x:
def f(a = foo()): pass
out = run_help(x.f)
Assert(out.find('f(a=abc)') != -1)
if is_silverlight==False:
Assert(out.find('unbound __main__.x method') != -1)
def test_bound_user_method():
class x:
def f(): pass
out = run_help(x().f)
Assert(out.find('f()') != -1)
if is_silverlight==False:
Assert(out.find('in module __main__:') != -1)
# list
class x:
def f(*args): pass
out = run_help(x().f)
Assert(out.find('f(*args)') != -1)
# kw dict
class x:
def f(**kw): pass
out = run_help(x().f)
Assert(out.find('f(**kw)') != -1)
# list & kw dict
class x:
def f(*args, **kwargs): pass
out = run_help(x().f)
Assert(out.find('f(*args, **kwargs)') != -1)
# default
class x:
def f(abc = 3): pass
out = run_help(x().f)
Assert(out.find('f(abc=3)') != -1)
# str vs repr
class foo(object):
def __repr__(self): return 'abc'
def __str__(self): return 'def'
class x:
def f(a = foo()): pass
out = run_help(x().f)
Assert(out.find('f(a=abc)') != -1)
if is_silverlight==False:
Assert(out.find('method of __main__.x instance') != -1)
@skip("stdlib") #CodePlex 17577
def test_bound_builtin_func():
x = []
out = run_help(x.append)
Assert(out.find('Help on built-in function append') != -1)
if is_cli: # Cpython and IronPython display different help
Assert(out.find('append(self: ') != -1)
@skip("win32")
def test_clr_addreference():
sys.stdout = stdout_reader()
help(clr.AddReference)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert(x.find("Adds a reference to a .NET assembly.") != -1)
@skip("win32", "silverlight", "cli64")
def test_paramrefs():
# System.DateTime.Parse (for example) has a paramrefs in its help text which get substitued
# by paramnames.
import System
x = run_help(System.DateTime.Parse)
Assert(x.find("equivalent to the date and time contained in s") != -1)
@skip("silverlight") #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=20236#
def test_type():
sys.stdout = stdout_reader()
help(type)
x = sys.stdout.text
sys.stdout = sys.__stdout__
Assert("CodeContext" not in x)
Assert(x.count("type(") > 1)
def test_builtinfunc_module():
AreEqual([].append.__module__, None)
AreEqual(min.__module__, '__builtin__')
#--MAIN------------------------------------------------------------------------
run_test(__name__)