FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet-rawsvnmig/pythonnet/src/tests/test_method.py at master · pythonnet/pythonnet-rawsvnmig · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Jun 4, 2019. It is now read-only.
pythonnet
/
pythonnet-rawsvnmig
Public archive
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet-rawsvnmig
/
pythonnet
/
src
/
tests
/
test_method.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
778 lines (568 loc) · 26.1 KB
Breadcrumbs
pythonnet-rawsvnmig
/
pythonnet
/
src
/
tests
/
test_method.py
Copy path
File metadata and controls
778 lines (568 loc) · 26.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
# ===========================================================================
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# ===========================================================================
import
sys
,
os
,
string
,
unittest
,
types
import
clr
clr
.
AddReference
(
"Python.Test"
)
from
Python
.
Test
import
MethodTest
,
MethodTestSub
import
System
class
MethodTests
(
unittest
.
TestCase
):
"""Test CLR method support."""
def
testInstanceMethodDescriptor
(
self
):
"""Test instance method descriptor behavior."""
def
test
():
MethodTest
().
PublicMethod
=
0
self
.
assertRaises
(
AttributeError
,
test
)
def
test
():
MethodTest
.
PublicMethod
=
0
self
.
assertRaises
(
AttributeError
,
test
)
def
test
():
del
MethodTest
().
PublicMethod
self
.
assertRaises
(
AttributeError
,
test
)
def
test
():
del
MethodTest
.
PublicMethod
self
.
assertRaises
(
AttributeError
,
test
)
def
testStaticMethodDescriptor
(
self
):
"""Test static method descriptor behavior."""
def
test
():
MethodTest
().
PublicStaticMethod
=
0
self
.
assertRaises
(
AttributeError
,
test
)
def
test
():
MethodTest
.
PublicStaticMethod
=
0
self
.
assertRaises
(
AttributeError
,
test
)
def
test
():
del
MethodTest
().
PublicStaticMethod
self
.
assertRaises
(
AttributeError
,
test
)
def
test
():
del
MethodTest
.
PublicStaticMethod
self
.
assertRaises
(
AttributeError
,
test
)
def
testPublicInstanceMethod
(
self
):
"""Test public instance method visibility."""
object
=
MethodTest
();
self
.
assertTrue
(
object
.
PublicMethod
()
==
"public"
)
def
testPublicStaticMethod
(
self
):
"""Test public static method visibility."""
object
=
MethodTest
();
self
.
assertTrue
(
MethodTest
.
PublicStaticMethod
()
==
"public static"
)
self
.
assertTrue
(
object
.
PublicStaticMethod
()
==
"public static"
)
def
testProtectedInstanceMethod
(
self
):
"""Test protected instance method visibility."""
object
=
MethodTest
();
self
.
assertTrue
(
object
.
ProtectedMethod
()
==
"protected"
)
def
testProtectedStaticMethod
(
self
):
"""Test protected static method visibility."""
object
=
MethodTest
();
result
=
"protected static"
self
.
assertTrue
(
MethodTest
.
ProtectedStaticMethod
()
==
result
)
self
.
assertTrue
(
object
.
ProtectedStaticMethod
()
==
result
)
def
testInternalMethod
(
self
):
"""Test internal method visibility."""
def
test
():
f
=
MethodTest
().
InternalMethod
self
.
assertRaises
(
AttributeError
,
test
)
def
test
():
f
=
MethodTest
.
InternalMethod
self
.
assertRaises
(
AttributeError
,
test
)
def
test
():
f
=
MethodTest
().
InternalStaticMethod
self
.
assertRaises
(
AttributeError
,
test
)
def
test
():
f
=
MethodTest
.
InternalStaticMethod
self
.
assertRaises
(
AttributeError
,
test
)
def
testPrivateMethod
(
self
):
"""Test private method visibility."""
def
test
():
f
=
MethodTest
().
PrivateMethod
self
.
assertRaises
(
AttributeError
,
test
)
def
test
():
f
=
MethodTest
.
PrivateMethod
self
.
assertRaises
(
AttributeError
,
test
)
def
test
():
f
=
MethodTest
().
PrivateStaticMethod
self
.
assertRaises
(
AttributeError
,
test
)
def
test
():
f
=
MethodTest
.
PrivateStaticMethod
self
.
assertRaises
(
AttributeError
,
test
)
def
testUnboundManagedMethodCall
(
self
):
"""Test calling unbound managed methods."""
object
=
MethodTest
()
self
.
assertTrue
(
MethodTest
.
PublicMethod
(
object
)
==
"public"
)
def
test
():
MethodTest
.
PublicMethod
()
self
.
assertRaises
(
TypeError
,
test
)
object
=
MethodTestSub
();
self
.
assertTrue
(
MethodTestSub
.
PublicMethod
(
object
)
==
"public"
)
self
.
assertTrue
(
MethodTestSub
.
PublicMethod
(
object
,
"echo"
)
==
"echo"
)
def
test
():
MethodTestSub
.
PublicMethod
(
"echo"
)
self
.
assertRaises
(
TypeError
,
test
)
def
testOverloadedMethodInheritance
(
self
):
"""Test that overloads are inherited properly."""
object
=
MethodTest
()
self
.
assertTrue
(
object
.
PublicMethod
()
==
"public"
)
def
test
():
object
=
MethodTest
()
object
.
PublicMethod
(
"echo"
)
self
.
assertRaises
(
TypeError
,
test
)
object
=
MethodTestSub
();
self
.
assertTrue
(
object
.
PublicMethod
()
==
"public"
)
self
.
assertTrue
(
object
.
PublicMethod
(
"echo"
)
==
"echo"
)
def
testMethodDescriptorAbuse
(
self
):
"""Test method descriptor abuse."""
desc
=
MethodTest
.
__dict__
[
'PublicMethod'
]
def
test
():
desc
.
__get__
(
0
,
0
)
self
.
assertRaises
(
TypeError
,
test
)
def
test
():
desc
.
__set__
(
0
,
0
)
self
.
assertRaises
(
AttributeError
,
test
)
def
testMethodDocstrings
(
self
):
"""Test standard method docstring generation"""
method
=
MethodTest
.
GetType
value
=
'System.Type GetType()'
self
.
assertTrue
(
method
.
__doc__
==
value
)
#======================================================================
# Tests of specific argument and result conversion scenarios
#======================================================================
def
testMethodCallEnumConversion
(
self
):
"""Test enum conversion in method call."""
from
System
import
TypeCode
object
=
MethodTest
()
r
=
object
.
TestEnumConversion
(
TypeCode
.
Int32
)
self
.
assertTrue
(
r
==
TypeCode
.
Int32
)
def
testMethodCallFlagsConversion
(
self
):
"""Test flags conversion in method call."""
from
System
.
IO
import
FileAccess
object
=
MethodTest
()
flags
=
FileAccess
.
Read
|
FileAccess
.
Write
r
=
object
.
TestFlagsConversion
(
flags
)
self
.
assertTrue
(
r
==
flags
)
def
testMethodCallStructConversion
(
self
):
"""Test struct conversion in method call."""
from
System
import
Guid
object
=
MethodTest
()
guid
=
Guid
.
NewGuid
()
temp
=
guid
.
ToString
()
r
=
object
.
TestStructConversion
(
guid
)
self
.
assertTrue
(
r
.
ToString
()
==
temp
)
def
testSubclassInstanceConversion
(
self
):
"""Test subclass instance conversion in method call."""
clr
.
AddReference
(
"System.Windows.Forms"
)
from
System
.
Windows
.
Forms
import
Form
,
Control
class
sub
(
Form
):
pass
object
=
MethodTest
()
form
=
sub
()
result
=
object
.
TestSubclassConversion
(
form
)
self
.
assertTrue
(
isinstance
(
result
,
Control
))
def
testNullArrayConversion
(
self
):
"""Test null array conversion in method call."""
from
System
import
Type
object
=
MethodTest
()
r
=
object
.
TestNullArrayConversion
(
None
)
self
.
assertTrue
(
r
==
None
)
def
testStringParamsArgs
(
self
):
"""Test use of string params."""
result
=
MethodTest
.
TestStringParamsArg
(
'one'
,
'two'
,
'three'
)
self
.
assertEqual
(
result
.
Length
,
3
)
self
.
assertEqual
(
len
(
result
),
3
,
result
)
self
.
assertTrue
(
result
[
0
]
==
'one'
)
self
.
assertTrue
(
result
[
1
]
==
'two'
)
self
.
assertTrue
(
result
[
2
]
==
'three'
)
result
=
MethodTest
.
TestStringParamsArg
([
'one'
,
'two'
,
'three'
])
self
.
assertTrue
(
len
(
result
)
==
3
)
self
.
assertTrue
(
result
[
0
]
==
'one'
)
self
.
assertTrue
(
result
[
1
]
==
'two'
)
self
.
assertTrue
(
result
[
2
]
==
'three'
)
def
testObjectParamsArgs
(
self
):
"""Test use of object params."""
result
=
MethodTest
.
TestObjectParamsArg
(
'one'
,
'two'
,
'three'
)
self
.
assertEqual
(
len
(
result
),
3
,
result
)
self
.
assertTrue
(
result
[
0
]
==
'one'
)
self
.
assertTrue
(
result
[
1
]
==
'two'
)
self
.
assertTrue
(
result
[
2
]
==
'three'
)
result
=
MethodTest
.
TestObjectParamsArg
([
'one'
,
'two'
,
'three'
])
self
.
assertEqual
(
len
(
result
),
3
,
result
)
self
.
assertTrue
(
result
[
0
]
==
'one'
)
self
.
assertTrue
(
result
[
1
]
==
'two'
)
self
.
assertTrue
(
result
[
2
]
==
'three'
)
def
testValueParamsArgs
(
self
):
"""Test use of value type params."""
result
=
MethodTest
.
TestValueParamsArg
(
1
,
2
,
3
)
self
.
assertEqual
(
len
(
result
),
3
)
self
.
assertTrue
(
result
[
0
]
==
1
)
self
.
assertTrue
(
result
[
1
]
==
2
)
self
.
assertTrue
(
result
[
2
]
==
3
)
result
=
MethodTest
.
TestValueParamsArg
([
1
,
2
,
3
])
self
.
assertEqual
(
len
(
result
),
3
)
self
.
assertTrue
(
result
[
0
]
==
1
)
self
.
assertTrue
(
result
[
1
]
==
2
)
self
.
assertTrue
(
result
[
2
]
==
3
)
def
testStringOutParams
(
self
):
"""Test use of string out-parameters."""
result
=
MethodTest
.
TestStringOutParams
(
"hi"
,
"there"
)
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertEqual
(
len
(
result
),
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
result
[
1
]
==
"output string"
)
result
=
MethodTest
.
TestStringOutParams
(
"hi"
,
None
)
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertEqual
(
len
(
result
),
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
result
[
1
]
==
"output string"
)
def
testStringRefParams
(
self
):
"""Test use of string byref parameters."""
result
=
MethodTest
.
TestStringRefParams
(
"hi"
,
"there"
)
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertEqual
(
len
(
result
),
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
result
[
1
]
==
"output string"
)
result
=
MethodTest
.
TestStringRefParams
(
"hi"
,
None
)
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertEqual
(
len
(
result
),
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
result
[
1
]
==
"output string"
)
def
testValueOutParams
(
self
):
"""Test use of value type out-parameters."""
result
=
MethodTest
.
TestValueOutParams
(
"hi"
,
1
)
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertEqual
(
len
(
result
),
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
result
[
1
]
==
42
)
def
test
():
MethodTest
.
TestValueOutParams
(
"hi"
,
None
)
# None cannot be converted to a value type like int, long, etc.
self
.
assertRaises
(
TypeError
,
test
)
def
testValueRefParams
(
self
):
"""Test use of value type byref parameters."""
result
=
MethodTest
.
TestValueRefParams
(
"hi"
,
1
)
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertEqual
(
len
(
result
),
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
result
[
1
]
==
42
)
def
test
():
MethodTest
.
TestValueRefParams
(
"hi"
,
None
)
# None cannot be converted to a value type like int, long, etc.
self
.
assertRaises
(
TypeError
,
test
)
def
testObjectOutParams
(
self
):
"""Test use of object out-parameters."""
result
=
MethodTest
.
TestObjectOutParams
(
"hi"
,
MethodTest
())
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertTrue
(
len
(
result
)
==
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
isinstance
(
result
[
1
],
System
.
Exception
))
result
=
MethodTest
.
TestObjectOutParams
(
"hi"
,
None
)
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertEqual
(
len
(
result
),
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
isinstance
(
result
[
1
],
System
.
Exception
))
def
testObjectRefParams
(
self
):
"""Test use of object byref parameters."""
result
=
MethodTest
.
TestObjectRefParams
(
"hi"
,
MethodTest
())
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertEqual
(
len
(
result
),
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
isinstance
(
result
[
1
],
System
.
Exception
))
result
=
MethodTest
.
TestObjectRefParams
(
"hi"
,
None
)
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertEqual
(
len
(
result
),
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
isinstance
(
result
[
1
],
System
.
Exception
))
def
testStructOutParams
(
self
):
"""Test use of struct out-parameters."""
result
=
MethodTest
.
TestStructOutParams
(
"hi"
,
System
.
Guid
.
NewGuid
())
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertEqual
(
len
(
result
),
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
isinstance
(
result
[
1
],
System
.
Guid
))
def
test
():
MethodTest
.
TestValueRefParams
(
"hi"
,
None
)
# None cannot be converted to a value type like a struct
self
.
assertRaises
(
TypeError
,
test
)
def
testStructRefParams
(
self
):
"""Test use of struct byref parameters."""
result
=
MethodTest
.
TestStructRefParams
(
"hi"
,
System
.
Guid
.
NewGuid
())
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertTrue
(
len
(
result
)
==
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
isinstance
(
result
[
1
],
System
.
Guid
))
def
test
():
MethodTest
.
TestValueRefParams
(
"hi"
,
None
)
# None cannot be converted to a value type like a struct
self
.
assertRaises
(
TypeError
,
test
)
def
testVoidSingleOutParam
(
self
):
"""Test void method with single out-parameter."""
result
=
MethodTest
.
TestVoidSingleOutParam
(
9
)
self
.
assertTrue
(
result
==
42
)
def
test
():
MethodTest
.
TestVoidSingleOutParam
(
None
)
# None cannot be converted to a value type
self
.
assertRaises
(
TypeError
,
test
)
def
testVoidSingleRefParam
(
self
):
"""Test void method with single ref-parameter."""
result
=
MethodTest
.
TestVoidSingleRefParam
(
9
)
self
.
assertTrue
(
result
==
42
)
def
test
():
MethodTest
.
TestVoidSingleRefParam
(
None
)
# None cannot be converted to a value type
self
.
assertRaises
(
TypeError
,
test
)
def
testExplicitSelectionWithOutModifier
(
self
):
"""Check explicit overload selection with out modifiers."""
refstr
=
System
.
String
(
""
).
GetType
().
MakeByRefType
()
result
=
MethodTest
.
TestStringOutParams
.
__overloads__
[
str
,
refstr
](
"hi"
,
"there"
)
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertTrue
(
len
(
result
)
==
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
result
[
1
]
==
"output string"
)
result
=
MethodTest
.
TestStringOutParams
.
__overloads__
[
str
,
refstr
](
"hi"
,
None
)
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertTrue
(
len
(
result
)
==
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
result
[
1
]
==
"output string"
)
def
testExplicitSelectionWithRefModifier
(
self
):
"""Check explicit overload selection with ref modifiers."""
refstr
=
System
.
String
(
""
).
GetType
().
MakeByRefType
()
result
=
MethodTest
.
TestStringRefParams
.
__overloads__
[
str
,
refstr
](
"hi"
,
"there"
)
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertTrue
(
len
(
result
)
==
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
result
[
1
]
==
"output string"
)
result
=
MethodTest
.
TestStringRefParams
.
__overloads__
[
str
,
refstr
](
"hi"
,
None
)
self
.
assertTrue
(
type
(
result
)
==
type
(()))
self
.
assertTrue
(
len
(
result
)
==
2
)
self
.
assertTrue
(
result
[
0
]
==
True
)
self
.
assertTrue
(
result
[
1
]
==
"output string"
)
def
testExplicitOverloadSelection
(
self
):
"""Check explicit overload selection using [] syntax."""
from
Python
.
Test
import
ISayHello1
,
InterfaceTest
,
ShortEnum
from
System
import
Array
inst
=
InterfaceTest
()
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
Boolean
](
True
)
self
.
assertTrue
(
value
==
True
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
bool
](
True
)
self
.
assertTrue
(
value
==
True
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
Byte
](
255
)
self
.
assertTrue
(
value
==
255
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
SByte
](
127
)
self
.
assertTrue
(
value
==
127
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
Char
](
u'A'
)
self
.
assertTrue
(
value
==
u'A'
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
Char
](
65535
)
self
.
assertTrue
(
value
==
unichr
(
65535
))
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
Int16
](
32767
)
self
.
assertTrue
(
value
==
32767
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
Int32
](
2147483647
)
self
.
assertTrue
(
value
==
2147483647
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
int
](
2147483647
)
self
.
assertTrue
(
value
==
2147483647
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
Int64
](
9223372036854775807L
)
self
.
assertTrue
(
value
==
9223372036854775807L
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
long
](
9223372036854775807L
)
self
.
assertTrue
(
value
==
9223372036854775807L
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
UInt16
](
65000
)
self
.
assertTrue
(
value
==
65000
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
UInt32
](
4294967295L
)
self
.
assertTrue
(
value
==
4294967295L
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
UInt64
](
18446744073709551615L
)
self
.
assertTrue
(
value
==
18446744073709551615L
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
Single
](
3.402823e38
)
self
.
assertTrue
(
value
==
3.402823e38
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
Double
](
1.7976931348623157e308
)
self
.
assertTrue
(
value
==
1.7976931348623157e308
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
float
](
1.7976931348623157e308
)
self
.
assertTrue
(
value
==
1.7976931348623157e308
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
Decimal
](
System
.
Decimal
.
One
)
self
.
assertTrue
(
value
==
System
.
Decimal
.
One
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
String
](
"spam"
)
self
.
assertTrue
(
value
==
"spam"
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
str
](
"spam"
)
self
.
assertTrue
(
value
==
"spam"
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
ShortEnum
](
ShortEnum
.
Zero
)
self
.
assertTrue
(
value
==
ShortEnum
.
Zero
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
Object
](
inst
)
self
.
assertTrue
(
value
.
__class__
==
inst
.
__class__
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
InterfaceTest
](
inst
)
self
.
assertTrue
(
value
.
__class__
==
inst
.
__class__
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
ISayHello1
](
inst
)
self
.
assertTrue
(
value
.
__class__
==
inst
.
__class__
)
atype
=
Array
[
System
.
Object
]
value
=
MethodTest
.
Overloaded
.
__overloads__
[
str
,
int
,
atype
](
"one"
,
1
,
atype
([
1
,
2
,
3
])
)
self
.
assertTrue
(
value
==
3
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
str
,
int
](
"one"
,
1
)
self
.
assertTrue
(
value
==
1
)
value
=
MethodTest
.
Overloaded
.
__overloads__
[
int
,
str
](
1
,
"one"
)
self
.
assertTrue
(
value
==
1
)
def
testOverloadSelectionWithArrayTypes
(
self
):
"""Check overload selection using array types."""
from
Python
.
Test
import
ISayHello1
,
InterfaceTest
,
ShortEnum
from
System
import
Array
inst
=
InterfaceTest
()
vtype
=
Array
[
System
.
Boolean
]
input
=
vtype
([
True
,
True
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
True
)
self
.
assertTrue
(
value
[
1
]
==
True
)
vtype
=
Array
[
bool
]
input
=
vtype
([
True
,
True
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
True
)
self
.
assertTrue
(
value
[
1
]
==
True
)
vtype
=
Array
[
System
.
Byte
]
input
=
vtype
([
0
,
255
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
0
)
self
.
assertTrue
(
value
[
1
]
==
255
)
vtype
=
Array
[
System
.
SByte
]
input
=
vtype
([
0
,
127
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
0
)
self
.
assertTrue
(
value
[
1
]
==
127
)
vtype
=
Array
[
System
.
Char
]
input
=
vtype
([
u'A'
,
u'Z'
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
u'A'
)
self
.
assertTrue
(
value
[
1
]
==
u'Z'
)
vtype
=
Array
[
System
.
Char
]
input
=
vtype
([
0
,
65535
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
unichr
(
0
))
self
.
assertTrue
(
value
[
1
]
==
unichr
(
65535
))
vtype
=
Array
[
System
.
Int16
]
input
=
vtype
([
0
,
32767
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
0
)
self
.
assertTrue
(
value
[
1
]
==
32767
)
vtype
=
Array
[
System
.
Int32
]
input
=
vtype
([
0
,
2147483647
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
0
)
self
.
assertTrue
(
value
[
1
]
==
2147483647
)
vtype
=
Array
[
int
]
input
=
vtype
([
0
,
2147483647
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
0
)
self
.
assertTrue
(
value
[
1
]
==
2147483647
)
vtype
=
Array
[
System
.
Int64
]
input
=
vtype
([
0
,
9223372036854775807L
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
0
)
self
.
assertTrue
(
value
[
1
]
==
9223372036854775807L
)
vtype
=
Array
[
long
]
input
=
vtype
([
0
,
9223372036854775807L
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
0
)
self
.
assertTrue
(
value
[
1
]
==
9223372036854775807L
)
vtype
=
Array
[
System
.
UInt16
]
input
=
vtype
([
0
,
65000
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
0
)
self
.
assertTrue
(
value
[
1
]
==
65000
)
vtype
=
Array
[
System
.
UInt32
]
input
=
vtype
([
0
,
4294967295L
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
0
)
self
.
assertTrue
(
value
[
1
]
==
4294967295L
)
vtype
=
Array
[
System
.
UInt64
]
input
=
vtype
([
0
,
18446744073709551615L
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
0
)
self
.
assertTrue
(
value
[
1
]
==
18446744073709551615L
)
vtype
=
Array
[
System
.
Single
]
input
=
vtype
([
0.0
,
3.402823e38
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
0.0
)
self
.
assertTrue
(
value
[
1
]
==
3.402823e38
)
vtype
=
Array
[
System
.
Double
]
input
=
vtype
([
0.0
,
1.7976931348623157e308
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
0.0
)
self
.
assertTrue
(
value
[
1
]
==
1.7976931348623157e308
)
vtype
=
Array
[
float
]
input
=
vtype
([
0.0
,
1.7976931348623157e308
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
0.0
)
self
.
assertTrue
(
value
[
1
]
==
1.7976931348623157e308
)
vtype
=
Array
[
System
.
Decimal
]
input
=
vtype
([
System
.
Decimal
.
Zero
,
System
.
Decimal
.
One
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
System
.
Decimal
.
Zero
)
self
.
assertTrue
(
value
[
1
]
==
System
.
Decimal
.
One
)
vtype
=
Array
[
System
.
String
]
input
=
vtype
([
"one"
,
"two"
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
"one"
)
self
.
assertTrue
(
value
[
1
]
==
"two"
)
vtype
=
Array
[
str
]
input
=
vtype
([
"one"
,
"two"
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
"one"
)
self
.
assertTrue
(
value
[
1
]
==
"two"
)
vtype
=
Array
[
ShortEnum
]
input
=
vtype
([
ShortEnum
.
Zero
,
ShortEnum
.
One
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
]
==
ShortEnum
.
Zero
)
self
.
assertTrue
(
value
[
1
]
==
ShortEnum
.
One
)
vtype
=
Array
[
System
.
Object
]
input
=
vtype
([
inst
,
inst
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
].
__class__
==
inst
.
__class__
)
self
.
assertTrue
(
value
[
1
].
__class__
==
inst
.
__class__
)
vtype
=
Array
[
InterfaceTest
]
input
=
vtype
([
inst
,
inst
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
].
__class__
==
inst
.
__class__
)
self
.
assertTrue
(
value
[
1
].
__class__
==
inst
.
__class__
)
vtype
=
Array
[
ISayHello1
]
input
=
vtype
([
inst
,
inst
])
value
=
MethodTest
.
Overloaded
.
__overloads__
[
vtype
](
input
)
self
.
assertTrue
(
value
[
0
].
__class__
==
inst
.
__class__
)
self
.
assertTrue
(
value
[
1
].
__class__
==
inst
.
__class__
)
def
testExplicitOverloadSelectionFailure
(
self
):
"""Check that overload selection fails correctly."""
def
test
():
value
=
MethodTest
.
Overloaded
.
__overloads__
[
System
.
Type
](
True
)
self
.
assertRaises
(
TypeError
,
test
)
def
test
():
value
=
MethodTest
.
Overloaded
.
__overloads__
[
int
,
int
](
1
,
1
)
self
.
assertRaises
(
TypeError
,
test
)
def
test
():
value
=
MethodTest
.
Overloaded
.
__overloads__
[
str
,
int
,
int
](
""
,
1
,
1
)
self
.
assertRaises
(
TypeError
,
test
)
def
test
():
value
=
MethodTest
.
Overloaded
.
__overloads__
[
int
,
long
](
1
)
self
.
assertRaises
(
TypeError
,
test
)
def
test_suite
():
return
unittest
.
makeSuite
(
MethodTests
)
def
main
():
unittest
.
TextTestRunner
().
run
(
test_suite
())
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL