Skip to content

Clean-up Tests #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
Remove dependency on six
Remove six.u(...), six.b(...)

Not needed since dropped older python versions
  • Loading branch information
vmuriart committed Jan 31, 2017
commit 8f2954429a75551f0a58625be78b7a0f0a7a7d1c
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ addons:
- nunit-console

install:
- pip install pycparser coverage codecov six
- pip install pycparser coverage codecov
- coverage run setup.py build_ext --inplace

script:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ init:

install:
# install for wheels & coverage
- pip install --upgrade pip wheel coverage codecov six
- pip install --upgrade pip wheel coverage codecov

# Install OpenCover. Can't put on packages.config; not Linux/Mono compatible
- .\tools\nuget\nuget.exe install OpenCover -OutputDirectory packages
Expand Down
26 changes: 5 additions & 21 deletions src/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import unittest
import Python.Test as Test
import System
import six

if six.PY3:
long = int
unichr = chr
from _compat import UserList, PY2, long, unichr


class ArrayTests(unittest.TestCase):
Expand Down Expand Up @@ -1098,10 +1094,6 @@ def testSequenceArrayConversion(self):
"""Test conversion of sequence-like objects to array arguments."""
from Python.Test import ArrayConversionTest
from Python.Test import Spam
if six.PY3:
from collections import UserList
else:
from UserList import UserList

items = UserList()
for i in range(10):
Expand All @@ -1115,10 +1107,6 @@ def testSequenceNestedArrayConversion(self):
"""Test conversion of sequences to array-of-array arguments."""
from Python.Test import ArrayConversionTest
from Python.Test import Spam
if six.PY3:
from collections import UserList
else:
from UserList import UserList

items = UserList()
for i in range(10):
Expand Down Expand Up @@ -1204,10 +1192,6 @@ def testSequenceArrayConversionTypeChecking(self):
"""Test error handling for sequence conversion to array arguments."""
from Python.Test import ArrayConversionTest
from Python.Test import Spam
if six.PY3:
from collections import UserList
else:
from UserList import UserList

# This should work, because null / None is a valid value in an
# array of reference types.
Expand Down Expand Up @@ -1322,9 +1306,9 @@ def testSpecialArrayCreation(self):
self.assertTrue(value[1] == 127)
self.assertTrue(value.Length == 2)

value = Array[System.Char]([six.u('A'), six.u('Z')])
self.assertTrue(value[0] == six.u('A'))
self.assertTrue(value[1] == six.u('Z'))
value = Array[System.Char]([u'A', u'Z'])
self.assertTrue(value[0] == u'A')
self.assertTrue(value[1] == u'Z')
self.assertTrue(value.Length == 2)

value = Array[System.Char]([0, 65535])
Expand Down Expand Up @@ -1353,7 +1337,7 @@ def testSpecialArrayCreation(self):
self.assertTrue(value.Length == 2)

# there's no explicit long type in python3, use System.Int64 instead
if not six.PY3:
if PY2:
value = Array[long]([0, long(9223372036854775807)])
self.assertTrue(value[0] == 0)
self.assertTrue(value[1] == long(9223372036854775807))
Expand Down
7 changes: 1 addition & 6 deletions src/tests/test_class.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# -*- coding: utf-8 -*-

import types
import unittest

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

if six.PY3:
DictProxyType = type(object.__dict__)
else:
DictProxyType = types.DictProxyType
from _compat import DictProxyType


class ClassTests(unittest.TestCase):
Expand Down
20 changes: 8 additions & 12 deletions src/tests/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

import unittest
import types
import six

if six.PY3:
ClassType = type
else:
ClassType = types.ClassType
from _compat import PY2, PY3, ClassType


class CompatibilityTests(unittest.TestCase):
Expand All @@ -19,10 +14,11 @@ def isCLRModule(self, object):
return type(object).__name__ == 'ModuleObject'

def isCLRRootModule(self, object):
if six.PY3:
if PY3:
# in Python 3 the clr module is a normal python module
return object.__name__ == "clr"
return type(object).__name__ == 'CLRModule'
elif PY2:
return type(object).__name__ == 'CLRModule'

def isCLRClass(self, object):
return type(object).__name__ == 'CLR Metatype' # for now
Expand All @@ -39,12 +35,12 @@ def testSimpleImport(self):
self.assertTrue(type(sys) == types.ModuleType)
self.assertTrue(sys.__name__ == 'sys')

if six.PY3:
if PY3:
import http.client
self.assertTrue(type(http.client) == types.ModuleType)
self.assertTrue(http.client.__name__ == 'http.client')

else:
elif PY2:
import httplib
self.assertTrue(type(httplib) == types.ModuleType)
self.assertTrue(httplib.__name__ == 'httplib')
Expand All @@ -59,12 +55,12 @@ def testSimpleImportWithAlias(self):
self.assertTrue(type(mySys) == types.ModuleType)
self.assertTrue(mySys.__name__ == 'sys')

if six.PY3:
if PY3:
import http.client as myHttplib
self.assertTrue(type(myHttplib) == types.ModuleType)
self.assertTrue(myHttplib.__name__ == 'http.client')

else:
elif PY2:
import httplib as myHttplib
self.assertTrue(type(myHttplib) == types.ModuleType)
self.assertTrue(myHttplib.__name__ == 'httplib')
Expand Down
42 changes: 19 additions & 23 deletions src/tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import unittest
from Python.Test import ConversionTest
import System
import six

if six.PY3:
long = int
unichr = chr
from _compat import indexbytes, long, unichr


class ConversionTests(unittest.TestCase):
Expand Down Expand Up @@ -171,16 +167,16 @@ def testCharConversion(self):
self.assertTrue(System.Char.MinValue == unichr(0))

object = ConversionTest()
self.assertTrue(object.CharField == six.u('A'))
self.assertTrue(object.CharField == u'A')

object.CharField = 'B'
self.assertTrue(object.CharField == six.u('B'))
self.assertTrue(object.CharField == u'B')

object.CharField = six.u('B')
self.assertTrue(object.CharField == six.u('B'))
object.CharField = u'B'
self.assertTrue(object.CharField == u'B')

object.CharField = 67
self.assertTrue(object.CharField == six.u('C'))
self.assertTrue(object.CharField == u'C')

def test():
ConversionTest().CharField = 65536
Expand Down Expand Up @@ -644,25 +640,25 @@ def testStringConversion(self):
object = ConversionTest()

self.assertTrue(object.StringField == "spam")
self.assertTrue(object.StringField == six.u("spam"))
self.assertTrue(object.StringField == u"spam")

object.StringField = "eggs"
self.assertTrue(object.StringField == "eggs")
self.assertTrue(object.StringField == six.u("eggs"))
self.assertTrue(object.StringField == u"eggs")

object.StringField = six.u("spam")
object.StringField = u"spam"
self.assertTrue(object.StringField == "spam")
self.assertTrue(object.StringField == six.u("spam"))
self.assertTrue(object.StringField == u"spam")

object.StringField = six.u('\uffff\uffff')
self.assertTrue(object.StringField == six.u('\uffff\uffff'))
object.StringField = u'\uffff\uffff'
self.assertTrue(object.StringField == u'\uffff\uffff')

object.StringField = System.String("spam")
self.assertTrue(object.StringField == "spam")
self.assertTrue(object.StringField == six.u("spam"))
self.assertTrue(object.StringField == u"spam")

object.StringField = System.String(six.u('\uffff\uffff'))
self.assertTrue(object.StringField == six.u('\uffff\uffff'))
object.StringField = System.String(u'\uffff\uffff')
self.assertTrue(object.StringField == u'\uffff\uffff')

object.StringField = None
self.assertTrue(object.StringField == None)
Expand Down Expand Up @@ -809,11 +805,11 @@ def testByteArrayConversion(self):
self.assertTrue(array[0] == 0)
self.assertTrue(array[4] == 4)

value = six.b("testing")
value = b"testing"
object.ByteArrayField = value
array = object.ByteArrayField
for i in range(len(value)):
self.assertTrue(array[i] == six.indexbytes(value, i))
self.assertTrue(array[i] == indexbytes(value, i))

def testSByteArrayConversion(self):
"""Test sbyte array conversion."""
Expand All @@ -827,11 +823,11 @@ def testSByteArrayConversion(self):
self.assertTrue(array[0] == 0)
self.assertTrue(array[4] == 4)

value = six.b("testing")
value = b"testing"
object.SByteArrayField = value
array = object.SByteArrayField
for i in range(len(value)):
self.assertTrue(array[i] == six.indexbytes(value, i))
self.assertTrue(array[i] == indexbytes(value, i))


def test_suite():
Expand Down
8 changes: 1 addition & 7 deletions src/tests/test_delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@
from Python.Test import StringDelegate, ObjectDelegate
from Python.Test import BoolDelegate
import unittest
import types
import Python.Test as Test
import System
import six

if six.PY3:
DictProxyType = type(object.__dict__)
else:
DictProxyType = types.DictProxyType
from _compat import DictProxyType


class DelegateTests(unittest.TestCase):
Expand Down
9 changes: 1 addition & 8 deletions src/tests/test_enum.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
# -*- coding: utf-8 -*-

import unittest
import types
from System import DayOfWeek
from Python import Test
import six

if six.PY3:
DictProxyType = type(object.__dict__)
long = int
else:
DictProxyType = types.DictProxyType
from _compat import DictProxyType, long


class EnumTests(unittest.TestCase):
Expand Down
32 changes: 13 additions & 19 deletions src/tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import sys
import unittest
import System
import six

if six.PY3:
unicode = str
from _compat import PY2, PY3, pickle, text_type


class ExceptionTests(unittest.TestCase):
Expand All @@ -17,7 +14,7 @@ def testUnifiedExceptionSemantics(self):
from System import Exception, Object

e = Exception('Something bad happened')
if not six.PY3:
if PY2:
import exceptions
self.assertTrue(isinstance(e, exceptions.Exception))
self.assertTrue(isinstance(e, Exception))
Expand Down Expand Up @@ -212,9 +209,9 @@ def testCatchExceptionManagedClass(self):
def testCatchExceptionPythonClass(self):
"""Test catching the python class of an exception."""
from System import OverflowException
if six.PY3:
if PY3:
from builtins import Exception
else:
elif PY2:
from exceptions import Exception

try:
Expand Down Expand Up @@ -288,8 +285,8 @@ def testStrOfException(self):
Convert.ToDateTime('this will fail')
except FormatException:
e = sys.exc_info()[1]
msg = unicode(e).encode("utf8") # fix for international installation
self.assertTrue(msg.find(unicode('System.Convert.ToDateTime').encode("utf8")) > -1, msg)
msg = text_type(e).encode("utf8") # fix for international installation
self.assertTrue(msg.find(text_type('System.Convert.ToDateTime').encode("utf8")) > -1, msg)

def testPythonCompatOfManagedExceptions(self):
"""Test if managed exceptions are compatible with Python's implementation
Expand All @@ -299,14 +296,14 @@ def testPythonCompatOfManagedExceptions(self):

e = OverflowException(msg)
self.assertEqual(str(e), msg)
self.assertEqual(unicode(e), msg)
self.assertEqual(text_type(e), msg)

self.assertEqual(e.args, (msg,))
self.assertTrue(isinstance(e.args, tuple))
if six.PY2:
self.assertEqual(repr(e), "OverflowException(u'A simple message',)")
else:
if PY3:
self.assertEqual(repr(e), "OverflowException('A simple message',)")
elif PY2:
self.assertEqual(repr(e), "OverflowException(u'A simple message',)")

def testExceptionIsInstanceOfSystemObject(self):
"""Test behavior of isinstance(<managed exception>, System.Object)."""
Expand Down Expand Up @@ -337,10 +334,6 @@ def testExceptionIsInstanceOfSystemObject(self):

def testPicklingExceptions(self):
from System import Exception
try:
import cPickle as pickle
except ImportError:
import pickle

exc = Exception("test")
dumped = pickle.dumps(exc)
Expand All @@ -349,7 +342,8 @@ def testPicklingExceptions(self):
self.assertEqual(exc.args, loaded.args)

def testChainedExceptions(self):
if six.PY3:
# TODO: Why is this test PY3 only?
if PY3:
from Python.Test import ExceptionTest

try:
Expand All @@ -358,7 +352,7 @@ def testChainedExceptions(self):
msgs = [
"Outer exception",
"Inner exception",
"Innermost exception"
"Innermost exception",
]

for msg in msgs:
Expand Down
Loading