PageRenderTime 96ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Languages/IronPython/Tests/test_methodbinder1.py

http://github.com/IronLanguages/main
Python | 1154 lines | 1132 code | 5 blank | 17 comment | 3 complexity | f9b9cc9a6aa627abf1cb754aac149f9e MD5 | raw file
Possible License(s): CPL-1.0, BSD-3-Clause, ISC, GPL-2.0, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. #####################################################################################
  2. #
  3. # Copyright (c) Microsoft Corporation. All rights reserved.
  4. #
  5. # This source code is subject to terms and conditions of the Apache License, Version 2.0. A
  6. # copy of the license can be found in the License.html file at the root of this distribution. If
  7. # you cannot locate the Apache License, Version 2.0, please send an email to
  8. # ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. # by the terms of the Apache License, Version 2.0.
  10. #
  11. # You must not remove this notice, or any other, from this software.
  12. #
  13. #
  14. #####################################################################################
  15. #
  16. # PART 1. how IronPython choose the CLI method, treat parameters WHEN NO OVERLOADS PRESENT
  17. #
  18. from iptest.assert_util import *
  19. from iptest.type_util import *
  20. skiptest("win32")
  21. load_iron_python_test()
  22. from IronPythonTest.BinderTest import *
  23. myint1, myint2 = myint(20), myint(-20)
  24. mylong1, mylong2 = mylong(3), mylong(-4)
  25. myfloat1, myfloat2 = myfloat(4.5), myfloat(-4.5)
  26. mycomplex1 = mycomplex(3)
  27. funcs = '''
  28. M100 M201 M202 M203 M204 M205 M301 M302 M303 M304
  29. M310 M311 M312 M313 M320 M321 M400 M401 M402 M403
  30. M404 M410 M411 M450 M451
  31. M500 M510 M600 M610 M611 M620 M630
  32. M650 M651 M652 M653
  33. M680 M700 M701
  34. M710 M715
  35. '''.split()
  36. args = '''
  37. NoArg Int32 Double BigInt Bool String SByte Int16 Int64 Single
  38. Byte UInt16 UInt32 UInt64 Char Decml Object I C1 C2
  39. S1 A C6 E1 E2
  40. ArrInt32 ArrI ParamArrInt32 ParamArrI ParamArrS Int32ParamArrInt32 IParamArrI
  41. IListInt Array IEnumerableInt IEnumeratorInt
  42. NullableInt RefInt32 OutInt32
  43. DefValInt32 Int32DefValInt32
  44. '''.split()
  45. arg2func = dict(zip(args, funcs))
  46. func2arg = dict(zip(funcs, args))
  47. TypeE = TypeError
  48. OverF = OverflowError
  49. def _get_funcs(args): return [arg2func[x] for x in args.split()]
  50. def _self_defined_method(name): return len(name) == 4 and name[0] == "M"
  51. def _my_call(func, arg):
  52. if isinstance(arg, tuple):
  53. l = len(arg)
  54. # by purpose
  55. if l == 0: func()
  56. elif l == 1: func(arg[0])
  57. elif l == 2: func(arg[0], arg[1])
  58. elif l == 3: func(arg[0], arg[1], arg[2])
  59. elif l == 4: func(arg[0], arg[1], arg[2], arg[3])
  60. elif l == 5: func(arg[0], arg[1], arg[2], arg[3], arg[4])
  61. elif l == 6: func(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5])
  62. else: func(*arg)
  63. else:
  64. func(arg)
  65. def _helper(func, positiveArgs, flagValue, negativeArgs, exceptType):
  66. for arg in positiveArgs:
  67. try:
  68. _my_call(func, arg)
  69. except Exception, e:
  70. Fail("unexpected exception %s when calling %s with %s\n%s" % (e, func, arg, func.__doc__))
  71. else:
  72. AreEqual(Flag.Value, flagValue)
  73. Flag.Value = -188
  74. for arg in negativeArgs:
  75. try:
  76. _my_call(func, arg)
  77. except Exception, e:
  78. if not isinstance(e, exceptType):
  79. Fail("expected '%s', but got '%s' when calling %s with %s\n%s" % (exceptType, e, func, arg, func.__doc__))
  80. else:
  81. Fail("expected exception (but didn't get one) when calling func %s on args %s\n%s" % (func, arg, func.__doc__))
  82. def test_this_matrix():
  83. '''
  84. This will test the full matrix.
  85. To print the matrix, enable the following flag
  86. '''
  87. print_the_matrix = False
  88. funcnames = "M201 M680 M202 M203 M204 M205 M301 M302 M303 M304 M310 M311 M312 M313 M320 M321 M400".split()
  89. matrix = (
  90. #### M201 M680 M202 M203 M204 M205 M301 M302 M303 M304 M310 M311 M312 M313 M320 M321 M400
  91. #### int int? double bigint bool str sbyte i16 i64 single byte ui16 ui32 ui64 char decm obj
  92. ( "SByteMax", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  93. ( "ByteMax", True, True, True, True, True, TypeE, OverF, True, True, True, True, True, True, True, TypeE, True, True, ),
  94. ( "Int16Max", True, True, True, True, True, TypeE, OverF, True, True, True, OverF, True, True, True, TypeE, True, True, ),
  95. ( "UInt16Max", True, True, True, True, True, TypeE, OverF, OverF, True, True, OverF, True, True, True, TypeE, True, True, ),
  96. ( "intMax", True, True, True, True, True, TypeE, OverF, OverF, True, True, OverF, OverF, True, True, TypeE, True, True, ),
  97. ( "UInt32Max", OverF, OverF, True, True, True, TypeE, OverF, OverF, True, True, OverF, OverF, True, True, TypeE, True, True, ),
  98. ( "Int64Max", OverF, OverF, True, True, True, TypeE, OverF, OverF, True, True, OverF, OverF, OverF, True, TypeE, True, True, ),
  99. ( "UInt64Max", OverF, OverF, True, True, True, TypeE, OverF, OverF, OverF, True, OverF, OverF, OverF, True, TypeE, True, True, ),
  100. ( "DecimalMax", OverF, OverF, True, True, True, TypeE, OverF, OverF, OverF, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  101. ( "SingleMax", OverF, OverF, True, True, True, TypeE, OverF, OverF, OverF, True, OverF, OverF, OverF, OverF, TypeE, OverF, True, ),
  102. ( "floatMax", OverF, OverF, True, True, True, TypeE, OverF, OverF, OverF, True, OverF, OverF, OverF, OverF, TypeE, OverF, True, ),
  103. #### M201 M680 M202 M203 M204 M205 M301 M302 M303 M304 M310 M311 M312 M313 M320 M321 M400
  104. #### int int? double bigint bool str sbyte i16 i64 single byte ui16 ui32 ui64 char decm obj
  105. ( "SByteMin", True, True, True, True, True, TypeE, True, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  106. ( "ByteMin", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  107. ( "Int16Min", True, True, True, True, True, TypeE, OverF, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  108. ( "UInt16Min", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  109. ( "intMin", True, True, True, True, True, TypeE, OverF, OverF, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  110. ( "UInt32Min", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  111. ( "Int64Min", OverF, OverF, True, True, True, TypeE, OverF, OverF, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  112. ( "UInt64Min", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  113. ( "DecimalMin", OverF, OverF, True , True, True, TypeE, OverF, OverF, OverF, True, OverF, OverF, OverF, OverF, TypeE, True , True, ),
  114. ( "SingleMin", OverF, OverF, True, True, True, TypeE, OverF, OverF, OverF, True, OverF, OverF, OverF, OverF, TypeE, OverF, True, ),
  115. ( "floatMin", OverF, OverF, True, True, True, TypeE, OverF, OverF, OverF, True, OverF, OverF, OverF, OverF, TypeE, OverF, True, ),
  116. #### M201 M680 M202 M203 M204 M205 M301 M302 M303 M304 M310 M311 M312 M313 M320 M321 M400
  117. #### int int? double bigint bool str sbyte i16 i64 single byte ui16 ui32 ui64 char decm obj
  118. ( "SBytePlusOne", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  119. ( "BytePlusOne", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  120. ( "Int16PlusOne", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  121. ( "UInt16PlusOne", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  122. ( "intPlusOne", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  123. ( myint1, True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  124. ( "UInt32PlusOne", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  125. ( "Int64PlusOne", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  126. ( "UInt64PlusOne", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  127. ( "DecimalPlusOne", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  128. ( "SinglePlusOne", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  129. ( "floatPlusOne", True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  130. ( myfloat1, True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  131. #### M201 M680 M202 M203 M204 M205 M301 M302 M303 M304 M310 M311 M312 M313 M320 M321 M400
  132. #### int int? double bigint bool str sbyte i16 i64 single byte ui16 ui32 ui64 char decm obj
  133. ( "SByteMinusOne", True, True, True, True, True, TypeE, True, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  134. ( "Int16MinusOne", True, True, True, True, True, TypeE, True, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  135. ( "intMinusOne", True, True, True, True, True, TypeE, True, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  136. ( myint2, True, True, True, True, True, TypeE, True, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  137. ( "Int64MinusOne", True, True, True, True, True, TypeE, True, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  138. ( "DecimalMinusOne", True, True, True, True, True, TypeE, True, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  139. ( "SingleMinusOne", True, True, True, True, True, TypeE, True, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  140. ( "floatMinusOne", True, True, True, True, True, TypeE, True, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  141. ( myfloat2, True, True, True, True, True, TypeE, True, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  142. ################################################## pass in bool #########################################################
  143. #### M201 M680 M202 M203 M204 M205 M301 M302 M303 M304 M310 M311 M312 M313 M320 M321 M400
  144. #### int int? double bigint bool str sbyte i16 i64 single byte ui16 ui32 ui64 char decm obj
  145. ( True, True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  146. ( False, True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  147. ################################################## pass in BigInt #########################################################
  148. #### int int? double bigint bool str sbyte i16 i64 single byte ui16 ui32 ui64 char decm obj
  149. #### M201 M680 M202 M203 M204 M205 M301 M302 M303 M304 M310 M311 M312 M313 M320 M321 M400
  150. ( 10L, True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  151. ( -10L, True, True, True, True, True, TypeE, True, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  152. ( 1234567890123456L, OverF, OverF, True , True, True, TypeE, OverF, OverF, True, True, OverF, OverF, OverF, True, TypeE, True, True, ),
  153. ( mylong1, True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ),
  154. ( mylong2, True, True, True, True, True, TypeE, True, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ),
  155. ################################################## pass in Complex #########################################################
  156. #### M201 M680 M202 M203 M204 M205 M301 M302 M303 M304 M310 M311 M312 M313 M320 M321 M400
  157. #### int int? double bigint bool str sbyte i16 i64 single byte ui16 ui32 ui64 char decm obj
  158. ( (3+0j), TypeE, TypeE, TypeE, TypeE, True, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, True, ),
  159. ( (3+1j), TypeE, TypeE, TypeE, TypeE, True, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, True, ),
  160. ( mycomplex1, TypeE, TypeE, TypeE, TypeE, True, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, True, )
  161. )
  162. if is_silverlight==False:
  163. InvariantCulture = System.Globalization.CultureInfo.InvariantCulture
  164. matrix = list(matrix)
  165. ################################################## pass in char #########################################################
  166. #### M201 M680 M202 M203 M204 M205 M301 M302 M303 M304 M310 M311 M312 M313 M320 M321 M400
  167. #### int int? double bigint bool str sbyte i16 i64 single byte ui16 ui32 ui64 char decm obj
  168. matrix.append((System.Char.Parse('A'), TypeE, TypeE, TypeE, TypeE, True, True, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, TypeE, True, True, True, ))
  169. ################################################## pass in float #########################################################
  170. #### single/double becomes Int32, but this does not apply to other primitive types
  171. #### int int? double bigint bool str sbyte i16 i64 single byte ui16 ui32 ui64 char decm obj
  172. matrix.append((System.Single.Parse("8.01", InvariantCulture), True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ))
  173. matrix.append((System.Double.Parse("10.2", InvariantCulture), True, True, True, True, True, TypeE, True, True, True, True, True, True, True, True, TypeE, True, True, ))
  174. matrix.append((System.Single.Parse("-8.1", InvariantCulture), True, True, True, True, True, TypeE, True, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ))
  175. matrix.append((System.Double.Parse("-1.8", InvariantCulture), True, True, True, True, True, TypeE, True, True, True, True, OverF, OverF, OverF, OverF, TypeE, True, True, ))
  176. matrix = tuple(matrix)
  177. for scenario in matrix:
  178. if isinstance(scenario[0], str):
  179. value = clr_numbers[scenario[0]]
  180. if print_the_matrix: print '(%18s,' % ('"'+ scenario[0] +'"'),
  181. else:
  182. value = scenario[0]
  183. if print_the_matrix: print '(%18s,' % value ,
  184. for i in range(len(funcnames)):
  185. funcname = funcnames[i]
  186. func = getattr(target, funcname)
  187. if print_the_matrix:
  188. try:
  189. func(value)
  190. print "True, ",
  191. except TypeError:
  192. print "TypeE,",
  193. except OverflowError:
  194. print "OverF,",
  195. print "),"
  196. else:
  197. try:
  198. func(value)
  199. except Exception,e:
  200. if scenario[i+1] not in [TypeE, OverF]:
  201. Fail("unexpected exception %s, when func %s on arg %s (%s)\n%s" % (e, funcname, scenario[0], type(value), func.__doc__))
  202. if isinstance(e, scenario[i+1]): pass
  203. else: Fail("expect %s, but got %s when func %s on arg %s (%s)\n%s" % (scenario[i+1], e, funcname, scenario[0], type(value), func.__doc__))
  204. else:
  205. if scenario[i+1] in [TypeE, OverF]:
  206. Fail("expect %s, but got none when func %s on arg %s (%s)\n%s" % (scenario[i+1], funcname, scenario[0], type(value), func.__doc__))
  207. left = Flag.Value ; Flag.Value = -99 # reset
  208. right = int(funcname[1:])
  209. if left != right:
  210. Fail("left %s != right %s when func %s on arg %s (%s)\n%s" % (left, right, funcname, scenario[0], type(value), func.__doc__))
  211. # these funcs should behavior same as M201(Int32)
  212. # should have NullableInt too ?
  213. for funcname in _get_funcs('RefInt32 ParamArrInt32 Int32ParamArrInt32'):
  214. for scenario in matrix:
  215. if isinstance(scenario[0], str): value = clr_numbers[scenario[0]]
  216. else: value = scenario[0]
  217. func = getattr(target, funcname)
  218. if scenario[1] not in [TypeE, OverF]:
  219. func(value)
  220. left = Flag.Value
  221. right = int(funcname[1:])
  222. if left != right:
  223. Fail("left %s != right %s when func %s on arg %s" % (left, right, funcname, scenario[0]))
  224. Flag.Value = -99 # reset
  225. else:
  226. try: func(value)
  227. except scenario[1]: pass # 1 is M201
  228. else: Fail("expect %s, but got none when func %s on arg %s" % (scenario[1], funcname, scenario[0]))
  229. def test_char_string_asked():
  230. # char asked
  231. _helper(target.M320, ['a', System.Char.MaxValue, System.Char.MinValue, 'abc'[2]], 320, ['abc', ('a b')], TypeError)
  232. # string asked
  233. _helper(target.M205, ['a', System.Char.MaxValue, System.Char.MinValue, 'abc'[2], 'abc', 'a b' ], 205, [('a', 'b'), 23, ], TypeError)
  234. def test_pass_extensible_types():
  235. # number covered by that matrix
  236. # string or char
  237. mystr1, mystr2 = mystr('a'), mystr('abc')
  238. _helper(target.M205, [mystr1, mystr2, ], 205, [], TypeError) # String
  239. _helper(target.M320, [mystr1, ], 320, [mystr2, ], TypeError) # Char
  240. # check the bool conversion result
  241. def test_bool_asked():
  242. for arg in ['a', 3, object(), True]:
  243. target.M204(arg)
  244. Assert(Flag.BValue, "argument is %s" % arg)
  245. Flag.BValue = False
  246. if is_silverlight==False:
  247. for arg in [0, System.Byte.Parse('0'), System.UInt64.Parse('0'), 0.0, 0L, False, None, tuple(), list()]:
  248. target.M204(arg)
  249. Assert(not Flag.BValue, "argument is %s" % (arg,))
  250. Flag.BValue = True
  251. def test_user_defined_conversion():
  252. class CP1:
  253. def __int__(self): return 100
  254. class CP2(object):
  255. def __int__(self): return 99
  256. class CP3: pass
  257. cp1, cp2, cp3 = CP1(), CP2(), CP3()
  258. ### 1. not work for Nullable<Int32> required (?)
  259. ### 2. (out int): should pass in nothing
  260. ### int params int int? ref int defVal int+defVal
  261. works = 'M201 M600 M680 M620 M700 M710 M715'
  262. for fn in works.split():
  263. _helper(getattr(target, fn), [cp1, cp2, ], int(fn[1:]), [cp3, ], TypeError)
  264. for fn in dir(target):
  265. ### bool obj
  266. if _self_defined_method(fn) and fn not in (works + 'M204 M400 '):
  267. _helper(getattr(target, fn), [], 0, [cp1, cp2, cp3, ], TypeError)
  268. def test_pass_in_derived_python_types():
  269. class CP1(I): pass
  270. class CP2(C1): pass
  271. class CP3(C2): pass
  272. class CP4(C6, I): pass
  273. cp1, cp2, cp3, cp4 = CP1(), CP2(), CP3(), CP4()
  274. # I asked
  275. _helper(target.M401, [C1(), C2(), S1(), cp1, cp2, cp3, cp4,], 401,[C3(), object()], TypeError)
  276. # C2 asked
  277. _helper(target.M403, [C2(), cp3, ], 403, [C3(), object(), C1(), cp1, cp2, cp4, ], TypeError)
  278. class CP1(A): pass
  279. class CP2(C6): pass
  280. cp1, cp2 = CP1(), CP2()
  281. # A asked
  282. _helper(target.M410, [C6(), cp1, cp2, cp4,], 410, [C3(), object(), C1(), cp3, ], TypeError)
  283. # C6 asked
  284. _helper(target.M411, [C6(), cp2, cp4, ], 411, [C3(), object(), C1(), cp1, cp3,], TypeError)
  285. def test_nullable_int():
  286. _helper(target.M680, [None, 100, 100L, System.Byte.MaxValue, System.UInt32.MinValue, myint1, mylong2, 3.6, ], 680, [(), 3+1j], TypeError)
  287. def test_out_int():
  288. if is_silverlight==False:
  289. _helper(target.M701, [], 701, [1, 10L, None, System.Byte.Parse('3')], TypeError) # not allow to pass in anything
  290. def test_collections():
  291. arrayInt = array_int((10, 20))
  292. tupleInt = ((10, 20), )
  293. listInt = ([10, 20], )
  294. tupleBool = ((True, False, True, True, False), )
  295. tupleLong1, tupleLong2 = ((10L, 20L), ), ((System.Int64.MaxValue, System.Int32.MaxValue * 2),)
  296. arrayByte = array_byte((10, 20))
  297. arrayObj = array_object(['str', 10])
  298. # IList<int>
  299. _helper(target.M650, [arrayInt, tupleInt, listInt, arrayObj, tupleLong1, tupleLong2, ], 650, [arrayByte, ], TypeError)
  300. # arrayObj, tupleLong1, tupleLong2 : conversion happens late
  301. # Array
  302. _helper(target.M651, [arrayInt, arrayObj, arrayByte, ], 651, [listInt, tupleInt, tupleLong1, tupleLong2, ], TypeError)
  303. # IEnumerable[int]
  304. _helper(target.M652, [arrayInt, arrayObj, arrayByte, listInt, tupleInt, tupleLong1, tupleLong2, ], 652, [], TypeError)
  305. # IEnumerator[int]
  306. _helper(target.M653, [], 653, [arrayInt, arrayObj, arrayByte, listInt, tupleInt, tupleLong1, tupleLong2, ], TypeError)
  307. # Int32[]
  308. _helper(target.M500, [arrayInt, tupleInt, tupleLong1, tupleBool, ], 500, [listInt, arrayByte, arrayObj, ], TypeError)
  309. _helper(target.M500, [], 500, [tupleLong2, ], OverflowError)
  310. # params Int32[]
  311. _helper(target.M600, [arrayInt, tupleInt, tupleLong1, tupleBool, ], 600, [listInt, arrayByte, arrayObj, ], TypeError)
  312. _helper(target.M600, [], 600, [tupleLong2, ], OverflowError)
  313. # Int32, params Int32[]
  314. _helper(target.M620, [(10, 10), (10L, 10), (10L, 10L), (10, 10L), (10, arrayInt), (10, (10, 20)), ], 620, [(10, [10, 20]), ], TypeError)
  315. _helper(target.M620, [], 620, [(10, 123456789101234L), ], OverflowError)
  316. arrayI1 = System.Array[I]( (C1(), C2()) )
  317. arrayI2 = System.Array[I]( () )
  318. arrayObj3 = System.Array[object]( (C1(), C2()) )
  319. tupleI = ((C1(), C2()),)
  320. listI = ([C1(), C2()],)
  321. _helper(target.M510, [arrayI1, arrayI2, tupleI, ], 510, [arrayObj3, listI, ], TypeError) # I[]
  322. _helper(target.M610, [arrayI1, arrayI2, tupleI, ], 610, [arrayObj3, listI, ], TypeError) # params I[]
  323. def test_no_arg_asked():
  324. # no args asked
  325. _helper(target.M100, [()], 100, [2, None, (2, None)], TypeError)
  326. def test_enum():
  327. # E1 asked
  328. _helper(target.M450, [E1.A, ], 450, [10, E2.A], TypeError)
  329. # E2: ushort asked
  330. if is_silverlight==False:
  331. _helper(target.M451, [E2.A, ], 451, [10, E1.A, System.UInt16.Parse("3")], TypeError)
  332. def _repeat_with_one_arg(goodStr, getArg):
  333. passSet = _get_funcs(goodStr)
  334. skipSet = []
  335. for fn in passSet:
  336. if fn in skipSet: continue
  337. arg = getArg()
  338. getattr(target, fn)(arg)
  339. left = Flag.Value
  340. right = int(fn[1:])
  341. if left != right:
  342. Fail("left %s != right %s when func %s on arg %s" % (left, right, fn, arg))
  343. for fn in dir(target):
  344. if _self_defined_method(fn) and (fn not in passSet) and (fn not in skipSet):
  345. arg = getArg()
  346. try: getattr(target, fn)(arg)
  347. except TypeError : pass
  348. else: Fail("expect TypeError, but got none when func %s on arg %s" % (fn, arg))
  349. def test_pass_in_none():
  350. test_str = '''
  351. Bool String Object I C1 C2 A C6
  352. ArrInt32 ArrI ParamArrInt32 ParamArrI ParamArrS IParamArrI
  353. IListInt Array IEnumerableInt IEnumeratorInt NullableInt
  354. '''
  355. # Big integers are only nullable in CLR 2
  356. if not is_net40:
  357. test_str = "BigInt " + test_str
  358. _repeat_with_one_arg(test_str, lambda : None)
  359. def test_pass_in_clrReference():
  360. import clr
  361. _repeat_with_one_arg('Object RefInt32 OutInt32', lambda : clr.Reference[int](0))
  362. _repeat_with_one_arg('Object', lambda : clr.Reference[object](None))
  363. _repeat_with_one_arg('Object RefInt32 OutInt32', lambda : clr.Reference[int](10))
  364. _repeat_with_one_arg('Object ', lambda : clr.Reference[float](123.123))
  365. _repeat_with_one_arg('Object', lambda : clr.Reference[type](str)) # ref.Value = (type)
  366. def test_pass_in_nothing():
  367. passSet = _get_funcs('NoArg ParamArrInt32 ParamArrS ParamArrI OutInt32 DefValInt32')
  368. skipSet = [ ] # be empty before release
  369. for fn in passSet:
  370. if fn in skipSet: continue
  371. getattr(target, fn)()
  372. left = Flag.Value
  373. right = int(fn[1:])
  374. if left != right:
  375. Fail("left %s != right %s when func %s on arg Nothing" % (left, right, fn))
  376. for fn in dir(target):
  377. if _self_defined_method(fn) and (fn not in passSet) and (fn not in skipSet):
  378. try: getattr(target, fn)()
  379. except TypeError : pass
  380. else: Fail("expect TypeError, but got none when func %s on arg Nothing" % fn)
  381. def test_other_concern():
  382. target = COtherConcern()
  383. # static void M100()
  384. target.M100()
  385. AreEqual(Flag.Value, 100); Flag.Value = 99
  386. COtherConcern.M100()
  387. AreEqual(Flag.Value, 100); Flag.Value = 99
  388. AssertError(TypeError, target.M100, target)
  389. AssertError(TypeError, COtherConcern.M100, target)
  390. # static void M101(COtherConcern arg)
  391. target.M101(target)
  392. AreEqual(Flag.Value, 101); Flag.Value = 99
  393. COtherConcern.M101(target)
  394. AreEqual(Flag.Value, 101); Flag.Value = 99
  395. AssertError(TypeError, target.M101)
  396. AssertError(TypeError, COtherConcern.M101)
  397. # void M102(COtherConcern arg)
  398. target.M102(target)
  399. AreEqual(Flag.Value, 102); Flag.Value = 99
  400. COtherConcern.M102(target, target)
  401. AreEqual(Flag.Value, 102); Flag.Value = 99
  402. AssertError(TypeError, target.M102)
  403. AssertError(TypeError, COtherConcern.M102, target)
  404. # generic method
  405. target.M200[int](100)
  406. AreEqual(Flag.Value, 200); Flag.Value = 99
  407. target.M200[int](100.1234)
  408. AreEqual(Flag.Value, 200); Flag.Value = 99
  409. target.M200[long](100)
  410. AreEqual(Flag.Value, 200); Flag.Value = 99
  411. AssertError(OverflowError, target.M200[System.Byte], 300)
  412. AssertError(OverflowError, target.M200[int], 12345678901234)
  413. # We should ignore Out attribute on non-byref.
  414. # It's used in native interop scenarios to designate a buffer (StringBUilder, arrays, etc.)
  415. # the caller allocates, passes to the method and expects the callee to populate it with data.
  416. AssertError(TypeError, target.M222)
  417. AreEqual(target.M222(0), None)
  418. AreEqual(Flag.Value, 222)
  419. # what does means when passing in None
  420. target.M300(None)
  421. AreEqual(Flag.Value, 300); Flag.Value = 99
  422. AreEqual(Flag.BValue, True)
  423. target.M300(C1())
  424. AreEqual(Flag.BValue, False)
  425. # void M400(ref Int32 arg1, out Int32 arg2, Int32 arg3) etc...
  426. AreEqual(target.M400(1, 100), (100, 100))
  427. AreEqual(target.M401(1, 100), (100, 100))
  428. AreEqual(target.M402(100, 1), (100, 100))
  429. # default Value
  430. target.M450()
  431. AreEqual(Flag.Value, 80); Flag.Value = 99
  432. # 8 args
  433. target.M500(1,2,3,4,5,6,7,8)
  434. AreEqual(Flag.Value, 500)
  435. AssertError(TypeError, target.M500)
  436. AssertError(TypeError, target.M500, 1)
  437. AssertError(TypeError, target.M500, 1,2,3,4,5,6,7,8,9)
  438. # IDictionary
  439. for x in [ {1:1}, {"str": 3} ]:
  440. target.M550(x)
  441. AreEqual(Flag.Value, 550); Flag.Value = 99
  442. AssertError(TypeError, target.M550, [1, 2])
  443. # not supported
  444. for fn in (target.M600, target.M601, target.M602):
  445. for l in ( {1:'a'}, [1,2], (1,2) ):
  446. AssertError(TypeError, fn, l)
  447. # delegate
  448. def f(x): return x * x
  449. AssertError(TypeError, target.M700, f)
  450. from IronPythonTest import IntIntDelegate
  451. for x in (lambda x: x, lambda x: x*2, f):
  452. target.M700(IntIntDelegate(x))
  453. AreEqual(Flag.Value, x(10)); Flag.Value = 99
  454. target.M701(lambda x: x*2)
  455. AreEqual(Flag.Value, 20); Flag.Value = 99
  456. AssertError(TypeError, target.M701, lambda : 10)
  457. # keywords
  458. x = target.M800(arg1 = 100, arg2 = 200L, arg3 = 'this'); AreEqual(x, 'THIS')
  459. x = target.M800(arg3 = 'Python', arg1 = 100, arg2 = 200L); AreEqual(x, 'PYTHON')
  460. x = target.M800(100, arg3 = 'iron', arg2 = C1()); AreEqual(x, 'IRON')
  461. try: target.M800(100, 'Yes', arg2 = C1())
  462. except TypeError: pass
  463. else: Fail("expect: got multiple values for keyword argument arg2")
  464. # more ref/out sanity check
  465. import clr
  466. def f1(): return clr.Reference[object](None)
  467. def f2(): return clr.Reference[int](10)
  468. def f3(): return clr.Reference[S1](S1())
  469. def f4(): return clr.Reference[C1](C2()) # C2 inherits C1
  470. for (f, a, b, c, d) in [
  471. ('M850', False, False, True, False),
  472. ('M851', False, False, False, True),
  473. ('M852', False, False, True, False),
  474. ('M853', False, False, False, True),
  475. ]:
  476. expect = (f in 'M850 M852') and S1 or C1
  477. func = getattr(target, f)
  478. for i in range(4):
  479. ref = (f1, f2, f3, f4)[i]()
  480. if (a,b,c,d)[i]:
  481. func(ref); AreEqual(type(ref.Value), expect)
  482. else:
  483. AssertError(TypeError, func, ref)
  484. # call 854
  485. AssertError(TypeError, target.M854, clr.Reference[object](None))
  486. AssertError(TypeError, target.M854, clr.Reference[int](10))
  487. # call 855
  488. AssertError(TypeError, target.M855, clr.Reference[object](None))
  489. AssertError(TypeError, target.M855, clr.Reference[int](10))
  490. # call 854 and 855 with Reference[bool]
  491. target.M854(clr.Reference[bool](True)); AreEqual(Flag.Value, 854)
  492. target.M855(clr.Reference[bool](True)); AreEqual(Flag.Value, 855)
  493. # practical
  494. ref = clr.Reference[int](0)
  495. ref2 = clr.Reference[int](0)
  496. ref.Value = 300
  497. ref2.Value = 100
  498. ## M860(ref arg1, arg2, out arg3): arg3 = arg1 + arg2; arg1 = 100;
  499. x = target.M860(ref, 200, ref2)
  500. AreEqual(x, None)
  501. AreEqual(ref.Value, 100)
  502. AreEqual(ref2.Value, 500)
  503. # pass one clr.Reference(), and leave the other one open
  504. ref.Value = 300
  505. AssertError(TypeError, target.M860, ref, 200)
  506. # the other way
  507. x = target.M860(300, 200)
  508. AreEqual(x, (100, 500))
  509. # GOtherConcern<T>
  510. target = GOtherConcern[int]()
  511. for x in [100, 200L, 4.56, myint1]:
  512. target.M100(x)
  513. AreEqual(Flag.Value, 100); Flag.Value = 99
  514. GOtherConcern[int].M100(target, 200)
  515. AreEqual(Flag.Value, 100); Flag.Value = 99
  516. AssertError(TypeError, target.M100, 'abc')
  517. AssertError(OverflowError, target.M100, 12345678901234)
  518. def test_iterator_sequence():
  519. class C:
  520. def __init__(self): self.x = 0
  521. def __iter__(self): return self
  522. def next(self):
  523. if self.x < 10:
  524. y = self.x
  525. self.x += 1
  526. return y
  527. else:
  528. self.x = 0
  529. raise StopIteration
  530. def __len__(self): return 10
  531. # different size
  532. c = C()
  533. list1 = [1, 2, 3]
  534. tuple1 = [4, 5, 6, 7]
  535. str1 = "890123"
  536. all = (list1, tuple1, str1, c)
  537. target = COtherConcern()
  538. for x in all:
  539. # IEnumerable / IEnumerator
  540. target.M620(x)
  541. AreEqual(Flag.Value, len(x)); Flag.Value = 0
  542. # built in types are not IEnumerator, they are enumerable
  543. if not isinstance(x, C):
  544. AssertError(TypeError, target.M621, x)
  545. else:
  546. target.M621(x)
  547. AreEqual(Flag.Value, len(x))
  548. # IEnumerable<char> / IEnumerator<char>
  549. target.M630(x)
  550. AreEqual(Flag.Value, len(x)); Flag.Value = 0
  551. AssertError(TypeError, target.M631, x)
  552. # IEnumerable<int> / IEnumerator<int>
  553. target.M640(x)
  554. AreEqual(Flag.Value, len(x)); Flag.Value = 0
  555. AssertError(TypeError, target.M641, x)
  556. # IList / IList<char> / IList<int>
  557. for x in (list1, tuple1):
  558. target.M622(x)
  559. AreEqual(Flag.Value, len(x))
  560. target.M632(x)
  561. AreEqual(Flag.Value, len(x))
  562. target.M642(x)
  563. AreEqual(Flag.Value, len(x))
  564. for x in (str1, c):
  565. AssertError(TypeError, target.M622, x)
  566. AssertError(TypeError, target.M632, x)
  567. AssertError(TypeError, target.M642, x)
  568. def test_explicit_inheritance():
  569. target = CInheritMany1()
  570. Assert(hasattr(target, "M"))
  571. target.M()
  572. AreEqual(Flag.Value, 100)
  573. I1.M(target); AreEqual(Flag.Value, 100); Flag.Value = 0
  574. target = CInheritMany2()
  575. target.M(); AreEqual(Flag.Value, 201)
  576. I1.M(target); AreEqual(Flag.Value, 200)
  577. target = CInheritMany3()
  578. Assert(not hasattr(target, "M"))
  579. try: target.M()
  580. except AttributeError: pass
  581. else: Fail("Expected AttributeError, got none")
  582. I1.M(target); AreEqual(Flag.Value, 300)
  583. I2.M(target); AreEqual(Flag.Value, 301)
  584. target = CInheritMany4()
  585. target.M(); AreEqual(Flag.Value, 401)
  586. I3[object].M(target); AreEqual(Flag.Value, 400)
  587. AssertError(TypeError, I3[int].M, target)
  588. target = CInheritMany5()
  589. I1.M(target); AreEqual(Flag.Value, 500)
  590. I2.M(target); AreEqual(Flag.Value, 501)
  591. I3[object].M(target); AreEqual(Flag.Value, 502)
  592. target.M(); AreEqual(Flag.Value, 503)
  593. target = CInheritMany6[int]()
  594. target.M(); AreEqual(Flag.Value, 601)
  595. I3[int].M(target); AreEqual(Flag.Value, 600)
  596. AssertError(TypeError, I3[object].M, target)
  597. target = CInheritMany7[int]()
  598. Assert(hasattr(target, "M"))
  599. target.M(); AreEqual(Flag.Value, 700)
  600. I3[int].M(target); AreEqual(Flag.Value, 700)
  601. target = CInheritMany8()
  602. Assert(not hasattr(target, "M"))
  603. try: target.M()
  604. except AttributeError: pass
  605. else: Fail("Expected AttributeError, got none")
  606. I1.M(target); AreEqual(Flag.Value, 800); Flag.Value = 0
  607. I4.M(target, 100); AreEqual(Flag.Value, 801)
  608. # target.M(100) ????
  609. # original repro
  610. from System.Collections.Generic import Dictionary
  611. d = Dictionary[object,object]()
  612. d.GetEnumerator() # not throw
  613. def test_nullable_property_double():
  614. from IronPythonTest import NullableTest
  615. nt = NullableTest()
  616. nt.DProperty = 1
  617. AreEqual(nt.DProperty, 1.0)
  618. nt.DProperty = 2.0
  619. AreEqual(nt.DProperty, 2.0)
  620. nt.DProperty = None
  621. AreEqual(nt.DProperty, None)
  622. @disabled("Merlin 309716")
  623. def test_nullable_property_long():
  624. from IronPythonTest import NullableTest
  625. nt = NullableTest()
  626. nt.LProperty = 1
  627. AreEqual(nt.LProperty, 1L)
  628. nt.LProperty = 2L
  629. AreEqual(nt.LProperty, 2L)
  630. nt.LProperty = None
  631. AreEqual(nt.LProperty, None)
  632. def test_nullable_property_bool():
  633. from IronPythonTest import NullableTest
  634. nt = NullableTest()
  635. nt.BProperty = 1.0
  636. AreEqual(nt.BProperty, True)
  637. nt.BProperty = 0.0
  638. AreEqual(nt.BProperty, False)
  639. nt.BProperty = True
  640. AreEqual(nt.BProperty, True)
  641. nt.BProperty = None
  642. AreEqual(nt.BProperty, None)
  643. def test_nullable_property_enum():
  644. from IronPythonTest import NullableTest
  645. nt = NullableTest()
  646. nt.EProperty = NullableTest.NullableEnums.NE1
  647. AreEqual(nt.EProperty, NullableTest.NullableEnums.NE1)
  648. nt.EProperty = None
  649. AreEqual(nt.EProperty, None)
  650. def test_nullable_parameter():
  651. from IronPythonTest import NullableTest
  652. nt = NullableTest()
  653. result = nt.Method(1)
  654. AreEqual(result, 1.0)
  655. result = nt.Method(2.0)
  656. AreEqual(result, 2.0)
  657. result = nt.Method(None)
  658. AreEqual(result, None)
  659. # Skip on silverlight because the System.Configuration is not available
  660. @skip("silverlight")
  661. @skip("netstandard") # no System.Configuration in netstandard
  662. def test_xequals_call_for_optimization():
  663. """
  664. Testing specifically for System.Configuration.ConfigurationManager
  665. because currently its .Equals method will throw null reference
  666. exception when called with null argument. This is a case that could
  667. slip through our dynamic site checks.
  668. """
  669. import clr
  670. clr.AddReference("System.Configuration");
  671. from System.Configuration import ConfigurationManager
  672. c = ConfigurationManager.ConnectionStrings
  673. #Invoke tests multiple times to make sure DynamicSites are utilized
  674. for i in xrange(3):
  675. if is_posix: # Posix has two default connection strings
  676. AreEqual(2, c.Count)
  677. else:
  678. AreEqual(1, c.Count)
  679. for i in xrange(3):
  680. count = c.Count
  681. if is_posix:
  682. AreEqual(2, count)
  683. else:
  684. AreEqual(1, count)
  685. AreEqual(c.Count, count)
  686. for i in xrange(3):
  687. #just ensure it doesn't throw
  688. c[0].Name
  689. #Just to be sure this doesn't throw...
  690. c.Count
  691. c.Count
  692. def test_interface_only_access():
  693. pc = InterfaceOnlyTest.PrivateClass
  694. # property set
  695. pc.Hello = InterfaceOnlyTest.PrivateClass
  696. # property get
  697. AreEqual(pc.Hello, pc)
  698. # method call w/ interface param
  699. pc.Foo(pc)
  700. # method call w/ interface ret val
  701. AreEqual(pc.RetInterface(), pc)
  702. # events
  703. global fired
  704. fired = False
  705. def fired(*args):
  706. global fired
  707. fired = True
  708. return args[0]
  709. # add event
  710. pc.MyEvent += fired
  711. # fire event
  712. AreEqual(pc.FireEvent(pc.GetEventArgs()), pc)
  713. AreEqual(fired, True)
  714. # remove event
  715. pc.MyEvent -= fired
  716. def test_ref_bytearr():
  717. target = COtherConcern()
  718. arr = System.Array[System.Byte]((2,3,4))
  719. res = target.M702(arr)
  720. AreEqual(Flag.Value, 702)
  721. AreEqual(type(res), System.Array[System.Byte])
  722. AreEqual(len(res), 0)
  723. i, res = target.M703(arr)
  724. AreEqual(Flag.Value, 703)
  725. AreEqual(i, 42)
  726. AreEqual(type(res), System.Array[System.Byte])
  727. AreEqual(len(res), 0)
  728. i, res = target.M704(arr, arr)
  729. AreEqual(Flag.Value, 704)
  730. AreEqual(i, 42)
  731. AreEqual(arr, res)
  732. sarr = clr.StrongBox[System.Array[System.Byte]](arr)
  733. res = target.M702(sarr)
  734. AreEqual(Flag.Value, 702)
  735. AreEqual(res, None)
  736. res = sarr.Value
  737. AreEqual(type(res), System.Array[System.Byte])
  738. AreEqual(len(res), 0)
  739. sarr.Value = arr
  740. i = target.M703(sarr)
  741. AreEqual(Flag.Value, 703)
  742. AreEqual(i, 42)
  743. AreEqual(len(sarr.Value), 0)
  744. i = target.M704(arr, sarr)
  745. AreEqual(Flag.Value, 704)
  746. AreEqual(i, 42)
  747. AreEqual(sarr.Value, arr)
  748. def test_struct_prop_assign():
  749. from IronPythonTest.BinderTest import SOtherConcern
  750. a = SOtherConcern()
  751. a.P100 = 42
  752. AreEqual(a.P100, 42)
  753. def test_generic_type_inference():
  754. from IronPythonTest import GenericTypeInference, GenericTypeInferenceInstance, SelfEnumerable
  755. from System import Array, Exception, ArgumentException
  756. from System.Collections.Generic import IEnumerable, List
  757. from System.Collections.Generic import Dictionary as Dict
  758. class UserGenericType(GenericTypeInferenceInstance): pass
  759. # public PythonType MInst<T>(T x) -> pytype(T)
  760. AreEqual(UserGenericType().MInst(42), int)
  761. class UserObject(object): pass
  762. userInst = UserObject()
  763. userInt, userLong, userFloat, userComplex, userStr = myint(), mylong(), myfloat(), mycomplex(), mystr()
  764. userTuple, userList, userDict = mytuple(), mylist(), mydict()
  765. objArray = System.Array[object]( (1,2,3) )
  766. doubleArray = System.Array[float]( (1.0,2.0,3.0) )
  767. for target in [GenericTypeInference, GenericTypeInferenceInstance(), UserGenericType()]:
  768. tests = [
  769. # simple single type tests, no constraints
  770. # public static PythonType M0<T>(T x) -> pytypeof(T)
  771. # target method, args, Result, KeywordCall, Exception
  772. (target.M0, (1, ), int, True, None),
  773. (target.M0, (userInst, ), object, True, None),
  774. (target.M0, (userInt, ), object, True, None),
  775. (target.M0, (userStr, ), object, True, None),
  776. (target.M0, (userLong, ), object, True, None),
  777. (target.M0, (userFloat, ), object, True, None),
  778. (target.M0, (userComplex, ), object, True, None),
  779. (target.M0, (userTuple, ), tuple, True, None),
  780. (target.M0, (userList, ), list, True, None),
  781. (target.M0, (userDict, ), dict, True, None),
  782. (target.M0, ((), ), tuple, True, None),
  783. (target.M0, ([], ), list, True, None),
  784. (target.M0, ({}, ), dict, True, None),
  785. # multiple arguments
  786. # public static PythonType M1<T>(T x, T y) -> pytypeof(T)
  787. # public static PythonType M2<T>(T x, T y, T z) -> pytypeof(T)
  788. (target.M1, (1, 2), int, True, None),
  789. (target.M2, (1, 2, 3), int, True, None),
  790. (target.M1, (userInst, userInst), object, True, None),
  791. (target.M2, (userInst, userInst, userInst), object, True, None),
  792. (target.M1, (1, 2.0), None, True, TypeError),
  793. (target.M1, (1, 'abc'), None, True, TypeError),
  794. (target.M1, (object(), userInst), object, True, None),
  795. (target.M1, ([], userList), list, True, None),
  796. # params arguments
  797. # public static PythonType M3<T>(params T[] args) -> pytypeof(T)
  798. (target.M3, (), None, False, TypeError),
  799. (target.M3, (1, ), int, False, None),
  800. (target.M3, (1, 2), int, False, None),
  801. (target.M3, (1, 2, 3), int, False, None),
  802. (target.M3, (1, 2.0), object, False, TypeError),
  803. (target.M3, (1, 'abc'), object, False, TypeError),
  804. (target.M3, (object(), userInst), object, False, None),
  805. (target.M3, ([], userList), list, False, None),
  806. # public static PythonType M4<T>(T x, params T[] args) -> pytypeof(T)
  807. (target.M4, (1, 2), int, False, None),
  808. (target.M4, (1, 2.0), object, False, TypeError),
  809. (target.M4, (1, 'abc'), object, False, TypeError),
  810. (target.M4, (object(), userInst), object, False, None),
  811. (target.M4, ([], userList), list, False, None),
  812. # simple constraints
  813. # public static PythonType M5<T>(T x) where T : class -> pytype(T)
  814. # public static PythonType M6<T>(T x) where T : struct -> pytype(T)
  815. # public static PythonType M7<T>(T x) where T : IList -> pytype(T)
  816. (target.M5, (1, ), None, False, TypeError),
  817. (target.M6, ('abc', ), None, False, TypeError),
  818. (target.M7, (object(), ), None, False, TypeError),
  819. (target.M7, (2, ), None, False, TypeError),
  820. (target.M5, ('abc', ), str, False, None),
  821. (target.M5, (object(), ), object, False, None),
  822. (target.M6, (1, ), int, False, None),
  823. (target.M7, ([], ), list, False, None),
  824. (target.M7, (objArray, ), type(objArray),False, None),
  825. # simple dependent constraints
  826. # public static PythonTuple M8<T0, T1>(T0 x, T1 y) where T0 : T1 -> (pytype(T0), pytype(T1))
  827. (target.M8, (1, 2), (int, int), False, None),
  828. (target.M8, ('abc', object()), (str, object),False, None),
  829. (target.M8, (object(), 'abc'), None, False, TypeError),
  830. (target.M8, (1, object()), (int, object),False, None),
  831. (target.M8, (object(), 1), None, False, TypeError),
  832. # no types can be inferred, error
  833. # public static PythonTuple M9<T0, T1>(object x, T1 y) where T0 : T1
  834. # public static PythonTuple M9b<T0, T1>(T0 x, object y) where T0 : T1
  835. # public static PythonType M11<T>(object x)
  836. # public static PythonType M12<T0, T1>(T0 x, object y)
  837. (target.M9, (1, 2), None, False, TypeError),
  838. (target.M9b, (1, 2), None, False, TypeError),
  839. (target.M9, (object(), object()), None, True, TypeError),
  840. (target.M9b, (object(), object()), None, True, TypeError),
  841. (target.M11, (1, ), None, False, TypeError),
  842. (target.M12, (1, 2), None, False, TypeError),
  843. # multiple dependent constraints
  844. # public static PythonTuple M10<T0, T1, T2>(T0 x, T1 y, T2 z) where T0 : T1 where T1 : T2 -> (pytype(T0), pytype(T1), pytype(T2))
  845. (target.M10, (ArgumentException(), Exception(), object()), (ArgumentException, Exception, object),False, None),
  846. (target.M10, (Exception(), ArgumentException(), object()), None,False, TypeError),
  847. (target.M10, (ArgumentException(), object(), Exception()), None,False, TypeError),
  848. (target.M10, (object(), ArgumentException(), Exception()), None,False, TypeError),
  849. (target.M10, (object(), Exception(), ArgumentException()), None,False, TypeError),
  850. # public static PythonType M11<T>(object x) -> pytypeof(T)
  851. # public static PythonType M12<T0, T1>(T0 x, object y) -> pytypeof(T0)
  852. (target.M11, (object(), ), None, True, TypeError),
  853. (target.M12, (3, object()), None, True, TypeError),
  854. # public static PythonType M13<T>(T x, Func<T> y) -> pytype(T), func()
  855. # public static PythonType M14<T>(T x, Action<T> y) -> pytype(T)
  856. # public static PythonTuple M15<T>(T x, IList<T> y) -> pytype, list...
  857. # public static PythonType M16<T>(T x, Dictionary<T, IList<T>> list) -> pytype, listKeys...
  858. (target.M13, (1, lambda: 42), (object, 42), False, None),
  859. (target.M14, (1, lambda x: None), object, False, None),
  860. (target.M15, (1, [2, ]), (object, 2), True, None),
  861. (target.M15, (1, (2, )), (object, 2), True, None),
  862. (target.M15, (1, objArray), (object, 1,2,3), True, None),
  863. (target.M15, (1, doubleArray), None, True, TypeError),
  864. (target.M16, (1, {1: [1,2]}), None, False, TypeError),
  865. # public static PythonType M17<T>(T x, IEnumerable<T> y) -> pytype(T)
  866. (target.M17, (SelfEnumerable(), SelfEnumerable()), SelfEnumerable, True, None),
  867. (target.M17, (1, [1,2,3]), object, True, None),
  868. (target.M17, (1.0, [1,2,3]), object,

Large files files are truncated, but you can click here to view the full file