[Zope-CVS] CVS: PythonNet/tests/python - test_array.py:1.1 runtests.py:1.3 test_conversion.py:1.3 test_delegate.py:1.3 test_indexer.py:1.2
Brian Lloyd
brian@zope.com
Mon, 28 Jul 2003 22:28:32 -0400
Update of /cvs-repository/PythonNet/tests/python
In directory cvs.zope.org:/tmp/cvs-serv5111/tests/python
Modified Files:
runtests.py test_conversion.py test_delegate.py
test_indexer.py
Added Files:
test_array.py
Log Message:
added indexer support, array support and preliminary thread primitives
=== Added File PythonNet/tests/python/test_array.py ===
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
#
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
import sys, os, string, unittest, types
import CLR.Python.Test as Test
class ArrayTests(unittest.TestCase):
"""Test support for managed arrays."""
def testPublicArray(self):
"""Test public arrays."""
object = Test.PublicArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == 0)
self.failUnless(items[4] == 4)
items[0] = 8
self.failUnless(items[0] == 8)
items[4] = 9
self.failUnless(items[4] == 9)
items[-4] = 0
self.failUnless(items[-4] == 0)
items[-1] = 4
self.failUnless(items[-1] == 4)
def testProtectedArray(self):
"""Test protected arrays."""
object = Test.ProtectedArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == 0)
self.failUnless(items[4] == 4)
items[0] = 8
self.failUnless(items[0] == 8)
items[4] = 9
self.failUnless(items[4] == 9)
items[-4] = 0
self.failUnless(items[-4] == 0)
items[-1] = 4
self.failUnless(items[-1] == 4)
def testInternalArray(self):
"""Test internal arrays."""
def test():
object = Test.InternalArrayTest()
items = object.items
self.failUnlessRaises(AttributeError, test)
def testPrivateArray(self):
"""Test private arrays."""
def test():
object = Test.PrivateArrayTest()
items = object.items
self.failUnlessRaises(AttributeError, test)
def testArrayBoundsChecking(self):
"""Test array bounds checking."""
object = Test.Int32ArrayTest()
items = object.items
self.failUnless(items[0] == 0)
self.failUnless(items[1] == 1)
self.failUnless(items[2] == 2)
self.failUnless(items[3] == 3)
self.failUnless(items[4] == 4)
self.failUnless(items[-5] == 0)
self.failUnless(items[-4] == 1)
self.failUnless(items[-3] == 2)
self.failUnless(items[-2] == 3)
self.failUnless(items[-1] == 4)
def test():
object = Test.Int32ArrayTest()
object.items[5]
self.failUnlessRaises(IndexError, test)
def test():
object = Test.Int32ArrayTest()
object.items[5] = 0
self.failUnlessRaises(IndexError, test)
def test():
object = Test.Int32ArrayTest()
items[-6]
self.failUnlessRaises(IndexError, test)
def test():
object = Test.Int32ArrayTest()
items[-6] = 0
self.failUnlessRaises(IndexError, test)
def testArrayContains(self):
"""Test array support for __contains__."""
object = Test.Int32ArrayTest()
items = object.items
self.failUnless(0 in items)
self.failUnless(1 in items)
self.failUnless(2 in items)
self.failUnless(3 in items)
self.failUnless(4 in items)
self.failIf(5 in items)
self.failIf(-1 in items)
self.failIf(None in items)
def testBooleanArray(self):
"""Test boolean arrays."""
object = Test.BooleanArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == True)
self.failUnless(items[1] == False)
self.failUnless(items[2] == True)
self.failUnless(items[3] == False)
self.failUnless(items[4] == True)
items[0] = False
self.failUnless(items[0] == False)
items[0] = True
self.failUnless(items[0] == True)
def test():
object = Test.ByteArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.ByteArrayTest()
object[0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testByteArray(self):
"""Test byte arrays."""
object = Test.ByteArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == 0)
self.failUnless(items[4] == 4)
max = 255
min = 0
items[0] = max
self.failUnless(items[0] == max)
items[0] = min
self.failUnless(items[0] == min)
items[-4] = max
self.failUnless(items[-4] == max)
items[-1] = min
self.failUnless(items[-1] == min)
def test():
object = Test.ByteArrayTest()
object.items[0] = max + 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.ByteArrayTest()
object.items[0] = min - 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.ByteArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.ByteArrayTest()
object[0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testSByteArray(self):
"""Test sbyte arrays."""
object = Test.SByteArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == 0)
self.failUnless(items[4] == 4)
max = 127
min = -128
items[0] = max
self.failUnless(items[0] == max)
items[0] = min
self.failUnless(items[0] == min)
items[-4] = max
self.failUnless(items[-4] == max)
items[-1] = min
self.failUnless(items[-1] == min)
def test():
object = Test.SByteArrayTest()
object.items[0] = max + 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.SByteArrayTest()
object.items[0] = min - 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.SByteArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.SByteArrayTest()
object[0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testCharArray(self):
"""Test char arrays."""
object = Test.CharArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == 'a')
self.failUnless(items[4] == 'e')
max = unichr(65535)
min = unichr(0)
items[0] = max
self.failUnless(items[0] == max)
items[0] = min
self.failUnless(items[0] == min)
items[-4] = max
self.failUnless(items[-4] == max)
items[-1] = min
self.failUnless(items[-1] == min)
def test():
object = Test.CharArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.CharArrayTest()
object[0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testInt16Array(self):
"""Test Int16 arrays."""
object = Test.Int16ArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == 0)
self.failUnless(items[4] == 4)
max = 32767
min = -32768
items[0] = max
self.failUnless(items[0] == max)
items[0] = min
self.failUnless(items[0] == min)
items[-4] = max
self.failUnless(items[-4] == max)
items[-1] = min
self.failUnless(items[-1] == min)
def test():
object = Test.Int16ArrayTest()
object.items[0] = max + 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.Int16ArrayTest()
object.items[0] = min - 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.Int16ArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.Int16ArrayTest()
object[0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testInt32Array(self):
"""Test Int32 arrays."""
object = Test.Int32ArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == 0)
self.failUnless(items[4] == 4)
max = 2147483647
min = -2147483648
items[0] = max
self.failUnless(items[0] == max)
items[0] = min
self.failUnless(items[0] == min)
items[-4] = max
self.failUnless(items[-4] == max)
items[-1] = min
self.failUnless(items[-1] == min)
def test():
object = Test.Int32ArrayTest()
object.items[0] = max + 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.Int32ArrayTest()
object.items[0] = min - 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.Int32ArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.Int32ArrayTest()
object[0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testInt64Array(self):
"""Test Int64 arrays."""
object = Test.Int64ArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == 0)
self.failUnless(items[4] == 4)
max = 9223372036854775807L
min = -9223372036854775808L
items[0] = max
self.failUnless(items[0] == max)
items[0] = min
self.failUnless(items[0] == min)
items[-4] = max
self.failUnless(items[-4] == max)
items[-1] = min
self.failUnless(items[-1] == min)
def test():
object = Test.Int64ArrayTest()
object.items[0] = max + 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.Int64ArrayTest()
object.items[0] = min - 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.Int64ArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.Int64ArrayTest()
object[0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testUInt16Array(self):
"""Test UInt16 arrays."""
object = Test.UInt16ArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == 0)
self.failUnless(items[4] == 4)
max = 65535
min = 0
items[0] = max
self.failUnless(items[0] == max)
items[0] = min
self.failUnless(items[0] == min)
items[-4] = max
self.failUnless(items[-4] == max)
items[-1] = min
self.failUnless(items[-1] == min)
def test():
object = Test.UInt16ArrayTest()
object.items[0] = max + 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.UInt16ArrayTest()
object.items[0] = min - 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.UInt16ArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.UInt16ArrayTest()
object[0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testUInt32Array(self):
"""Test UInt32 arrays."""
object = Test.UInt32ArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == 0)
self.failUnless(items[4] == 4)
max = 4294967295L
min = 0
items[0] = max
self.failUnless(items[0] == max)
items[0] = min
self.failUnless(items[0] == min)
items[-4] = max
self.failUnless(items[-4] == max)
items[-1] = min
self.failUnless(items[-1] == min)
def test():
object = Test.UInt32ArrayTest()
object.items[0] = max + 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.UInt32ArrayTest()
object.items[0] = min - 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.UInt32ArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.UInt32ArrayTest()
object[0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testUInt64Array(self):
"""Test UInt64 arrays."""
object = Test.UInt64ArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == 0)
self.failUnless(items[4] == 4)
max = 18446744073709551615L
min = 0
items[0] = max
self.failUnless(items[0] == max)
items[0] = min
self.failUnless(items[0] == min)
items[-4] = max
self.failUnless(items[-4] == max)
items[-1] = min
self.failUnless(items[-1] == min)
def test():
object = Test.UInt64ArrayTest()
object.items[0] = max + 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.UInt64ArrayTest()
object.items[0] = min - 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.UInt64ArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.UInt64ArrayTest()
object[0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testSingleArray(self):
"""Test Single arrays."""
object = Test.SingleArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == 0.0)
self.failUnless(items[4] == 4.0)
max = 3.402823e38
min = -3.402823e38
items[0] = max
self.failUnless(items[0] == max)
items[0] = min
self.failUnless(items[0] == min)
items[-4] = max
self.failUnless(items[-4] == max)
items[-1] = min
self.failUnless(items[-1] == min)
def test():
object = Test.SingleArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.SingleArrayTest()
object[0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testDoubleArray(self):
"""Test Double arrays."""
object = Test.DoubleArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == 0.0)
self.failUnless(items[4] == 4.0)
max = 1.7976931348623157e308
min = -1.7976931348623157e308
items[0] = max
self.failUnless(items[0] == max)
items[0] = min
self.failUnless(items[0] == min)
items[-4] = max
self.failUnless(items[-4] == max)
items[-1] = min
self.failUnless(items[-1] == min)
def test():
object = Test.DoubleArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.DoubleArrayTest()
object[0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testDecimalArray(self):
"""Test Decimal arrays."""
object = Test.DecimalArrayTest()
items = object.items
from CLR.System import Decimal
max_d = Decimal.Parse("79228162514264337593543950335")
min_d = Decimal.Parse("-79228162514264337593543950335")
self.failUnless(len(items) == 5)
self.failUnless(items[0] == Decimal(0))
self.failUnless(items[4] == Decimal(4))
items[0] = max_d
self.failUnless(items[0] == max_d)
items[0] = min_d
self.failUnless(items[0] == min_d)
items[-4] = max_d
self.failUnless(items[-4] == max_d)
items[-1] = min_d
self.failUnless(items[-1] == min_d)
def test():
object = Test.DecimalArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.DecimalArrayTest()
object[0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testStringArray(self):
"""Test String arrays."""
object = Test.StringArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == '0')
self.failUnless(items[4] == '4')
items[0] = "spam"
self.failUnless(items[0] == "spam")
items[0] = "eggs"
self.failUnless(items[0] == "eggs")
items[-4] = "spam"
self.failUnless(items[-4] == "spam")
items[-1] = "eggs"
self.failUnless(items[-1] == "eggs")
def test():
object = Test.StringArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.Int64ArrayTest()
object[0] = 0
self.failUnlessRaises(TypeError, test)
def testEnumArray(self):
"""Test enum arrays."""
from CLR.Python.Test import ShortEnum
object = Test.EnumArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0] == ShortEnum.Zero)
self.failUnless(items[4] == ShortEnum.Four)
items[0] = ShortEnum.Four
self.failUnless(items[0] == ShortEnum.Four)
items[0] = ShortEnum.Zero
self.failUnless(items[0] == ShortEnum.Zero)
items[-4] = ShortEnum.Four
self.failUnless(items[-4] == ShortEnum.Four)
items[-1] = ShortEnum.Zero
self.failUnless(items[-1] == ShortEnum.Zero)
def test():
object = Test.EnumArrayTest()
object.items[0] = 99
self.failUnlessRaises(ValueError, test)
def test():
object = Test.EnumArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.EnumArrayTest()
object[0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testObjectArray(self):
"""Test object arrays."""
from CLR.Python.Test import Spam
object = Test.ObjectArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0].GetValue() == "0")
self.failUnless(items[4].GetValue() == "4")
items[0] = Spam("4")
self.failUnless(items[0].GetValue() == "4")
items[0] = Spam("0")
self.failUnless(items[0].GetValue() == "0")
items[-4] = Spam("4")
self.failUnless(items[-4].GetValue() == "4")
items[-1] = Spam("0")
self.failUnless(items[-1].GetValue() == "0")
items[0] = 99
self.failUnless(items[0] == 99)
items[0] = None
self.failUnless(items[0] == None)
def test():
object = Test.ObjectArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.ObjectArrayTest()
object.items["wrong"] = "wrong"
self.failUnlessRaises(TypeError, test)
def testInterfaceArray(self):
"""Test interface arrays."""
from CLR.Python.Test import Spam
object = Test.InterfaceArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0].GetValue() == "0")
self.failUnless(items[4].GetValue() == "4")
items[0] = Spam("4")
self.failUnless(items[0].GetValue() == "4")
items[0] = Spam("0")
self.failUnless(items[0].GetValue() == "0")
items[-4] = Spam("4")
self.failUnless(items[-4].GetValue() == "4")
items[-1] = Spam("0")
self.failUnless(items[-1].GetValue() == "0")
items[0] = None
self.failUnless(items[0] == None)
def test():
object = Test.InterfaceArrayTest()
object.items[0] = 99
self.failUnlessRaises(TypeError, test)
def test():
object = Test.InterfaceArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.InterfaceArrayTest()
object.items["wrong"] = "wrong"
self.failUnlessRaises(TypeError, test)
def testTypedArray(self):
"""Test typed arrays."""
from CLR.Python.Test import Spam
object = Test.TypedArrayTest()
items = object.items
self.failUnless(len(items) == 5)
self.failUnless(items[0].GetValue() == "0")
self.failUnless(items[4].GetValue() == "4")
items[0] = Spam("4")
self.failUnless(items[0].GetValue() == "4")
items[0] = Spam("0")
self.failUnless(items[0].GetValue() == "0")
items[-4] = Spam("4")
self.failUnless(items[-4].GetValue() == "4")
items[-1] = Spam("0")
self.failUnless(items[-1].GetValue() == "0")
items[0] = None
self.failUnless(items[0] == None)
def test():
object = Test.TypedArrayTest()
object.items[0] = 99
self.failUnlessRaises(TypeError, test)
def test():
object = Test.TypedArrayTest()
v = object.items["wrong"]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.TypedArrayTest()
object.items["wrong"] = "wrong"
self.failUnlessRaises(TypeError, test)
def testMultiDimensionalArray(self):
"""Test multi-dimensional arrays."""
object = Test.MultiDimensionalArrayTest()
items = object.items
self.failUnless(len(items) == 25)
self.failUnless(items[0, 0] == 0)
self.failUnless(items[0, 1] == 1)
self.failUnless(items[0, 2] == 2)
self.failUnless(items[0, 3] == 3)
self.failUnless(items[0, 4] == 4)
self.failUnless(items[1, 0] == 5)
self.failUnless(items[1, 1] == 6)
self.failUnless(items[1, 2] == 7)
self.failUnless(items[1, 3] == 8)
self.failUnless(items[1, 4] == 9)
self.failUnless(items[2, 0] == 10)
self.failUnless(items[2, 1] == 11)
self.failUnless(items[2, 2] == 12)
self.failUnless(items[2, 3] == 13)
self.failUnless(items[2, 4] == 14)
self.failUnless(items[3, 0] == 15)
self.failUnless(items[3, 1] == 16)
self.failUnless(items[3, 2] == 17)
self.failUnless(items[3, 3] == 18)
self.failUnless(items[3, 4] == 19)
self.failUnless(items[4, 0] == 20)
self.failUnless(items[4, 1] == 21)
self.failUnless(items[4, 2] == 22)
self.failUnless(items[4, 3] == 23)
self.failUnless(items[4, 4] == 24)
max = 2147483647
min = -2147483648
items[0, 0] = max
self.failUnless(items[0, 0] == max)
items[0, 0] = min
self.failUnless(items[0, 0] == min)
items[-4, 0] = max
self.failUnless(items[-4, 0] == max)
items[-1, -1] = min
self.failUnless(items[-1, -1] == min)
def test():
object = Test.MultiDimensionalArrayTest()
object.items[0, 0] = max + 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.MultiDimensionalArrayTest()
object.items[0, 0] = min - 1
self.failUnlessRaises(OverflowError, test)
def test():
object = Test.MultiDimensionalArrayTest()
v = object.items["wrong", 0]
self.failUnlessRaises(TypeError, test)
def test():
object = Test.MultiDimensionalArrayTest()
object[0, 0] = "wrong"
self.failUnlessRaises(TypeError, test)
def testArrayAbuse(self):
"""Test array abuse."""
_class = Test.PublicArrayTest
object = Test.PublicArrayTest()
def test():
del _class.__getitem__
self.failUnlessRaises(AttributeError, test)
def test():
del object.__getitem__
self.failUnlessRaises(AttributeError, test)
def test():
del _class.__setitem__
self.failUnlessRaises(AttributeError, test)
def test():
del object.__setitem__
self.failUnlessRaises(AttributeError, test)
def test():
Test.PublicArrayTest.__getitem__(0, 0)
self.failUnlessRaises(TypeError, test)
def test():
Test.PublicArrayTest.__setitem__(0, 0, 0)
self.failUnlessRaises(TypeError, test)
def test():
desc = Test.PublicArrayTest.__dict__['__getitem__']
desc(0, 0)
self.failUnlessRaises(TypeError, test)
def test():
desc = Test.PublicArrayTest.__dict__['__setitem__']
desc(0, 0, 0)
self.failUnlessRaises(TypeError, test)
def test_suite():
return unittest.makeSuite(ArrayTests)
def main():
unittest.TextTestRunner().run(test_suite())
if __name__ == '__main__':
testcase.setup()
main()
=== PythonNet/tests/python/runtests.py 1.2 => 1.3 ===
--- PythonNet/tests/python/runtests.py:1.2 Thu Jul 24 19:55:11 2003
+++ PythonNet/tests/python/runtests.py Mon Jul 28 22:28:26 2003
@@ -1,7 +1,10 @@
"""Run all of the unit tests for this package."""
def main():
+ import time
+ start = time.clock()
+
for name in (
'test_module',
'test_conversion',
@@ -14,11 +17,15 @@
'test_event',
'test_method',
'test_delegate',
- 'test_exceptions',
+ 'test_array',
+ #'test_exceptions',
):
module = __import__(name)
module.main()
+ stop = time.clock()
+ took = str(stop - start)
+ print 'Total Time: %s' % took
if __name__ == '__main__':
main()
=== PythonNet/tests/python/test_conversion.py 1.2 => 1.3 ===
--- PythonNet/tests/python/test_conversion.py:1.2 Mon Jul 14 14:34:21 2003
+++ PythonNet/tests/python/test_conversion.py Mon Jul 28 22:28:26 2003
@@ -166,6 +166,12 @@
self.failUnlessRaises(OverflowError, test)
+ def test():
+ ConversionTest().CharField = None
+
+ self.failUnlessRaises(TypeError, test)
+
+
def testInt16Conversion(self):
"""Test int16 conversion."""
self.failUnless(System.Int16.MaxValue == 32767)
@@ -568,10 +574,10 @@
def testDecimalConversion(self):
"""Test decimal conversion."""
- from CLR.System import Decimal, OverflowException
+ from CLR.System import Decimal
- max_long = 79228162514264337593543950335L
- min_long = -79228162514264337593543950335L
+ max_d = Decimal.Parse("79228162514264337593543950335")
+ min_d = Decimal.Parse("-79228162514264337593543950335")
self.failUnless(Decimal.ToInt64(Decimal(10)) == 10L)
@@ -587,15 +593,11 @@
object.DecimalField = Decimal.Zero
self.failUnless(object.DecimalField == Decimal.Zero)
- def test():
- d = Decimal(max_long + 1)
-
- self.failUnlessRaises(OverflowException, test)
+ object.DecimalField = max_d
+ self.failUnless(object.DecimalField == max_d)
- def test():
- d = Decimal(min_long - 1)
-
- self.failUnlessRaises(OverflowException, test)
+ object.DecimalField = min_d
+ self.failUnless(object.DecimalField == min_d)
def test():
ConversionTest().DecimalField = None
@@ -611,6 +613,7 @@
ConversionTest().DecimalField = 1
self.failUnlessRaises(TypeError, test)
+
def testStringConversion(self):
"""Test string / unicode conversion."""
=== PythonNet/tests/python/test_delegate.py 1.2 => 1.3 ===
--- PythonNet/tests/python/test_delegate.py:1.2 Mon Jul 14 14:34:21 2003
+++ PythonNet/tests/python/test_delegate.py Mon Jul 28 22:28:26 2003
@@ -278,7 +278,7 @@
return unittest.makeSuite(DelegateTests)
def main():
- unittest.TextTestRunner().run(test_suite())
+ unittest.TextTestRunner(verbosity=3).run(test_suite())
if __name__ == '__main__':
testcase.setup()
=== PythonNet/tests/python/test_indexer.py 1.1 => 1.2 ===
--- PythonNet/tests/python/test_indexer.py:1.1 Thu Jul 24 19:55:11 2003
+++ PythonNet/tests/python/test_indexer.py Mon Jul 28 22:28:26 2003
@@ -25,10 +25,7 @@
object[1] = "one"
self.failUnless(object[1] == "one")
- def test():
- value = object[10]
-
- self.failUnlessRaises(IndexError, test)
+ self.failUnless(object[10] == None)
def testProtectedIndexer(self):
@@ -41,18 +38,13 @@
object[1] = "one"
self.failUnless(object[1] == "one")
- def test():
- value = object[10]
-
- self.failUnlessRaises(IndexError, test)
+ self.failUnless(object[10] == None)
def testInternalIndexer(self):
"""Test internal indexers."""
object = Test.InternalIndexerTest()
- # think about this!
-
def test():
object[0] = "zero"
@@ -61,40 +53,590 @@
def test():
Test.InternalIndexerTest.__getitem__(object, 0)
- self.failUnlessRaises(AttributeError, test)
+ self.failUnlessRaises(TypeError, test)
def test():
object.__getitem__(0)
- self.failUnlessRaises(AttributeError, test)
+ self.failUnlessRaises(TypeError, test)
def testPrivateIndexer(self):
"""Test private indexers."""
object = Test.PrivateIndexerTest()
-
+
def test():
object[0] = "zero"
self.failUnlessRaises(TypeError, test)
def test():
- Test.InternalIndexerTest.__getitem__(object, 0)
+ Test.PrivateIndexerTest.__getitem__(object, 0)
- self.failUnlessRaises(AttributeError, test)
+ self.failUnlessRaises(TypeError, test)
def test():
object.__getitem__(0)
- self.failUnlessRaises(AttributeError, test)
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testBooleanIndexer(self):
+ """Test boolean indexers."""
+ object = Test.BooleanIndexerTest()
+
+ self.failUnless(object[True] == None)
+ self.failUnless(object[1] == None)
+
+ object[0] = "false"
+ self.failUnless(object[0] == "false")
+
+ object[1] = "true"
+ self.failUnless(object[1] == "true")
+
+ object[False] = "false"
+ self.failUnless(object[False] == "false")
+
+ object[True] = "true"
+ self.failUnless(object[True] == "true")
+
+
+ def testByteIndexer(self):
+ """Test byte indexers."""
+ object = Test.ByteIndexerTest()
+ max = 255
+ min = 0
+
+ self.failUnless(object[max] == None)
+
+ object[max] = str(max)
+ self.failUnless(object[max] == str(max))
+
+ object[min] = str(min)
+ self.failUnless(object[min] == str(min))
+
+ def test():
+ object = Test.ByteIndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.ByteIndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+ def testSByteIndexer(self):
+ """Test sbyte indexers."""
+ object = Test.SByteIndexerTest()
+ max = 127
+ min = -128
+
+ self.failUnless(object[max] == None)
+
+ object[max] = str(max)
+ self.failUnless(object[max] == str(max))
+
+ object[min] = str(min)
+ self.failUnless(object[min] == str(min))
+
+ def test():
+ object = Test.SByteIndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.SByteIndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testCharIndexer(self):
+ """Test char indexers."""
+ object = Test.CharIndexerTest()
+ max = unichr(65535)
+ min = unichr(0)
+
+ self.failUnless(object[max] == None)
+
+ object[max] = "max"
+ self.failUnless(object[max] == "max")
+
+ object[min] = "min"
+ self.failUnless(object[min] == "min")
+
+ def test():
+ object = Test.CharIndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.CharIndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testInt16Indexer(self):
+ """Test Int16 indexers."""
+ object = Test.Int16IndexerTest()
+ max = 32767
+ min = -32768
+
+ self.failUnless(object[max] == None)
+
+ object[max] = str(max)
+ self.failUnless(object[max] == str(max))
+
+ object[min] = str(min)
+ self.failUnless(object[min] == str(min))
+
+ def test():
+ object = Test.Int16IndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.Int16IndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
- # add typed indexer tests here.
+
+ def testInt32Indexer(self):
+ """Test Int32 indexers."""
+ object = Test.Int32IndexerTest()
+ max = 2147483647
+ min = -2147483648
+
+ self.failUnless(object[max] == None)
+
+ object[max] = str(max)
+ self.failUnless(object[max] == str(max))
+
+ object[min] = str(min)
+ self.failUnless(object[min] == str(min))
+
+ def test():
+ object = Test.Int32IndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.Int32IndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testInt64Indexer(self):
+ """Test Int64 indexers."""
+ object = Test.Int64IndexerTest()
+ max = 9223372036854775807L
+ min = -9223372036854775808L
+
+ self.failUnless(object[max] == None)
+
+ object[max] = str(max)
+ self.failUnless(object[max] == str(max))
+
+ object[min] = str(min)
+ self.failUnless(object[min] == str(min))
+
+ def test():
+ object = Test.Int64IndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.Int64IndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testUInt16Indexer(self):
+ """Test UInt16 indexers."""
+ object = Test.UInt16IndexerTest()
+ max = 65535
+ min = 0
+
+ self.failUnless(object[max] == None)
+
+ object[max] = str(max)
+ self.failUnless(object[max] == str(max))
+
+ object[min] = str(min)
+ self.failUnless(object[min] == str(min))
+
+ def test():
+ object = Test.UInt16IndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.UInt16IndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testUInt32Indexer(self):
+ """Test UInt32 indexers."""
+ object = Test.UInt32IndexerTest()
+ max = 4294967295L
+ min = 0
+
+ self.failUnless(object[max] == None)
+
+ object[max] = str(max)
+ self.failUnless(object[max] == str(max))
+
+ object[min] = str(min)
+ self.failUnless(object[min] == str(min))
+
+ def test():
+ object = Test.UInt32IndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.UInt32IndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testUInt64Indexer(self):
+ """Test UInt64 indexers."""
+ object = Test.UInt64IndexerTest()
+ max = 18446744073709551615L
+ min = 0
+
+ self.failUnless(object[max] == None)
+
+ object[max] = str(max)
+ self.failUnless(object[max] == str(max))
+
+ object[min] = str(min)
+ self.failUnless(object[min] == str(min))
+
+ def test():
+ object = Test.UInt64IndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.UInt64IndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testSingleIndexer(self):
+ """Test Single indexers."""
+ object = Test.SingleIndexerTest()
+ max = 3.402823e38
+ min = -3.402823e38
+
+ self.failUnless(object[max] == None)
+
+ object[max] = "max"
+ self.failUnless(object[max] == "max")
+
+ object[min] = "min"
+ self.failUnless(object[min] == "min")
+
+ def test():
+ object = Test.SingleIndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.SingleIndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testDoubleIndexer(self):
+ """Test Double indexers."""
+ object = Test.DoubleIndexerTest()
+ max = 1.7976931348623157e308
+ min = -1.7976931348623157e308
+
+ self.failUnless(object[max] == None)
+
+ object[max] = "max"
+ self.failUnless(object[max] == "max")
+
+ object[min] = "min"
+ self.failUnless(object[min] == "min")
+
+ def test():
+ object = Test.DoubleIndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.DoubleIndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testDecimalIndexer(self):
+ """Test Decimal indexers."""
+ object = Test.DecimalIndexerTest()
+
+ from CLR.System import Decimal
+ max_d = Decimal.Parse("79228162514264337593543950335")
+ min_d = Decimal.Parse("-79228162514264337593543950335")
+
+ self.failUnless(object[max_d] == None)
+
+ object[max_d] = "max"
+ self.failUnless(object[max_d] == "max")
+
+ object[min_d] = "min"
+ self.failUnless(object[min_d] == "min")
+
+ def test():
+ object = Test.DecimalIndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.DecimalIndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testStringIndexer(self):
+ """Test String indexers."""
+ object = Test.StringIndexerTest()
+
+ self.failUnless(object["spam"] == None)
+ self.failUnless(object[u"spam"] == None)
+
+ object["spam"] = "spam"
+ self.failUnless(object["spam"] == "spam")
+ self.failUnless(object["spam"] == u"spam")
+ self.failUnless(object[u"spam"] == "spam")
+ self.failUnless(object[u"spam"] == u"spam")
+
+ object[u"eggs"] = u"eggs"
+ self.failUnless(object["eggs"] == "eggs")
+ self.failUnless(object["eggs"] == u"eggs")
+ self.failUnless(object[u"eggs"] == "eggs")
+ self.failUnless(object[u"eggs"] == u"eggs")
+
+ def test():
+ object = Test.StringIndexerTest()
+ object[1]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.StringIndexerTest()
+ object[1] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testEnumIndexer(self):
+ """Test enum indexers."""
+ object = Test.EnumIndexerTest()
+
+ key = Test.ShortEnum.One
+
+ self.failUnless(object[key] == None)
+
+ object[key] = "spam"
+ self.failUnless(object[key] == "spam")
+
+ object[key] = "eggs"
+ self.failUnless(object[key] == "eggs")
+
+ object[1] = "spam"
+ self.failUnless(object[1] == "spam")
+
+ def test():
+ object = Test.EnumIndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.EnumIndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testObjectIndexer(self):
+ """Test object indexers."""
+ object = Test.ObjectIndexerTest()
+
+ from CLR.Python.Test import Spam
+ spam = Spam("spam")
+
+ self.failUnless(object[spam] == None)
+ self.failUnless(object["spam"] == None)
+ self.failUnless(object[1] == None)
+ self.failUnless(object[None] == None)
+
+ object[spam] = "spam"
+ self.failUnless(object[spam] == "spam")
+
+ object["spam"] = "eggs"
+ self.failUnless(object["spam"] == "eggs")
+
+ object[1] = "one"
+ self.failUnless(object[1] == "one")
+
+ object[1L] = "long"
+ self.failUnless(object[1L] == "long")
+
+ def test():
+ class eggs:
+ pass
+ key = eggs()
+ object = Test.ObjectIndexerTest()
+ object[key] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testInterfaceIndexer(self):
+ """Test interface indexers."""
+ object = Test.InterfaceIndexerTest()
+
+ from CLR.Python.Test import Spam
+ spam = Spam("spam")
+
+ self.failUnless(object[spam] == None)
+
+ object[spam] = "spam"
+ self.failUnless(object[spam] == "spam")
+
+ object[spam] = "eggs"
+ self.failUnless(object[spam] == "eggs")
+
+ def test():
+ object = Test.InterfaceIndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.InterfaceIndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testTypedIndexer(self):
+ """Test typed indexers."""
+ object = Test.TypedIndexerTest()
+
+ from CLR.Python.Test import Spam
+ spam = Spam("spam")
+
+ self.failUnless(object[spam] == None)
+
+ object[spam] = "spam"
+ self.failUnless(object[spam] == "spam")
+
+ object[spam] = "eggs"
+ self.failUnless(object[spam] == "eggs")
+
+ def test():
+ object = Test.TypedIndexerTest()
+ object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.TypedIndexerTest()
+ object["wrong"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testMultiArgIndexer(self):
+ """Test indexers that take multiple index arguments."""
+ object = Test.MultiArgIndexerTest()
+
+ object[0, 1] = "zero one"
+ self.failUnless(object[0, 1] == "zero one")
+
+ object[1, 9] = "one nine"
+ self.failUnless(object[1, 9] == "one nine")
+
+ self.failUnless(object[10, 50] == None)
+
+ def test():
+ object = Test.MultiArgIndexerTest()
+ v = object[0, "one"]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.MultiArgIndexerTest()
+ object[0, "one"] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
+
+
+ def testMultiTypeIndexer(self):
+ """Test indexers that take multiple indices of different types."""
+ object = Test.MultiTypeIndexerTest()
+ spam = Test.Spam("spam")
+
+ object[0, "one", spam] = "zero one spam"
+ self.failUnless(object[0, "one", spam] == "zero one spam")
+
+ object[1, "nine", spam] = "one nine spam"
+ self.failUnless(object[1, "nine", spam] == "one nine spam")
+
+ def test():
+ object = Test.MultiTypeIndexerTest()
+ v = object[0, 1, spam]
+
+ self.failUnlessRaises(TypeError, test)
+
+ def test():
+ object = Test.MultiTypeIndexerTest()
+ object[0, 1, spam] = "wrong"
+
+ self.failUnlessRaises(TypeError, test)
def testIndexerWrongKeyType(self):
"""Test calling an indexer using a key of the wrong type."""
+
+ def test():
+ object = Test.PublicIndexerTest()
+ v = object["wrong"]
+
+ self.failUnlessRaises(TypeError, test)
+
def test():
object = Test.PublicIndexerTest()
object["wrong"] = "spam"
@@ -104,6 +646,7 @@
def testIndexerWrongValueType(self):
"""Test calling an indexer using a value of the wrong type."""
+
def test():
object = Test.PublicIndexerTest()
object[1] = 9993.9
@@ -119,12 +662,22 @@
def test():
del _class.__getitem__
- self.failUnlessRaises(TypeError, test)
+ self.failUnlessRaises(AttributeError, test)
def test():
del object.__getitem__
- self.failUnlessRaises(TypeError, test)
+ self.failUnlessRaises(AttributeError, test)
+
+ def test():
+ del _class.__setitem__
+
+ self.failUnlessRaises(AttributeError, test)
+
+ def test():
+ del object.__setitem__
+
+ self.failUnlessRaises(AttributeError, test)