PageRenderTime 42ms CodeModel.GetById 36ms app.highlight 4ms RepoModel.GetById 1ms 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
  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'''
 16Create a Python class which derives from CLR type(s).
 17'''
 18#------------------------------------------------------------------------------
 19
 20from iptest.assert_util import *
 21skiptest("silverlight")
 22
 23add_clr_assemblies("baseclasscs", "typesamples")
 24
 25from Merlin.Testing import *
 26from Merlin.Testing.BaseClass import *
 27import System
 28
 29def test_simply_derive():
 30    class C(EmptyClass): pass
 31    class C(EmptyTypeGroup2): pass
 32    class C(EmptyGenericClass[int]): pass
 33    class C(IEmpty): pass
 34    class C(IGenericEmpty[int]): pass
 35    class C(AbstractEmptyClass): pass
 36
 37    class C(INotEmpty): pass
 38    class C(AbstractNotEmptyClass): pass
 39    
 40    #class C(EmptyDelegate): pass
 41    
 42    class C(System.Double): pass
 43
 44def test_multiple_typegroup():
 45    class C(IInterfaceGroup1, IInterfaceGroup2): pass
 46    class C(IInterfaceGroup1, IInterfaceGroup2, EmptyClass): pass
 47    class C(EmptyTypeGroup2, IInterfaceGroup1, IInterfaceGroup2): pass    
 48    class C(EmptyTypeGroup2, IInterfaceGroup1[int], IInterfaceGroup2): pass    
 49    
 50def test_negative_simply_derive():
 51    # value type, sealed ref type
 52    def f1():
 53        class C(EmptyStruct): pass
 54    def f2():
 55        class C(EmptyEnum): pass
 56    def f3():
 57        class C(SealedClass): pass
 58    def f4():
 59        class C(System.Single): pass
 60
 61    
 62    AssertErrorWithMessage(TypeError, "cannot derive from Merlin.Testing.BaseClass.EmptyStruct because it is a value type", f1)
 63    AssertErrorWithMessage(TypeError, "cannot derive from Merlin.Testing.BaseClass.EmptyEnum because it is a value type", f2)
 64    AssertErrorWithMessage(TypeError, "cannot derive from Merlin.Testing.BaseClass.SealedClass because it is sealed", f3)
 65    AssertErrorWithMessage(TypeError, "cannot derive from System.Single because it is a value type", f4)
 66
 67    # open generic
 68    def f():
 69        class C(EmptyGenericClass): pass
 70    AssertErrorWithMessage(TypeError, 
 71        "C: cannot inhert from open generic instantiation IronPython.Runtime.Types.PythonType. Only closed instantiations are supported.",
 72        f)
 73    
 74    def f():
 75        class C(IGenericEmpty): pass
 76    AssertErrorWithMessage(TypeError, 
 77        "C: cannot inhert from open generic instantiation Merlin.Testing.BaseClass.IGenericEmpty`1[T]. Only closed instantiations are supported.",
 78        f)
 79    
 80    def f():
 81        class C(EmptyTypeGroup1): pass
 82    AssertErrorWithMessage(TypeError, 
 83        "cannot derive from open generic types <types 'EmptyTypeGroup1[T]', 'EmptyTypeGroup1[K, V]'>",
 84        f)
 85
 86    # too many base (same or diff)
 87    def f():    
 88        class C(EmptyClass, EmptyClass): pass
 89    AssertErrorWithMessage(TypeError, "duplicate base class EmptyClass", f)
 90   
 91    def f():
 92        class C(IEmpty, EmptyClass, IEmpty): pass
 93    AssertErrorWithMessage(TypeError, "duplicate base class IEmpty", f)
 94                            
 95    def f():
 96        class C(EmptyClass, EmptyGenericClass[int]): pass
 97    AssertErrorWithMessage(TypeError, 
 98        "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,
 99        f)
100    
101    class B:pass
102    b = B()
103    def f(): 
104        class C(object, b): pass
105    AssertErrorWithPartialMessage(TypeError, 
106        "metaclass conflict instance and type",
107        f)
108    
109    def f():
110        class C(EmptyGenericClass[()]): pass
111    AssertError(ValueError, f)
112    
113def test_system_type_cs0644():
114    # http://msdn2.microsoft.com/en-us/library/hxds244y(VS.80).aspx
115    # bug 363984
116    #class C(System.Delegate): pass
117    #class C(System.Array): pass
118    #class C(System.ValueType): pass
119    #class C(System.Enum): pass
120    pass
121
122
123def test_mbr():
124    class C(System.MarshalByRefObject): pass
125
126    #class C('abc'): pass
127
128
129# scenarios
130# C derive from interface I, D derive from C and I (again)
131
132# interface's base types: interfaces (implement them)
133# ctor: params/param_dict
134
135
136
137run_test(__name__)
138