[Zope-CVS] CVS: PythonNet/tests/python - test_array.py:1.3
test_class.py:1.6 test_conversion.py:1.4 test_delegate.py:1.5
test_enum.py:1.2 test_event.py:1.3 test_exceptions.py:1.3
test_field.py:1.2 test_indexer.py:1.3 test_interface.py:1.2
test_method.py:1.2 test_module.py:1.2 test_property.py:1.2
Brian Lloyd
brian at zope.com
Tue Oct 7 22:29:19 EDT 2003
Update of /cvs-repository/PythonNet/tests/python
In directory cvs.zope.org:/tmp/cvs-serv8705/tests/python
Modified Files:
test_array.py test_class.py test_conversion.py
test_delegate.py test_enum.py test_event.py test_exceptions.py
test_field.py test_indexer.py test_interface.py test_method.py
test_module.py test_property.py
Log Message:
Finally finished event / delegate tests, refactoring and fixing. Now
its a race to see if I can get out a preview 3 before the baby comes ;)
=== PythonNet/tests/python/test_array.py 1.2 => 1.3 ===
--- PythonNet/tests/python/test_array.py:1.2 Tue Sep 30 19:54:13 2003
+++ PythonNet/tests/python/test_array.py Tue Oct 7 22:29:18 2003
@@ -12,6 +12,7 @@
import sys, os, string, unittest, types
import CLR.Python.Test as Test
+
class ArrayTests(unittest.TestCase):
"""Test support for managed arrays."""
=== PythonNet/tests/python/test_class.py 1.5 => 1.6 ===
--- PythonNet/tests/python/test_class.py:1.5 Tue Sep 30 19:54:13 2003
+++ PythonNet/tests/python/test_class.py Tue Oct 7 22:29:18 2003
@@ -16,15 +16,6 @@
import CLR.System as System
-class ClassicClass:
- def kind(self):
- return 'classic'
-
-class NewStyleClass(object):
- def kind(self):
- return 'new-style'
-
-
class ClassTests(unittest.TestCase):
"""Test CLR class support."""
@@ -33,11 +24,13 @@
String = System.String
self.assertEquals(String.Empty, "")
+
def testBasicValueType(self):
"""Test usage of CLR defined value types."""
Int32 = System.Int32
self.assertEquals(Int32.MaxValue, 2147483647)
+
def testClassStandardAttrs(self):
"""Test standard class attributes."""
self.failUnless(ClassTest.__name__ == 'ClassTest')
@@ -45,6 +38,7 @@
self.failUnless(type(ClassTest.__dict__) == types.DictProxyType)
self.failUnless(ClassTest.__doc__ == None)
+
def testNonPublicClass(self):
"""Test that non-public classes are inaccessible."""
from CLR.Python import Test
@@ -59,6 +53,7 @@
self.failUnlessRaises(AttributeError, test)
+
def testBasicSubclass(self):
"""Test basic subclass of a managed class."""
@@ -122,6 +117,7 @@
self.failUnless(table.Count == 3)
+
def testOverrideSetItem(self):
"""Test managed subclass overriding __setitem__."""
@@ -143,6 +139,15 @@
self.failUnless(table.Count == 3)
+
+
+class ClassicClass:
+ def kind(self):
+ return 'classic'
+
+class NewStyleClass(object):
+ def kind(self):
+ return 'new-style'
=== PythonNet/tests/python/test_conversion.py 1.3 => 1.4 ===
--- PythonNet/tests/python/test_conversion.py:1.3 Mon Jul 28 22:28:26 2003
+++ PythonNet/tests/python/test_conversion.py Tue Oct 7 22:29:18 2003
@@ -13,6 +13,7 @@
from CLR.Python.Test import ConversionTest
from CLR import System
+
class ConversionTests(unittest.TestCase):
"""Test CLR <-> Python type conversions."""
@@ -39,6 +40,7 @@
object.BooleanField = System.Boolean('a')
self.failUnless(object.BooleanField == 1)
+
def testSByteConversion(self):
"""Test sbyte conversion."""
self.failUnless(System.SByte.MaxValue == 127)
@@ -89,6 +91,7 @@
self.failUnlessRaises(OverflowError, test)
+
def testByteConversion(self):
"""Test byte conversion."""
self.failUnless(System.Byte.MaxValue == 255)
@@ -139,6 +142,7 @@
self.failUnlessRaises(OverflowError, test)
+
def testCharConversion(self):
"""Test char conversion."""
self.failUnless(System.Char.MaxValue == unichr(65535))
@@ -222,6 +226,7 @@
self.failUnlessRaises(OverflowError, test)
+
def testInt32Conversion(self):
"""Test int32 conversion."""
self.failUnless(System.Int32.MaxValue == 2147483647)
@@ -272,6 +277,7 @@
self.failUnlessRaises(OverflowError, test)
+
def testInt64Conversion(self):
"""Test int64 conversion."""
self.failUnless(System.Int64.MaxValue == 9223372036854775807L)
@@ -322,6 +328,7 @@
self.failUnlessRaises(OverflowError, test)
+
def testUInt16Conversion(self):
"""Test uint16 conversion."""
self.failUnless(System.UInt16.MaxValue == 65535)
@@ -372,6 +379,7 @@
self.failUnlessRaises(OverflowError, test)
+
def testUInt32Conversion(self):
"""Test uint32 conversion."""
self.failUnless(System.UInt32.MaxValue == 4294967295L)
@@ -422,6 +430,7 @@
self.failUnlessRaises(OverflowError, test)
+
def testUInt64Conversion(self):
"""Test uint64 conversion."""
self.failUnless(System.UInt64.MaxValue == 18446744073709551615L)
@@ -472,6 +481,7 @@
self.failUnlessRaises(OverflowError, test)
+
def testSingleConversion(self):
"""Test single conversion."""
self.failUnless(System.Single.MaxValue == 3.402823e38)
@@ -522,6 +532,7 @@
self.failUnlessRaises(OverflowError, test)
+
def testDoubleConversion(self):
"""Test double conversion."""
self.failUnless(System.Double.MaxValue == 1.7976931348623157e308)
@@ -572,6 +583,7 @@
self.failUnlessRaises(OverflowError, test)
+
def testDecimalConversion(self):
"""Test decimal conversion."""
from CLR.System import Decimal
@@ -648,6 +660,7 @@
self.failUnlessRaises(TypeError, test)
+
def testInterfaceConversion(self):
"""Test interface conversion."""
from CLR.Python.Test import Spam
@@ -678,6 +691,7 @@
self.failUnlessRaises(TypeError, test)
+
def testObjectConversion(self):
"""Test object conversion."""
from CLR.Python.Test import Spam
@@ -706,6 +720,7 @@
self.failUnlessRaises(TypeError, test)
+
def testEnumConversion(self):
"""Test enum conversion."""
from CLR.Python.Test import ShortEnum
@@ -747,6 +762,7 @@
object.EnumField = "spam"
self.failUnlessRaises(TypeError, test)
+
def testNullConversion(self):
"""Test null conversion."""
=== PythonNet/tests/python/test_delegate.py 1.4 => 1.5 ===
--- PythonNet/tests/python/test_delegate.py:1.4 Wed Jul 30 09:59:01 2003
+++ PythonNet/tests/python/test_delegate.py Tue Oct 7 22:29:18 2003
@@ -15,6 +15,7 @@
import CLR.Python.Test as Test
import CLR.System as System
+
class DelegateTests(unittest.TestCase):
"""Test CLR delegate support."""
@@ -25,9 +26,11 @@
self.failUnless(type(PublicDelegate.__dict__) == types.DictProxyType)
self.failUnless(PublicDelegate.__doc__ == None)
+
def testGlobalDelegateVisibility(self):
"""Test visibility of module-level delegates."""
from CLR.Python.Test import PublicDelegate
+
self.failUnless(PublicDelegate.__name__ == 'PublicDelegate')
self.failUnless(Test.PublicDelegate.__name__ == 'PublicDelegate')
@@ -41,6 +44,7 @@
self.failUnlessRaises(AttributeError, test)
+
def testNestedDelegateVisibility(self):
"""Test visibility of nested delegates."""
ob = DelegateTest.PublicDelegate
@@ -59,6 +63,7 @@
self.failUnlessRaises(AttributeError, test)
+
def testDelegateFromFunction(self):
"""Test delegate implemented with a Python function."""
@@ -75,6 +80,7 @@
self.failUnless(ob.CallStringDelegate(ob.stringDelegate) == "hello")
self.failUnless(ob.stringDelegate() == "hello")
+
def testDelegateFromMethod(self):
"""Test delegate implemented with a Python instance method."""
@@ -93,6 +99,7 @@
self.failUnless(ob.CallStringDelegate(ob.stringDelegate) == "hello")
self.failUnless(ob.stringDelegate() == "hello")
+
def testDelegateFromUnboundMethod(self):
"""Test failure mode for unbound methods."""
@@ -106,6 +113,7 @@
self.failUnlessRaises(TypeError, test)
+
def testDelegateFromStaticMethod(self):
"""Test delegate implemented with a Python static method."""
@@ -135,6 +143,7 @@
self.failUnless(ob.CallStringDelegate(ob.stringDelegate) == "hello")
self.failUnless(ob.stringDelegate() == "hello")
+
def testDelegateFromClassMethod(self):
"""Test delegate implemented with a Python class method."""
@@ -164,6 +173,7 @@
self.failUnless(ob.CallStringDelegate(ob.stringDelegate) == "hello")
self.failUnless(ob.stringDelegate() == "hello")
+
def testDelegateFromCallable(self):
"""Test delegate implemented with a Python callable object."""
@@ -182,6 +192,7 @@
self.failUnless(ob.CallStringDelegate(ob.stringDelegate) == "hello")
self.failUnless(ob.stringDelegate() == "hello")
+
def testDelegateFromManagedInstanceMethod(self):
"""Test delegate implemented with a managed instance method."""
ob = DelegateTest()
@@ -194,6 +205,7 @@
self.failUnless(ob.CallStringDelegate(ob.stringDelegate) == "hello")
self.failUnless(ob.stringDelegate() == "hello")
+
def testDelegateFromManagedStaticMethod(self):
"""Test delegate implemented with a managed static method."""
d = StringDelegate(DelegateTest.StaticSayHello)
@@ -206,6 +218,7 @@
self.failUnless(ob.CallStringDelegate(ob.stringDelegate) == "hello")
self.failUnless(ob.stringDelegate() == "hello")
+
def testDelegateFromDelegate(self):
"""Test delegate implemented with another delegate."""
@@ -223,17 +236,6 @@
self.failUnless(ob.CallStringDelegate(ob.stringDelegate) == "hello")
self.failUnless(ob.stringDelegate() == "hello")
- # test async delegates
-
- # test d as event handler
-
- # test multicast delegates
-
- # test explicit op_
-
- # test sig mismatch, both on managed and Python side
-
- # test return wrong type
def testDelegateWithInvalidArgs(self):
"""Test delegate instantiation with invalid (non-callable) args."""
@@ -253,6 +255,31 @@
self.failUnlessRaises(TypeError, test)
+ def testMulticastDelegate(self):
+ """Test multicast delegates."""
+
+ class Multi:
+ def __init__(self):
+ self.value = 0
+
+ def count(self):
+ self.value += 1
+ return 'ok'
+
+ inst = Multi()
+ d1 = StringDelegate(inst.count)
+ d2 = StringDelegate(inst.count)
+
+ md = System.Delegate.Combine(d1, d2)
+ ob = DelegateTest()
+
+ self.failUnless(ob.CallStringDelegate(md) == "ok")
+ self.failUnless(inst.value == 2)
+
+ self.failUnless(md() == "ok")
+ self.failUnless(inst.value == 4)
+
+
def testSubclassDelegateFails(self):
"""Test that subclassing of a delegate type fails."""
def test():
@@ -261,6 +288,7 @@
self.failUnlessRaises(TypeError, test)
+
def testDelegateEquality(self):
"""Test delegate equality."""
@@ -272,7 +300,18 @@
ob.stringDelegate = d
self.failUnless(ob.stringDelegate == d)
-
+
+ # test async delegates
+
+ # test multicast delegates
+
+ # test explicit op_
+
+ # test sig mismatch, both on managed and Python side
+
+ # test return wrong type
+
+
def test_suite():
return unittest.makeSuite(DelegateTests)
=== PythonNet/tests/python/test_enum.py 1.1 => 1.2 ===
--- PythonNet/tests/python/test_enum.py:1.1 Mon Feb 17 22:44:38 2003
+++ PythonNet/tests/python/test_enum.py Tue Oct 7 22:29:18 2003
@@ -13,6 +13,7 @@
from CLR.System import DayOfWeek
from CLR.Python import Test
+
class EnumTests(unittest.TestCase):
"""Test CLR enum support."""
@@ -23,6 +24,7 @@
self.failUnless(type(DayOfWeek.__dict__) == types.DictProxyType)
self.failUnless(DayOfWeek.__doc__ == None)
+
def testEnumGetMember(self):
"""Test access to enum members."""
self.failUnless(DayOfWeek.Sunday == 0)
@@ -33,54 +35,63 @@
self.failUnless(DayOfWeek.Friday == 5)
self.failUnless(DayOfWeek.Saturday == 6)
+
def testByteEnum(self):
"""Test byte enum."""
self.failUnless(Test.ByteEnum.Zero == 0)
self.failUnless(Test.ByteEnum.One == 1)
self.failUnless(Test.ByteEnum.Two == 2)
+
def testSByteEnum(self):
"""Test sbyte enum."""
self.failUnless(Test.SByteEnum.Zero == 0)
self.failUnless(Test.SByteEnum.One == 1)
self.failUnless(Test.SByteEnum.Two == 2)
+
def testShortEnum(self):
"""Test short enum."""
self.failUnless(Test.ShortEnum.Zero == 0)
self.failUnless(Test.ShortEnum.One == 1)
self.failUnless(Test.ShortEnum.Two == 2)
+
def testUShortEnum(self):
"""Test ushort enum."""
self.failUnless(Test.UShortEnum.Zero == 0)
self.failUnless(Test.UShortEnum.One == 1)
self.failUnless(Test.UShortEnum.Two == 2)
+
def testIntEnum(self):
"""Test int enum."""
self.failUnless(Test.IntEnum.Zero == 0)
self.failUnless(Test.IntEnum.One == 1)
self.failUnless(Test.IntEnum.Two == 2)
+
def testUIntEnum(self):
"""Test uint enum."""
self.failUnless(Test.UIntEnum.Zero == 0L)
self.failUnless(Test.UIntEnum.One == 1L)
self.failUnless(Test.UIntEnum.Two == 2L)
+
def testLongEnum(self):
"""Test long enum."""
self.failUnless(Test.LongEnum.Zero == 0L)
self.failUnless(Test.LongEnum.One == 1L)
self.failUnless(Test.LongEnum.Two == 2L)
+
def testULongEnum(self):
"""Test ulong enum."""
self.failUnless(Test.ULongEnum.Zero == 0L)
self.failUnless(Test.ULongEnum.One == 1L)
self.failUnless(Test.ULongEnum.Two == 2L)
+
def testInstantiateEnumFails(self):
"""Test that instantiation of an enum class fails."""
def test():
@@ -88,6 +99,7 @@
self.failUnlessRaises(TypeError, test)
+
def testSubclassEnumFails(self):
"""Test that subclassing of an enumeration fails."""
def test():
@@ -96,6 +108,7 @@
self.failUnlessRaises(TypeError, test)
+
def testEnumSetMemberFails(self):
"""Test that setattr operations on enumerations fail."""
def test():
@@ -108,6 +121,7 @@
self.failUnlessRaises(TypeError, test)
+
def testEnumWithFlagsAttrConversion(self):
"""Test enumeration conversion with FlagsAttribute set."""
from CLR.System.Windows.Forms import Label
@@ -121,6 +135,7 @@
Test.FieldTest().EnumField = 99
self.failUnlessRaises(ValueError, test)
+
def testEnumConversion(self):
"""Test enumeration conversion."""
=== PythonNet/tests/python/test_event.py 1.2 => 1.3 ===
--- PythonNet/tests/python/test_event.py:1.2 Thu Oct 2 23:06:20 2003
+++ PythonNet/tests/python/test_event.py Tue Oct 7 22:29:18 2003
@@ -10,8 +10,9 @@
# FOR A PARTICULAR PURPOSE.
import sys, os, string, unittest, types
+from CLR.Python.Test import EventTest, TestEventHandler
from CLR.Python.Test import TestEventArgs
-from CLR.Python.Test import EventTest
+
class EventTests(unittest.TestCase):
"""Test CLR event support."""
@@ -116,13 +117,13 @@
object.PublicEvent += handler2.handler
object.PublicEvent += handler3.handler
- object.FireEvent(object, TestEventArgs(10))
+ object.PublicEvent(object, TestEventArgs(10))
self.failUnless(handler1.value == 10)
self.failUnless(handler2.value == 10)
self.failUnless(handler3.value == 10)
- object.FireEvent(object, TestEventArgs(20))
+ object.PublicEvent(object, TestEventArgs(20))
self.failUnless(handler1.value == 20)
self.failUnless(handler2.value == 20)
@@ -133,12 +134,12 @@
"""Test conditional firing of events."""
object = EventTest()
- if (object.PublicEvent != None):
- empty = 0
- else:
- empty = 1
+ self.failIf(object.PublicEvent)
- self.failUnless(empty == 1)
+ handler = GenericHandler()
+ object.PublicEvent += handler.handler
+
+ self.failUnless(object.PublicEvent)
def testIndirectFireEvent(self):
@@ -173,13 +174,260 @@
# before invoking it. From Python, an event never appears to be
# null, because we create descriptors to represent declared events.
- # This check just ensures that the runtime is effectively turning
- # an invokation of a null event into a no-op - if it is not handled
- # correctly, the process should bail with a NullReferenceException.
+ # Event descriptors do support __nonzero__, which allows you to
+ # check for an empty event from Python using 'if event:'.
object = EventTest()
object.PublicEvent(object, TestEventArgs(10))
+ if object.PublicEvent:
+ raise ValueError, 'Event descriptor should evaluate false'
+
+ handler = GenericHandler()
+ object.PublicEvent += handler.handler
+
+ if not object.PublicEvent:
+ raise ValueError, 'Event descriptor should evaluate true'
+
+
+ def testInstanceMethodHandler(self):
+ """Test instance method handlers."""
+ object = EventTest()
+ handler = GenericHandler()
+
+ object.PublicEvent += handler.handler
+ self.failUnless(handler.value == None)
+
+ object.PublicEvent(object, TestEventArgs(10))
+ self.failUnless(handler.value == 10)
+
+ object.PublicEvent -= handler.handler
+ self.failUnless(handler.value == 10)
+
+ object.PublicEvent(object, TestEventArgs(20))
+ self.failUnless(handler.value == 10)
+
+
+ def testVarArgsInstanceMethodHandler(self):
+ """Test vararg instance method handlers."""
+ object = EventTest()
+ handler = VariableArgsHandler()
+
+ object.PublicEvent += handler.handler
+ self.failUnless(handler.value == None)
+
+ object.PublicEvent(object, TestEventArgs(10))
+ self.failUnless(handler.value == 10)
+
+ object.PublicEvent -= handler.handler
+ self.failUnless(handler.value == 10)
+
+ object.PublicEvent(object, TestEventArgs(20))
+ self.failUnless(handler.value == 10)
+
+
+ def testCallableObjectHandler(self):
+ """Test callable object handlers."""
+ object = EventTest()
+ handler = CallableHandler()
+
+ object.PublicEvent += handler
+ self.failUnless(handler.value == None)
+
+ object.PublicEvent(object, TestEventArgs(10))
+ self.failUnless(handler.value == 10)
+
+ object.PublicEvent -= handler
+ self.failUnless(handler.value == 10)
+
+ object.PublicEvent(object, TestEventArgs(20))
+ self.failUnless(handler.value == 10)
+
+
+ def testVarArgsCallableHandler(self):
+ """Test varargs callable handlers."""
+ object = EventTest()
+ handler = VarCallableHandler()
+
+ object.PublicEvent += handler
+ self.failUnless(handler.value == None)
+
+ object.PublicEvent(object, TestEventArgs(10))
+ self.failUnless(handler.value == 10)
+
+ object.PublicEvent -= handler
+ self.failUnless(handler.value == 10)
+
+ object.PublicEvent(object, TestEventArgs(20))
+ self.failUnless(handler.value == 10)
+
+
+ def testStaticMethodHandler(self):
+ """Test static method handlers."""
+ object = EventTest()
+ handler = StaticMethodHandler()
+
+ object.PublicEvent += handler.handler
+ self.failUnless(handler.value == None)
+
+ object.PublicEvent(object, TestEventArgs(10))
+ self.failUnless(handler.value == 10)
+
+ object.PublicEvent -= handler.handler
+ self.failUnless(handler.value == 10)
+
+ object.PublicEvent(object, TestEventArgs(20))
+ self.failUnless(handler.value == 10)
+
+
+ def testClassMethodHandler(self):
+ """Test class method handlers."""
+ object = EventTest()
+ handler = ClassMethodHandler()
+
+ object.PublicEvent += handler.handler
+ self.failUnless(handler.value == None)
+
+ object.PublicEvent(object, TestEventArgs(10))
+ self.failUnless(handler.value == 10)
+
+ object.PublicEvent -= handler.handler
+ self.failUnless(handler.value == 10)
+
+ object.PublicEvent(object, TestEventArgs(20))
+ self.failUnless(handler.value == 10)
+
+
+ def testManagedInstanceMethodHandler(self):
+ """Test managed instance method handlers."""
+ object = EventTest()
+
+ object.PublicEvent += object.GenericHandler
+ self.failUnless(object.value == 0)
+
+ object.PublicEvent(object, TestEventArgs(10))
+ self.failUnless(object.value == 10)
+
+ object.PublicEvent -= object.GenericHandler
+ self.failUnless(object.value == 10)
+
+ object.PublicEvent(object, TestEventArgs(20))
+ self.failUnless(object.value == 10)
+
+
+ def testManagedStaticMethodHandler(self):
+ """Test managed static method handlers."""
+ object = EventTest()
+
+ object.PublicEvent += object.StaticHandler
+ self.failUnless(EventTest.s_value == 0)
+
+ object.PublicEvent(object, TestEventArgs(10))
+ self.failUnless(EventTest.s_value == 10)
+
+ object.PublicEvent -= object.StaticHandler
+ self.failUnless(EventTest.s_value == 10)
+
+ object.PublicEvent(object, TestEventArgs(20))
+ self.failUnless(EventTest.s_value == 10)
+
+
+ def testUnboundMethodHandler(self):
+ """Test failure mode for unbound method handlers."""
+
+ def test():
+ object = EventTest()
+ object.PublicEvent += GenericHandler.handler
+ object.PublicEvent(object, TestEventArgs(10))
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testFunctionHandler(self):
+ """Test function handlers."""
+ object = EventTest()
+ dict = {'value':None}
+
+ def handler(sender, args, dict=dict):
+ dict['value'] = args.value
+
+ object.PublicEvent += handler
+ self.failUnless(dict['value'] == None)
+
+ object.PublicEvent(object, TestEventArgs(10))
+ self.failUnless(dict['value'] == 10)
+
+ object.PublicEvent -= handler
+ self.failUnless(dict['value'] == 10)
+
+ object.PublicEvent(object, TestEventArgs(20))
+ self.failUnless(dict['value'] == 10)
+
+
+ def testAddNonCallableHandler(self):
+ """Test handling of attempts to add non-callable handlers."""
+
+ def test():
+ object = EventTest()
+ object.PublicEvent += 10
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = EventTest()
+ object.PublicEvent += "spam"
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+
+ class spam:
+ pass
+
+ object = EventTest()
+ object.PublicEvent += spam()
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testRemoveUnknownHandler(self):
+ """Test removing an event handler that was never added."""
+ def test():
+ object = EventTest()
+ handler = GenericHandler()
+
+ object.PublicEvent -= handler.handler
+
+ self.failUnlessRaises(ValueError, test)
+
+
+ def testHandlerCallbackFailure(self):
+ """Test failure mode for inappropriate handlers."""
+
+ class BadHandler:
+ def handler(self, one):
+ return 'too many'
+
+ def test():
+ object = EventTest()
+ handler = BadHandler()
+ object.PublicEvent += handler.handler
+ object.PublicEvent(object, TestEventArgs(10))
+
+ self.failUnlessRaises(TypeError, test)
+
+ class BadHandler:
+ def handler(self, one, two, three, four, five):
+ return 'not enough'
+
+ def test():
+ object = EventTest()
+ handler = BadHandler()
+ object.PublicEvent += handler.handler
+ object.PublicEvent(object, TestEventArgs(10))
+
+ self.failUnlessRaises(TypeError, test)
+
def testIncorrectInvokation(self):
"""Test incorrect invokation of events."""
@@ -188,44 +436,46 @@
handler = GenericHandler()
object.PublicEvent += handler.handler
- object.PublicEvent(32)
-
def test():
object.PublicEvent()
- self.failUnlessRaises(ValueError, test)
+ self.failUnlessRaises(TypeError, test)
def test():
- EventTest().PublicEvent(32)
+ object.PublicEvent(32)
- self.failUnlessRaises(ValueError, test)
+ self.failUnlessRaises(TypeError, test)
- def testRemoveEventHandlers(self):
- """Test removal of event handlers."""
+ def testExplicitCLSEventRegistration(self):
+ """Test explicit CLS event registration."""
object = EventTest()
+ handler = GenericHandler()
- handler1 = GenericHandler()
- handler2 = GenericHandler()
+ delegate = TestEventHandler(handler.handler)
+ object.add_PublicEvent(delegate)
+ self.failUnless(handler.value == None)
- object.PublicEvent += handler1.handler
- object.PublicEvent += handler2.handler
-
- object.FireEvent(object, TestEventArgs(10))
-
- self.failUnless(handler1.value == 10)
- self.failUnless(handler2.value == 10)
+ object.PublicEvent(object, TestEventArgs(10))
+ self.failUnless(handler.value == 10)
- object.PublicEvent -= handler2.handler
+ object.remove_PublicEvent(delegate)
+ self.failUnless(handler.value == 10)
- object.PublicEvent(TestEventArgs(20))
-
- self.failUnless(handler1.value == 20)
- self.failUnless(handler2.value == 10)
+ object.PublicEvent(object, TestEventArgs(20))
+ self.failUnless(handler.value == 10)
+ def testImplicitCLSEventRegistration(self):
+ """Test implicit CLS event registration."""
+
+ def test():
+ object = EventTest()
+ handler = GenericHandler()
+ object.add_PublicEvent(handler.handler)
+
+ self.failUnlessRaises(TypeError, test)
-# test different kinds of callables
def testEventDescriptorAbuse(self):
"""Test event descriptor abuse."""
@@ -253,13 +503,6 @@
self.failUnlessRaises(TypeError, test)
- def testCrash(self):
- """Test crash."""
- desc = EventTest.__dict__['PublicEvent']
- evil = desc.__get__(0, 0)
- evil()
-
-
class GenericHandler:
"""A generic handler to test event callbacks."""
@@ -268,6 +511,59 @@
def handler(self, sender, args):
self.value = args.value
+
+
+class VariableArgsHandler:
+ """A variable args handler to test event callbacks."""
+ def __init__(self):
+ self.value = None
+
+ def handler(self, *args):
+ ob, eventargs = args
+ self.value = eventargs.value
+
+
+class CallableHandler:
+ """A callable handler to test event callbacks."""
+ def __init__(self):
+ self.value = None
+
+ def __call__(self, sender, args):
+ self.value = args.value
+
+
+class VarCallableHandler:
+ """A variable args callable handler to test event callbacks."""
+ def __init__(self):
+ self.value = None
+
+ def __call__(self, *args):
+ ob, eventargs = args
+ self.value = eventargs.value
+
+
+class StaticMethodHandler(object):
+ """A static method handler to test event callbacks."""
+
+ value = None
+
+ def handler(sender, args):
+ StaticMethodHandler.value = args.value
+
+ handler = staticmethod(handler)
+
+
+class ClassMethodHandler(object):
+ """A class method handler to test event callbacks."""
+
+ value = None
+
+ def handler(cls, sender, args):
+ cls.value = args.value
+
+ handler = classmethod(handler)
+
+
=== PythonNet/tests/python/test_exceptions.py 1.2 => 1.3 ===
--- PythonNet/tests/python/test_exceptions.py:1.2 Thu Jul 24 19:55:11 2003
+++ PythonNet/tests/python/test_exceptions.py Tue Oct 7 22:29:18 2003
@@ -36,6 +36,7 @@
self.failUnless(type is NullReferenceException)
self.failUnless(isinstance(value, NullReferenceException))
+
def testRaiseClassExceptionWithValue(self):
"""Test class exception propagation with associated value."""
from CLR.System import NullReferenceException
@@ -53,6 +54,7 @@
self.failUnless(isinstance(value, NullReferenceException))
self.failUnless(value.Message == 'Aiiieee!')
+
def testRaiseInstanceException(self):
"""Test instance exception propagation."""
from CLR.System import NullReferenceException
@@ -70,6 +72,7 @@
self.failUnless(isinstance(value, NullReferenceException))
self.failUnless(value.Message == '')
+
def testRaiseInstanceExceptionWithArgs(self):
"""Test instance exception propagation with args."""
from CLR.System import NullReferenceException
@@ -87,6 +90,7 @@
self.failUnless(isinstance(value, NullReferenceException))
self.failUnless(value.Message == 'Aiiieee!')
+
def testManagedExceptionPropagation(self):
"""Test propagation of exceptions raised in managed code."""
from CLR.System import Decimal, OverflowException
@@ -95,7 +99,6 @@
l = Decimal.ToInt64(Decimal.MaxValue)
self.failUnlessRaises(OverflowException, test)
-
=== PythonNet/tests/python/test_field.py 1.1 => 1.2 ===
--- PythonNet/tests/python/test_field.py:1.1 Mon Feb 17 22:44:38 2003
+++ PythonNet/tests/python/test_field.py Tue Oct 7 22:29:18 2003
@@ -14,6 +14,7 @@
from CLR.Python.Test import ShortEnum
from CLR import System
+
class FieldTests(unittest.TestCase):
"""Test CLR field support."""
@@ -30,6 +31,7 @@
self.failUnlessRaises(TypeError, test)
+
def testPublicStaticField(self):
"""Test public static fields."""
object = FieldTest();
@@ -52,6 +54,7 @@
self.failUnlessRaises(TypeError, test)
+
def testProtectedInstanceField(self):
"""Test protected instance fields."""
object = FieldTest();
@@ -65,6 +68,7 @@
self.failUnlessRaises(TypeError, test)
+
def testProtectedStaticField(self):
"""Test protected static fields."""
object = FieldTest();
@@ -87,6 +91,7 @@
self.failUnlessRaises(TypeError, test)
+
def testReadOnlyInstanceField(self):
"""Test readonly instance fields."""
self.failUnless(FieldTest().ReadOnlyField == 0)
@@ -101,6 +106,7 @@
self.failUnlessRaises(TypeError, test)
+
def testReadOnlyStaticField(self):
"""Test readonly static fields."""
object = FieldTest();
@@ -128,6 +134,7 @@
self.failUnlessRaises(TypeError, test)
+
def testConstantField(self):
"""Test const fields."""
object = FieldTest();
@@ -155,6 +162,7 @@
self.failUnlessRaises(TypeError, test)
+
def testInternalField(self):
"""Test internal fields."""
@@ -173,6 +181,7 @@
self.failUnlessRaises(AttributeError, test)
+
def testPrivateField(self):
"""Test private fields."""
@@ -191,6 +200,7 @@
self.failUnlessRaises(AttributeError, test)
+
def testFieldDescriptorGetSet(self):
"""Test field descriptor get / set."""
@@ -214,6 +224,7 @@
descriptor = FieldTest.__dict__['PublicStaticField']
self.failUnless(type(descriptor) != types.IntType)
+
def testFieldDescriptorWrongType(self):
"""Test setting a field using a value of the wrong type."""
def test():
@@ -221,6 +232,7 @@
self.failUnlessRaises(TypeError, test)
+
def testFieldDescriptorAbuse(self):
"""Test field descriptor abuse."""
desc = FieldTest.__dict__['PublicField']
@@ -235,6 +247,7 @@
self.failUnlessRaises(TypeError, test)
+
def testBooleanField(self):
"""Test boolean fields."""
# change this to true / false later for Python 2.3?
@@ -244,6 +257,7 @@
object.BooleanField = 1
self.failUnless(object.BooleanField == 1)
+
def testSByteField(self):
"""Test sbyte fields."""
object = FieldTest()
@@ -252,6 +266,7 @@
object.SByteField = 1
self.failUnless(object.SByteField == 1)
+
def testByteField(self):
"""Test byte fields."""
object = FieldTest()
@@ -260,6 +275,7 @@
object.ByteField = 1
self.failUnless(object.ByteField == 1)
+
def testCharField(self):
"""Test char fields."""
object = FieldTest()
@@ -274,6 +290,7 @@
self.failUnless(object.CharField == u'C')
self.failUnless(object.CharField == 'C')
+
def testInt16Field(self):
"""Test int16 fields."""
object = FieldTest()
@@ -282,6 +299,7 @@
object.Int16Field = 1
self.failUnless(object.Int16Field == 1)
+
def testInt32Field(self):
"""Test int32 fields."""
object = FieldTest()
@@ -290,6 +308,7 @@
object.Int32Field = 1
self.failUnless(object.Int32Field == 1)
+
def testInt64Field(self):
"""Test int64 fields."""
object = FieldTest()
@@ -298,6 +317,7 @@
object.Int64Field = 1
self.failUnless(object.Int64Field == 1)
+
def testUInt16Field(self):
"""Test uint16 fields."""
object = FieldTest()
@@ -306,6 +326,7 @@
object.UInt16Field = 1
self.failUnless(object.UInt16Field == 1)
+
def testUInt32Field(self):
"""Test uint32 fields."""
object = FieldTest()
@@ -314,6 +335,7 @@
object.UInt32Field = 1
self.failUnless(object.UInt32Field == 1)
+
def testUInt64Field(self):
"""Test uint64 fields."""
object = FieldTest()
@@ -322,6 +344,7 @@
object.UInt64Field = 1
self.failUnless(object.UInt64Field == 1)
+
def testSingleField(self):
"""Test single fields."""
object = FieldTest()
@@ -330,6 +353,7 @@
object.SingleField = 1.1
self.failUnless(object.SingleField == 1.1)
+
def testDoubleField(self):
"""Test double fields."""
object = FieldTest()
@@ -338,6 +362,7 @@
object.DoubleField = 1.1
self.failUnless(object.DoubleField == 1.1)
+
def testDecimalField(self):
"""Test decimal fields."""
object = FieldTest()
@@ -346,6 +371,7 @@
object.DecimalField = System.Decimal(1)
self.failUnless(object.DecimalField == System.Decimal(1))
+
def testStringField(self):
"""Test string fields."""
object = FieldTest()
@@ -354,6 +380,7 @@
object.StringField = "eggs"
self.failUnless(object.StringField == "eggs")
+
def testInterfaceField(self):
"""Test interface fields."""
from CLR.Python.Test import Spam
@@ -367,6 +394,7 @@
self.failUnless(object.SpamField.__class__.__name__ == "ISpam")
self.failUnless(object.SpamField.GetValue() == "eggs")
+
def testObjectField(self):
"""Test object fields."""
object = FieldTest()
@@ -381,6 +409,7 @@
object.ObjectField = None
self.failUnless(object.ObjectField == None)
+
def testEnumField(self):
"""Test enum fields."""
object = FieldTest()
@@ -389,6 +418,7 @@
object.EnumField = ShortEnum.One
self.failUnless(object.EnumField == ShortEnum.One)
+
def testNullableField(self):
"""Test nullable fields."""
object = FieldTest()
@@ -413,7 +443,6 @@
FieldTest().EnumField = None
self.failUnlessRaises(TypeError, test)
-
=== PythonNet/tests/python/test_indexer.py 1.2 => 1.3 ===
--- PythonNet/tests/python/test_indexer.py:1.2 Mon Jul 28 22:28:26 2003
+++ PythonNet/tests/python/test_indexer.py Tue Oct 7 22:29:18 2003
@@ -12,6 +12,7 @@
import sys, os, string, unittest, types
import CLR.Python.Test as Test
+
class IndexerTests(unittest.TestCase):
"""Test support for indexer properties."""
=== PythonNet/tests/python/test_interface.py 1.1 => 1.2 ===
--- PythonNet/tests/python/test_interface.py:1.1 Mon Feb 17 22:44:38 2003
+++ PythonNet/tests/python/test_interface.py Tue Oct 7 22:29:18 2003
@@ -14,6 +14,7 @@
import CLR.System as System
import CLR.Python.Test as Test
+
class InterfaceTests(unittest.TestCase):
"""Test CLR interface support."""
@@ -24,6 +25,7 @@
self.failUnless(type(InterfaceTest.__dict__) == types.DictProxyType)
self.failUnless(InterfaceTest.__doc__ == None)
+
def testGlobalInterfaceVisibility(self):
"""Test visibility of module-level interfaces."""
from CLR.Python.Test import IPublicInterface
@@ -39,6 +41,7 @@
self.failUnlessRaises(AttributeError, test)
+
def testNestedInterfaceVisibility(self):
"""Test visibility of nested interfaces."""
ob = InterfaceTest.IPublic
@@ -57,6 +60,7 @@
self.failUnlessRaises(AttributeError, test)
+
def testExplicitCastToInterface(self):
"""Test explicit cast to an interface."""
ob = InterfaceTest()
@@ -75,8 +79,6 @@
self.failUnless(hasattr(i2, 'SayHello'))
self.failIf(hasattr(i2, 'HelloProperty'))
-
- # probably should test some funky interface conversion scenarios
def test_suite():
=== PythonNet/tests/python/test_method.py 1.1 => 1.2 ===
--- PythonNet/tests/python/test_method.py:1.1 Mon Feb 17 22:44:38 2003
+++ PythonNet/tests/python/test_method.py Tue Oct 7 22:29:18 2003
@@ -12,6 +12,7 @@
import sys, os, string, unittest, types
from CLR.Python.Test import MethodTest
+
class MethodTests(unittest.TestCase):
"""Test CLR method support."""
@@ -37,6 +38,7 @@
self.failUnlessRaises(AttributeError, test)
+
def testStaticMethodDescriptor(self):
"""Test static method descriptor behavior."""
def test():
@@ -59,22 +61,26 @@
self.failUnlessRaises(AttributeError, test)
+
def testPublicInstanceMethod(self):
"""Test public instance method visibility."""
object = MethodTest();
self.failUnless(object.PublicMethod() == "public")
+
def testPublicStaticMethod(self):
"""Test public static method visibility."""
object = MethodTest();
self.failUnless(MethodTest.PublicStaticMethod() == "public static")
self.failUnless(object.PublicStaticMethod() == "public static")
+
def testProtectedInstanceMethod(self):
"""Test protected instance method visibility."""
object = MethodTest();
self.failUnless(object.ProtectedMethod() == "protected")
+
def testProtectedStaticMethod(self):
"""Test protected static method visibility."""
object = MethodTest();
@@ -82,6 +88,7 @@
self.failUnless(MethodTest.ProtectedStaticMethod() == result)
self.failUnless(object.ProtectedStaticMethod() == result)
+
def testInternalMethod(self):
"""Test internal method visibility."""
def test():
@@ -104,6 +111,7 @@
self.failUnlessRaises(AttributeError, test)
+
def testPrivateMethod(self):
"""Test private method visibility."""
def test():
@@ -125,6 +133,7 @@
f = MethodTest.PrivateStaticMethod
self.failUnlessRaises(AttributeError, test)
+
def testMethodDescriptorAbuse(self):
"""Test method descriptor abuse."""
=== PythonNet/tests/python/test_module.py 1.1 => 1.2 ===
--- PythonNet/tests/python/test_module.py:1.1 Mon Feb 17 22:44:38 2003
+++ PythonNet/tests/python/test_module.py Tue Oct 7 22:29:18 2003
@@ -11,15 +11,18 @@
import sys, os, string, unittest, types
+
class ModuleTests(unittest.TestCase):
"""Test CLR modules and the CLR import hook."""
def isCLRModule(self, object):
return type(object).__name__ == 'ModuleObject'
+
def isCLRClass(self, object):
return type(object).__name__ == 'MetaType' # for now
+
def testModuleInterface(self):
"""Test the interface exposed by CLR module objects."""
import CLR.System as System
@@ -37,6 +40,7 @@
self.failUnlessRaises(AttributeError, test)
+
def testSimpleImport(self):
"""Test simple import."""
import CLR
@@ -51,6 +55,7 @@
self.failUnless(type(httplib) == types.ModuleType)
self.failUnless(httplib.__name__ == 'httplib')
+
def testSimpleImportWithAlias(self):
"""Test simple import with aliasing."""
import CLR as myCLR
@@ -65,6 +70,7 @@
self.failUnless(type(myHttplib) == types.ModuleType)
self.failUnless(myHttplib.__name__ == 'httplib')
+
def testDottedNameImport(self):
"""Test dotted-name import."""
import CLR.System
@@ -75,6 +81,7 @@
self.failUnless(type(xml.dom) == types.ModuleType)
self.failUnless(xml.dom.__name__ == 'xml.dom')
+
def testDottedNameImportWithAlias(self):
"""Test dotted-name import with aliasing."""
import CLR.System as mySystem
@@ -85,6 +92,7 @@
self.failUnless(type(myDom) == types.ModuleType)
self.failUnless(myDom.__name__ == 'xml.dom')
+
def testSimpleImportFrom(self):
"""Test simple 'import from'."""
from CLR import System
@@ -95,6 +103,7 @@
self.failUnless(type(dom) == types.ModuleType)
self.failUnless(dom.__name__ == 'xml.dom')
+
def testSimpleImportFromWithAlias(self):
"""Test simple 'import from' with aliasing."""
from CLR import System as mySystem
@@ -105,6 +114,7 @@
self.failUnless(type(myDom) == types.ModuleType)
self.failUnless(myDom.__name__ == 'xml.dom')
+
def testDottedNameImportFrom(self):
"""Test dotted-name 'import from'."""
from CLR.System import Xml
@@ -123,6 +133,7 @@
self.failUnless(type(PullDOM) == types.ClassType)
self.failUnless(PullDOM.__name__ == 'PullDOM')
+
def testDottedNameImportFromWithAlias(self):
"""Test dotted-name 'import from' with aliasing."""
from CLR.System import Xml as myXml
@@ -141,6 +152,7 @@
self.failUnless(type(myPullDOM) == types.ClassType)
self.failUnless(myPullDOM.__name__ == 'PullDOM')
+
def testFromModuleImportStar(self):
"""Test from module import * behavior."""
# Using 'from x import *' is considered evil generally, more so
@@ -152,6 +164,7 @@
self.failUnless(m.__name__ == 'CLR.System.Xml')
self.failUnless(self.isCLRModule(m))
+
def testImplicitAssemblyLoad(self):
"""Test implicit assembly loading via import."""
@@ -170,6 +183,7 @@
self.failUnless(self.isCLRClass(Graphics))
self.failUnless(Graphics.__name__ == 'Graphics')
+
def testExplicitAssemblyLoad(self):
"""Test explicit assembly loading using standard CLR tools."""
from CLR.System.Reflection import Assembly
@@ -196,6 +210,7 @@
import CLR.System
self.failUnless(self.isCLRClass(CLR.System.UriBuilder))
+
def testImportNonExistantModule(self):
"""Test import failure for a non-existant module."""
def test():
@@ -203,12 +218,14 @@
self.failUnlessRaises(ImportError, test)
+
def testLookupNoNamespaceType(self):
"""Test lookup of types without a qualified namespace."""
import CLR.Python.Test
import CLR
self.failUnless(self.isCLRClass(CLR.NoNamespaceType))
+
def testModuleLookupRecursion(self):
"""Test for recursive lookup handling."""
def test1():
@@ -222,6 +239,7 @@
self.failUnlessRaises(AttributeError, test2)
+
def testModuleGetAttr(self):
"""Test module getattr behavior."""
import CLR.System as System
@@ -242,6 +260,7 @@
self.failUnlessRaises(TypeError, test)
+
def testModuleAttrAbuse(self):
"""Test handling of attempts to set module attributes."""
def test():
@@ -286,6 +305,7 @@
self.failUnlessRaises(TypeError, test)
+
def testModuleTypeAbuse(self):
"""Test handling of attempts to break the module type."""
import CLR.System as System
@@ -305,6 +325,7 @@
mtype.__repr__(0)
self.failUnlessRaises(TypeError, test)
+
def test_suite():
=== PythonNet/tests/python/test_property.py 1.1 => 1.2 ===
--- PythonNet/tests/python/test_property.py:1.1 Mon Feb 17 22:44:38 2003
+++ PythonNet/tests/python/test_property.py Tue Oct 7 22:29:18 2003
@@ -12,6 +12,7 @@
import sys, os, string, unittest, types
from CLR.Python.Test import PropertyTest
+
class PropertyTests(unittest.TestCase):
"""Test CLR property support."""
@@ -28,6 +29,7 @@
self.failUnlessRaises(TypeError, test)
+
def testPublicStaticProperty(self):
"""Test public static properties."""
object = PropertyTest();
@@ -50,6 +52,7 @@
self.failUnlessRaises(TypeError, test)
+
def testProtectedInstanceProperty(self):
"""Test protected instance properties."""
object = PropertyTest();
@@ -63,6 +66,7 @@
self.failUnlessRaises(TypeError, test)
+
def testProtectedStaticProperty(self):
"""Test protected static properties."""
object = PropertyTest();
@@ -85,6 +89,7 @@
self.failUnlessRaises(TypeError, test)
+
def testInternalProperty(self):
"""Test internal properties."""
@@ -103,6 +108,7 @@
self.failUnlessRaises(AttributeError, test)
+
def testPrivateProperty(self):
"""Test private properties."""
@@ -121,11 +127,12 @@
self.failUnlessRaises(AttributeError, test)
+
def testPropertyDescriptorGetSet(self):
"""Test property descriptor get / set."""
# This test ensures that setting an attribute implemented with
- # a descript actually goes through the descriptor (rather than
+ # a descriptor actually goes through the descriptor (rather than
# silently replacing the descriptor in the instance or type dict.
object = PropertyTest()
@@ -144,6 +151,7 @@
descriptor = PropertyTest.__dict__['PublicStaticProperty']
self.failUnless(type(descriptor) != types.IntType)
+
def testPropertyDescriptorWrongType(self):
"""Test setting a property using a value of the wrong type."""
def test():
@@ -151,6 +159,7 @@
object.PublicProperty = "spam"
self.failUnlessRaises(TypeError, test)
+
def testPropertyDescriptorAbuse(self):
"""Test property descriptor abuse."""
More information about the Zope-CVS
mailing list