13
13
14
14
from Python .Test import MethodTest , MethodTestSub
15
15
import System
16
+ import six
17
+
18
+ if six .PY3 :
19
+ long = int
20
+ unichr = chr
21
+
16
22
17
23
class MethodTests (unittest .TestCase ):
18
24
"""Test CLR method support."""
@@ -235,11 +241,11 @@ def testMethodCallStructConversion(self):
235
241
236
242
def testSubclassInstanceConversion (self ):
237
243
"""Test subclass instance conversion in method call."""
238
- class sub (System .Exception ):
244
+ class TestSubException (System .Exception ):
239
245
pass
240
246
241
247
object = MethodTest ()
242
- instance = sub ()
248
+ instance = TestSubException ()
243
249
result = object .TestSubclassConversion (instance )
244
250
self .assertTrue (isinstance (result , System .Exception ))
245
251
@@ -522,8 +528,8 @@ def testExplicitOverloadSelection(self):
522
528
value = MethodTest .Overloaded .__overloads__ [System .SByte ](127 )
523
529
self .assertTrue (value == 127 )
524
530
525
- value = MethodTest .Overloaded .__overloads__ [System .Char ](u 'A' )
526
- self .assertTrue (value == u 'A' )
531
+ value = MethodTest .Overloaded .__overloads__ [System .Char ](six . u ( 'A' ) )
532
+ self .assertTrue (value == six . u ( 'A' ) )
527
533
528
534
value = MethodTest .Overloaded .__overloads__ [System .Char ](65535 )
529
535
self .assertTrue (value == unichr (65535 ))
@@ -538,25 +544,27 @@ def testExplicitOverloadSelection(self):
538
544
self .assertTrue (value == 2147483647 )
539
545
540
546
value = MethodTest .Overloaded .__overloads__ [System .Int64 ](
541
- 9223372036854775807L
547
+ long ( 9223372036854775807 )
542
548
)
543
- self .assertTrue (value == 9223372036854775807L )
549
+ self .assertTrue (value == long ( 9223372036854775807 ) )
544
550
545
- value = MethodTest .Overloaded .__overloads__ [long ](
546
- 9223372036854775807L
547
- )
548
- self .assertTrue (value == 9223372036854775807L )
551
+ # Python 3 has no explicit long type, use System.Int64 instead
552
+ if not six .PY3 :
553
+ value = MethodTest .Overloaded .__overloads__ [long ](
554
+ long (9223372036854775807 )
555
+ )
556
+ self .assertTrue (value == long (9223372036854775807 ))
549
557
550
558
value = MethodTest .Overloaded .__overloads__ [System .UInt16 ](65000 )
551
559
self .assertTrue (value == 65000 )
552
560
553
- value = MethodTest .Overloaded .__overloads__ [System .UInt32 ](4294967295L )
554
- self .assertTrue (value == 4294967295L )
561
+ value = MethodTest .Overloaded .__overloads__ [System .UInt32 ](long ( 4294967295 ) )
562
+ self .assertTrue (value == long ( 4294967295 ) )
555
563
556
564
value = MethodTest .Overloaded .__overloads__ [System .UInt64 ](
557
- 18446744073709551615L
565
+ long ( 18446744073709551615 )
558
566
)
559
- self .assertTrue (value == 18446744073709551615L )
567
+ self .assertTrue (value == long ( 18446744073709551615 ) )
560
568
561
569
value = MethodTest .Overloaded .__overloads__ [System .Single ](3.402823e38 )
562
570
self .assertTrue (value == 3.402823e38 )
@@ -638,10 +646,10 @@ def testOverloadSelectionWithArrayTypes(self):
638
646
self .assertTrue (value [1 ] == 127 )
639
647
640
648
vtype = Array [System .Char ]
641
- input = vtype ([u 'A', u 'Z' ])
649
+ input = vtype ([six . u ( 'A' ), six . u ( 'Z' ) ])
642
650
value = MethodTest .Overloaded .__overloads__ [vtype ](input )
643
- self .assertTrue (value [0 ] == u 'A' )
644
- self .assertTrue (value [1 ] == u 'Z' )
651
+ self .assertTrue (value [0 ] == six . u ( 'A' ) )
652
+ self .assertTrue (value [1 ] == six . u ( 'Z' ) )
645
653
646
654
vtype = Array [System .Char ]
647
655
input = vtype ([0 , 65535 ])
@@ -668,16 +676,18 @@ def testOverloadSelectionWithArrayTypes(self):
668
676
self .assertTrue (value [1 ] == 2147483647 )
669
677
670
678
vtype = Array [System .Int64 ]
671
- input = vtype ([0 , 9223372036854775807L ])
679
+ input = vtype ([0 , long ( 9223372036854775807 ) ])
672
680
value = MethodTest .Overloaded .__overloads__ [vtype ](input )
673
681
self .assertTrue (value [0 ] == 0 )
674
- self .assertTrue (value [1 ] == 9223372036854775807L )
682
+ self .assertTrue (value [1 ] == long ( 9223372036854775807 ))
675
683
676
- vtype = Array [long ]
677
- input = vtype ([0 , 9223372036854775807L ])
678
- value = MethodTest .Overloaded .__overloads__ [vtype ](input )
679
- self .assertTrue (value [0 ] == 0 )
680
- self .assertTrue (value [1 ] == 9223372036854775807L )
684
+ # Python 3 has no explicit long type, use System.Int64 instead
685
+ if not six .PY3 :
686
+ vtype = Array [long ]
687
+ input = vtype ([0 , long (9223372036854775807 )])
688
+ value = MethodTest .Overloaded .__overloads__ [vtype ](input )
689
+ self .assertTrue (value [0 ] == 0 )
690
+ self .assertTrue (value [1 ] == long (9223372036854775807 ))
681
691
682
692
vtype = Array [System .UInt16 ]
683
693
input = vtype ([0 , 65000 ])
@@ -686,16 +696,16 @@ def testOverloadSelectionWithArrayTypes(self):
686
696
self .assertTrue (value [1 ] == 65000 )
687
697
688
698
vtype = Array [System .UInt32 ]
689
- input = vtype ([0 , 4294967295L ])
699
+ input = vtype ([0 , long ( 4294967295 ) ])
690
700
value = MethodTest .Overloaded .__overloads__ [vtype ](input )
691
701
self .assertTrue (value [0 ] == 0 )
692
- self .assertTrue (value [1 ] == 4294967295L )
702
+ self .assertTrue (value [1 ] == long ( 4294967295 ))
693
703
694
704
vtype = Array [System .UInt64 ]
695
- input = vtype ([0 , 18446744073709551615L ])
705
+ input = vtype ([0 , long ( 18446744073709551615 ) ])
696
706
value = MethodTest .Overloaded .__overloads__ [vtype ](input )
697
707
self .assertTrue (value [0 ] == 0 )
698
- self .assertTrue (value [1 ] == 18446744073709551615L )
708
+ self .assertTrue (value [1 ] == long ( 18446744073709551615 ))
699
709
700
710
vtype = Array [System .Single ]
701
711
input = vtype ([0.0 , 3.402823e38 ])
0 commit comments