Skip to content
Prev Previous commit
Next Next commit
Clean-up imports
- Fix py2/py3 range/zip behavior
  - Ensure same functions being used
- Fix Exception/System.Exception name clashes
  • Loading branch information
vmuriart committed Jan 31, 2017
commit 30470bbaa293885c54c629d26c8f4d764e188313
4 changes: 3 additions & 1 deletion src/tests/test_array.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-

import unittest

import Python.Test as Test
import System
from _compat import UserList, PY2, long, unichr

from _compat import PY2, UserList, long, range, unichr


class ArrayTests(unittest.TestCase):
Expand Down
31 changes: 21 additions & 10 deletions src/tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

import Python.Test as Test
import System
from Python.Test import ClassTest
from System.Collections import Hashtable

from _compat import DictProxyType
from _compat import DictProxyType, range


class ClassTests(unittest.TestCase):
Expand All @@ -25,13 +23,17 @@ def testBasicValueType(self):

def testClassStandardAttrs(self):
"""Test standard class attributes."""
from Python.Test import ClassTest

self.assertTrue(ClassTest.__name__ == 'ClassTest')
self.assertTrue(ClassTest.__module__ == 'Python.Test')
self.assertTrue(type(ClassTest.__dict__) == DictProxyType)
self.assertTrue(len(ClassTest.__doc__) > 0)

def testClassDocstrings(self):
"""Test standard class docstring generation"""
from Python.Test import ClassTest

value = 'Void .ctor()'
self.assertTrue(ClassTest.__doc__ == value)

Expand All @@ -47,7 +49,6 @@ def testClassDefaultRepr(self):

def testNonPublicClass(self):
"""Test that non-public classes are inaccessible."""
from Python import Test

def test():
from Python.Test import InternalClass
Expand All @@ -61,6 +62,7 @@ def test():

def testBasicSubclass(self):
"""Test basic subclass of a managed class."""
from System.Collections import Hashtable

class MyTable(Hashtable):
def howMany(self):
Expand Down Expand Up @@ -141,26 +143,31 @@ def testStructConstruction(self):

def testIEnumerableIteration(self):
"""Test iteration over objects supporting IEnumerable."""
list = Test.ClassTest.GetArrayList()
from Python.Test import ClassTest

list = ClassTest.GetArrayList()

for item in list:
self.assertTrue((item > -1) and (item < 10))

dict = Test.ClassTest.GetHashtable()
dict = ClassTest.GetHashtable()

for item in dict:
cname = item.__class__.__name__
self.assertTrue(cname.endswith('DictionaryEntry'))

def testIEnumeratorIteration(self):
"""Test iteration over objects supporting IEnumerator."""
chars = Test.ClassTest.GetEnumerator()
from Python.Test import ClassTest

chars = ClassTest.GetEnumerator()

for item in chars:
self.assertTrue(item in 'test string')

def testOverrideGetItem(self):
"""Test managed subclass overriding __getitem__."""
from System.Collections import Hashtable

class MyTable(Hashtable):
def __getitem__(self, key):
Expand All @@ -180,6 +187,7 @@ def __getitem__(self, key):

def testOverrideSetItem(self):
"""Test managed subclass overriding __setitem__."""
from System.Collections import Hashtable

class MyTable(Hashtable):
def __setitem__(self, key, value):
Expand All @@ -198,10 +206,9 @@ def __setitem__(self, key, value):
self.assertTrue(table.Count == 3)

def testAddAndRemoveClassAttribute(self):

from System import TimeSpan

for i in range(100):
for _ in range(100):
TimeSpan.new_method = lambda self: self.TotalMinutes
ts = TimeSpan.FromHours(1)
self.assertTrue(ts.new_method() == 60)
Expand All @@ -210,6 +217,7 @@ def testAddAndRemoveClassAttribute(self):

def testComparisons(self):
from System import DateTimeOffset
from Python.Test import ClassTest

d1 = DateTimeOffset.Parse("2016-11-14")
d2 = DateTimeOffset.Parse("2016-11-15")
Expand Down Expand Up @@ -247,12 +255,14 @@ def testComparisons(self):
self.assertRaises(TypeError, lambda: c1 < c2)

def testSelfCallback(self):
""" Test calling back and forth between this and a c# baseclass."""
"""Test calling back and forth between this and a c# baseclass."""

class CallbackUser(Test.SelfCallbackTest):
def DoCallback(self):
self.PyCallbackWasCalled = False
self.SameReference = False
return self.Callback(self)

def PyCallback(self, self2):
self.PyCallbackWasCalled = True
self.SameReference = self == self2
Expand All @@ -262,6 +272,7 @@ def PyCallback(self, self2):
self.assertTrue(testobj.PyCallbackWasCalled)
self.assertTrue(testobj.SameReference)


class ClassicClass:
def kind(self):
return 'classic'
Expand Down
5 changes: 3 additions & 2 deletions src/tests/test_compat.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-

import unittest
import types
from _compat import PY2, PY3, ClassType
import unittest

from _compat import ClassType, PY2, PY3, range


class CompatibilityTests(unittest.TestCase):
Expand Down
1 change: 1 addition & 0 deletions src/tests/test_constructors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import unittest

import System


Expand Down
6 changes: 4 additions & 2 deletions src/tests/test_conversion.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-

import unittest
from Python.Test import ConversionTest

import System
from _compat import indexbytes, long, unichr
from Python.Test import ConversionTest

from _compat import indexbytes, long, range, unichr


class ConversionTests(unittest.TestCase):
Expand Down
11 changes: 8 additions & 3 deletions src/tests/test_delegate.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
# TODO: Add test for ObjectDelegate

from Python.Test import DelegateTest, PublicDelegate
from Python.Test import StringDelegate, ObjectDelegate
from Python.Test import BoolDelegate
import unittest

import Python.Test as Test
import System
from Python.Test import DelegateTest, StringDelegate

from _compat import DictProxyType


Expand All @@ -14,6 +15,8 @@ class DelegateTests(unittest.TestCase):

def testDelegateStandardAttrs(self):
"""Test standard delegate attributes."""
from Python.Test import PublicDelegate

self.assertTrue(PublicDelegate.__name__ == 'PublicDelegate')
self.assertTrue(PublicDelegate.__module__ == 'Python.Test')
self.assertTrue(type(PublicDelegate.__dict__) == DictProxyType)
Expand Down Expand Up @@ -264,6 +267,7 @@ def count(self):

def testSubclassDelegateFails(self):
"""Test that subclassing of a delegate type fails."""
from Python.Test import PublicDelegate

def test():
class Boom(PublicDelegate):
Expand All @@ -284,6 +288,7 @@ def sayhello():

def testBoolDelegate(self):
"""Test boolean delegate."""
from Python.Test import BoolDelegate

def always_so_negative():
return 0
Expand Down
8 changes: 6 additions & 2 deletions src/tests/test_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@

import unittest

from Python.Test import DocWithCtorTest, DocWithoutCtorTest, DocWithCtorNoDocTest


class DocStringTests(unittest.TestCase):
"""Test doc strings support."""

def testDocWithCtor(self):
from Python.Test import DocWithCtorTest

self.assertEqual(DocWithCtorTest.__doc__, 'DocWithCtorTest Class')
self.assertEqual(DocWithCtorTest.TestMethod.__doc__, 'DocWithCtorTest TestMethod')
self.assertEqual(DocWithCtorTest.StaticTestMethod.__doc__, 'DocWithCtorTest StaticTestMethod')

def testDocWithCtorNoDoc(self):
from Python.Test import DocWithCtorNoDocTest

self.assertEqual(DocWithCtorNoDocTest.__doc__, 'Void .ctor(Boolean)')
self.assertEqual(DocWithCtorNoDocTest.TestMethod.__doc__, 'Void TestMethod(Double, Int32)')
self.assertEqual(DocWithCtorNoDocTest.StaticTestMethod.__doc__, 'Void StaticTestMethod(Double, Int32)')

def testDocWithoutCtor(self):
from Python.Test import DocWithoutCtorTest

self.assertEqual(DocWithoutCtorTest.__doc__, 'DocWithoutCtorTest Class')
self.assertEqual(DocWithoutCtorTest.TestMethod.__doc__, 'DocWithoutCtorTest TestMethod')
self.assertEqual(DocWithoutCtorTest.StaticTestMethod.__doc__, 'DocWithoutCtorTest StaticTestMethod')
Expand Down
5 changes: 3 additions & 2 deletions src/tests/test_engine.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
# FIXME: This test module fails due to unhandled exceptions

import sys
import unittest
from Python.Runtime import PythonEngine

import System
from Python.Runtime import PythonEngine

# XXX This test module isn't used!

class EngineTests(unittest.TestCase):
"""Test PythonEngine embedding APIs."""
Expand Down
12 changes: 10 additions & 2 deletions src/tests/test_enum.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-

import unittest
from System import DayOfWeek
from Python import Test

import Python.Test as Test

from _compat import DictProxyType, long


Expand All @@ -11,13 +12,17 @@ class EnumTests(unittest.TestCase):

def testEnumStandardAttrs(self):
"""Test standard enum attributes."""
from System import DayOfWeek

self.assertTrue(DayOfWeek.__name__ == 'DayOfWeek')
self.assertTrue(DayOfWeek.__module__ == 'System')
self.assertTrue(type(DayOfWeek.__dict__) == DictProxyType)
self.assertTrue(DayOfWeek.__doc__ == None)

def testEnumGetMember(self):
"""Test access to enum members."""
from System import DayOfWeek

self.assertTrue(DayOfWeek.Sunday == 0)
self.assertTrue(DayOfWeek.Monday == 1)
self.assertTrue(DayOfWeek.Tuesday == 2)
Expand Down Expand Up @@ -76,6 +81,7 @@ def testULongEnum(self):

def testInstantiateEnumFails(self):
"""Test that instantiation of an enum class fails."""
from System import DayOfWeek

def test():
ob = DayOfWeek()
Expand All @@ -84,6 +90,7 @@ def test():

def testSubclassEnumFails(self):
"""Test that subclassing of an enumeration fails."""
from System import DayOfWeek

def test():
class Boom(DayOfWeek):
Expand All @@ -93,6 +100,7 @@ class Boom(DayOfWeek):

def testEnumSetMemberFails(self):
"""Test that setattr operations on enumerations fail."""
from System import DayOfWeek

def test():
DayOfWeek.Sunday = 13
Expand Down
10 changes: 7 additions & 3 deletions src/tests/test_event.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-

import unittest
from Python.Test import EventTest, TestEventHandler
from Python.Test import TestEventArgs

from Python.Test import EventTest, TestEventArgs

from _compat import range


class EventTests(unittest.TestCase):
Expand Down Expand Up @@ -515,7 +517,7 @@ def test():
object.PublicEvent -= handler.handler

def testIncorrectInvokation(self):
"""Test incorrect invokation of events."""
"""Test incorrect invocation of events."""
object = EventTest()

handler = GenericHandler()
Expand All @@ -535,6 +537,8 @@ def test():

def testExplicitCLSEventRegistration(self):
"""Test explicit CLS event registration."""
from Python.Test import TestEventHandler

object = EventTest()
handler = GenericHandler()

Expand Down
Loading