PageRenderTime 56ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/IronPython_Main/Languages/IronPython/Tests/interop/net/derivation/test_simplederive.py

#
Python | 138 lines | 75 code | 30 blank | 33 comment | 0 complexity | 8294c1c14348f171294b24363568eaa0 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  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. Create a Python class which derives from CLR type(s).
  17. '''
  18. #------------------------------------------------------------------------------
  19. from iptest.assert_util import *
  20. skiptest("silverlight")
  21. add_clr_assemblies("baseclasscs", "typesamples")
  22. from Merlin.Testing import *
  23. from Merlin.Testing.BaseClass import *
  24. import System
  25. def test_simply_derive():
  26. class C(EmptyClass): pass
  27. class C(EmptyTypeGroup2): pass
  28. class C(EmptyGenericClass[int]): pass
  29. class C(IEmpty): pass
  30. class C(IGenericEmpty[int]): pass
  31. class C(AbstractEmptyClass): pass
  32. class C(INotEmpty): pass
  33. class C(AbstractNotEmptyClass): pass
  34. #class C(EmptyDelegate): pass
  35. class C(System.Double): pass
  36. def test_multiple_typegroup():
  37. class C(IInterfaceGroup1, IInterfaceGroup2): pass
  38. class C(IInterfaceGroup1, IInterfaceGroup2, EmptyClass): pass
  39. class C(EmptyTypeGroup2, IInterfaceGroup1, IInterfaceGroup2): pass
  40. class C(EmptyTypeGroup2, IInterfaceGroup1[int], IInterfaceGroup2): pass
  41. def test_negative_simply_derive():
  42. # value type, sealed ref type
  43. def f1():
  44. class C(EmptyStruct): pass
  45. def f2():
  46. class C(EmptyEnum): pass
  47. def f3():
  48. class C(SealedClass): pass
  49. def f4():
  50. class C(System.Single): pass
  51. AssertErrorWithMessage(TypeError, "cannot derive from Merlin.Testing.BaseClass.EmptyStruct because it is a value type", f1)
  52. AssertErrorWithMessage(TypeError, "cannot derive from Merlin.Testing.BaseClass.EmptyEnum because it is a value type", f2)
  53. AssertErrorWithMessage(TypeError, "cannot derive from Merlin.Testing.BaseClass.SealedClass because it is sealed", f3)
  54. AssertErrorWithMessage(TypeError, "cannot derive from System.Single because it is a value type", f4)
  55. # open generic
  56. def f():
  57. class C(EmptyGenericClass): pass
  58. AssertErrorWithMessage(TypeError,
  59. "C: cannot inhert from open generic instantiation IronPython.Runtime.Types.PythonType. Only closed instantiations are supported.",
  60. f)
  61. def f():
  62. class C(IGenericEmpty): pass
  63. AssertErrorWithMessage(TypeError,
  64. "C: cannot inhert from open generic instantiation Merlin.Testing.BaseClass.IGenericEmpty`1[T]. Only closed instantiations are supported.",
  65. f)
  66. def f():
  67. class C(EmptyTypeGroup1): pass
  68. AssertErrorWithMessage(TypeError,
  69. "cannot derive from open generic types <types 'EmptyTypeGroup1[T]', 'EmptyTypeGroup1[K, V]'>",
  70. f)
  71. # too many base (same or diff)
  72. def f():
  73. class C(EmptyClass, EmptyClass): pass
  74. AssertErrorWithMessage(TypeError, "duplicate base class EmptyClass", f)
  75. def f():
  76. class C(IEmpty, EmptyClass, IEmpty): pass
  77. AssertErrorWithMessage(TypeError, "duplicate base class IEmpty", f)
  78. def f():
  79. class C(EmptyClass, EmptyGenericClass[int]): pass
  80. AssertErrorWithMessage(TypeError,
  81. "C: can only extend one CLI or builtin type, not both Merlin.Testing.BaseClass.EmptyClass (for IronPython.Runtime.Types.PythonType) and Merlin.Testing.BaseClass.EmptyGenericClass`1[[System.Int32, mscorlib, Version=%d.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] (for IronPython.Runtime.Types.PythonType)" % System.Environment.Version.Major,
  82. f)
  83. class B:pass
  84. b = B()
  85. def f():
  86. class C(object, b): pass
  87. AssertErrorWithPartialMessage(TypeError,
  88. "metaclass conflict instance and type",
  89. f)
  90. def f():
  91. class C(EmptyGenericClass[()]): pass
  92. AssertError(ValueError, f)
  93. def test_system_type_cs0644():
  94. # http://msdn2.microsoft.com/en-us/library/hxds244y(VS.80).aspx
  95. # bug 363984
  96. #class C(System.Delegate): pass
  97. #class C(System.Array): pass
  98. #class C(System.ValueType): pass
  99. #class C(System.Enum): pass
  100. pass
  101. def test_mbr():
  102. class C(System.MarshalByRefObject): pass
  103. #class C('abc'): pass
  104. # scenarios
  105. # C derive from interface I, D derive from C and I (again)
  106. # interface's base types: interfaces (implement them)
  107. # ctor: params/param_dict
  108. run_test(__name__)