Skip to content
This repository was archived by the owner on Jul 22, 2023. It is now read-only.

Commit a51a4bf

Browse files
committed
Remove dependency on six
Remove six.u(...), six.b(...) Not needed since dropped older python versions
1 parent fb71914 commit a51a4bf

17 files changed

+103
-190
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ addons:
2525
- nunit-console
2626

2727
install:
28-
- pip install pycparser coverage codecov six
28+
- pip install pycparser coverage codecov
2929
- coverage run setup.py build_ext --inplace
3030

3131
script:

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ init:
4646

4747
install:
4848
# install for wheels & coverage
49-
- pip install --upgrade pip wheel coverage codecov six
49+
- pip install --upgrade pip wheel coverage codecov
5050

5151
# Install OpenCover. Can't put on packages.config; not Linux/Mono compatible
5252
- .\tools\nuget\nuget.exe install OpenCover -OutputDirectory packages

src/tests/test_array.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
import unittest
44
import Python.Test as Test
55
import System
6-
import six
7-
8-
if six.PY3:
9-
long = int
10-
unichr = chr
6+
from _compat import UserList, PY2, long, unichr
117

128

139
class ArrayTests(unittest.TestCase):
@@ -1098,10 +1094,6 @@ def testSequenceArrayConversion(self):
10981094
"""Test conversion of sequence-like objects to array arguments."""
10991095
from Python.Test import ArrayConversionTest
11001096
from Python.Test import Spam
1101-
if six.PY3:
1102-
from collections import UserList
1103-
else:
1104-
from UserList import UserList
11051097

11061098
items = UserList()
11071099
for i in range(10):
@@ -1115,10 +1107,6 @@ def testSequenceNestedArrayConversion(self):
11151107
"""Test conversion of sequences to array-of-array arguments."""
11161108
from Python.Test import ArrayConversionTest
11171109
from Python.Test import Spam
1118-
if six.PY3:
1119-
from collections import UserList
1120-
else:
1121-
from UserList import UserList
11221110

11231111
items = UserList()
11241112
for i in range(10):
@@ -1204,10 +1192,6 @@ def testSequenceArrayConversionTypeChecking(self):
12041192
"""Test error handling for sequence conversion to array arguments."""
12051193
from Python.Test import ArrayConversionTest
12061194
from Python.Test import Spam
1207-
if six.PY3:
1208-
from collections import UserList
1209-
else:
1210-
from UserList import UserList
12111195

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

1325-
value = Array[System.Char]([six.u('A'), six.u('Z')])
1326-
self.assertTrue(value[0] == six.u('A'))
1327-
self.assertTrue(value[1] == six.u('Z'))
1309+
value = Array[System.Char]([u'A', u'Z'])
1310+
self.assertTrue(value[0] == u'A')
1311+
self.assertTrue(value[1] == u'Z')
13281312
self.assertTrue(value.Length == 2)
13291313

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

13551339
# there's no explicit long type in python3, use System.Int64 instead
1356-
if not six.PY3:
1340+
if PY2:
13571341
value = Array[long]([0, long(9223372036854775807)])
13581342
self.assertTrue(value[0] == 0)
13591343
self.assertTrue(value[1] == long(9223372036854775807))

src/tests/test_class.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
# -*- coding: utf-8 -*-
22

3-
import types
43
import unittest
54

65
import Python.Test as Test
76
import System
8-
import six
97
from Python.Test import ClassTest
108
from System.Collections import Hashtable
119

12-
if six.PY3:
13-
DictProxyType = type(object.__dict__)
14-
else:
15-
DictProxyType = types.DictProxyType
10+
from _compat import DictProxyType
1611

1712

1813
class ClassTests(unittest.TestCase):

src/tests/test_compat.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
import unittest
44
import types
5-
import six
6-
7-
if six.PY3:
8-
ClassType = type
9-
else:
10-
ClassType = types.ClassType
5+
from _compat import PY2, PY3, ClassType
116

127

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

2116
def isCLRRootModule(self, object):
22-
if six.PY3:
17+
if PY3:
2318
# in Python 3 the clr module is a normal python module
2419
return object.__name__ == "clr"
25-
return type(object).__name__ == 'CLRModule'
20+
elif PY2:
21+
return type(object).__name__ == 'CLRModule'
2622

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

42-
if six.PY3:
38+
if PY3:
4339
import http.client
4440
self.assertTrue(type(http.client) == types.ModuleType)
4541
self.assertTrue(http.client.__name__ == 'http.client')
4642

47-
else:
43+
elif PY2:
4844
import httplib
4945
self.assertTrue(type(httplib) == types.ModuleType)
5046
self.assertTrue(httplib.__name__ == 'httplib')
@@ -59,12 +55,12 @@ def testSimpleImportWithAlias(self):
5955
self.assertTrue(type(mySys) == types.ModuleType)
6056
self.assertTrue(mySys.__name__ == 'sys')
6157

62-
if six.PY3:
58+
if PY3:
6359
import http.client as myHttplib
6460
self.assertTrue(type(myHttplib) == types.ModuleType)
6561
self.assertTrue(myHttplib.__name__ == 'http.client')
6662

67-
else:
63+
elif PY2:
6864
import httplib as myHttplib
6965
self.assertTrue(type(myHttplib) == types.ModuleType)
7066
self.assertTrue(myHttplib.__name__ == 'httplib')

src/tests/test_conversion.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
import unittest
44
from Python.Test import ConversionTest
55
import System
6-
import six
7-
8-
if six.PY3:
9-
long = int
10-
unichr = chr
6+
from _compat import indexbytes, long, unichr
117

128

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

173169
object = ConversionTest()
174-
self.assertTrue(object.CharField == six.u('A'))
170+
self.assertTrue(object.CharField == u'A')
175171

176172
object.CharField = 'B'
177-
self.assertTrue(object.CharField == six.u('B'))
173+
self.assertTrue(object.CharField == u'B')
178174

179-
object.CharField = six.u('B')
180-
self.assertTrue(object.CharField == six.u('B'))
175+
object.CharField = u'B'
176+
self.assertTrue(object.CharField == u'B')
181177

182178
object.CharField = 67
183-
self.assertTrue(object.CharField == six.u('C'))
179+
self.assertTrue(object.CharField == u'C')
184180

185181
def test():
186182
ConversionTest().CharField = 65536
@@ -644,25 +640,25 @@ def testStringConversion(self):
644640
object = ConversionTest()
645641

646642
self.assertTrue(object.StringField == "spam")
647-
self.assertTrue(object.StringField == six.u("spam"))
643+
self.assertTrue(object.StringField == u"spam")
648644

649645
object.StringField = "eggs"
650646
self.assertTrue(object.StringField == "eggs")
651-
self.assertTrue(object.StringField == six.u("eggs"))
647+
self.assertTrue(object.StringField == u"eggs")
652648

653-
object.StringField = six.u("spam")
649+
object.StringField = u"spam"
654650
self.assertTrue(object.StringField == "spam")
655-
self.assertTrue(object.StringField == six.u("spam"))
651+
self.assertTrue(object.StringField == u"spam")
656652

657-
object.StringField = six.u('\uffff\uffff')
658-
self.assertTrue(object.StringField == six.u('\uffff\uffff'))
653+
object.StringField = u'\uffff\uffff'
654+
self.assertTrue(object.StringField == u'\uffff\uffff')
659655

660656
object.StringField = System.String("spam")
661657
self.assertTrue(object.StringField == "spam")
662-
self.assertTrue(object.StringField == six.u("spam"))
658+
self.assertTrue(object.StringField == u"spam")
663659

664-
object.StringField = System.String(six.u('\uffff\uffff'))
665-
self.assertTrue(object.StringField == six.u('\uffff\uffff'))
660+
object.StringField = System.String(u'\uffff\uffff')
661+
self.assertTrue(object.StringField == u'\uffff\uffff')
666662

667663
object.StringField = None
668664
self.assertTrue(object.StringField == None)
@@ -809,11 +805,11 @@ def testByteArrayConversion(self):
809805
self.assertTrue(array[0] == 0)
810806
self.assertTrue(array[4] == 4)
811807

812-
value = six.b("testing")
808+
value = b"testing"
813809
object.ByteArrayField = value
814810
array = object.ByteArrayField
815811
for i in range(len(value)):
816-
self.assertTrue(array[i] == six.indexbytes(value, i))
812+
self.assertTrue(array[i] == indexbytes(value, i))
817813

818814
def testSByteArrayConversion(self):
819815
"""Test sbyte array conversion."""
@@ -827,11 +823,11 @@ def testSByteArrayConversion(self):
827823
self.assertTrue(array[0] == 0)
828824
self.assertTrue(array[4] == 4)
829825

830-
value = six.b("testing")
826+
value = b"testing"
831827
object.SByteArrayField = value
832828
array = object.SByteArrayField
833829
for i in range(len(value)):
834-
self.assertTrue(array[i] == six.indexbytes(value, i))
830+
self.assertTrue(array[i] == indexbytes(value, i))
835831

836832

837833
def test_suite():

src/tests/test_delegate.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@
44
from Python.Test import StringDelegate, ObjectDelegate
55
from Python.Test import BoolDelegate
66
import unittest
7-
import types
87
import Python.Test as Test
98
import System
10-
import six
11-
12-
if six.PY3:
13-
DictProxyType = type(object.__dict__)
14-
else:
15-
DictProxyType = types.DictProxyType
9+
from _compat import DictProxyType
1610

1711

1812
class DelegateTests(unittest.TestCase):

src/tests/test_enum.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
# -*- coding: utf-8 -*-
22

33
import unittest
4-
import types
54
from System import DayOfWeek
65
from Python import Test
7-
import six
8-
9-
if six.PY3:
10-
DictProxyType = type(object.__dict__)
11-
long = int
12-
else:
13-
DictProxyType = types.DictProxyType
6+
from _compat import DictProxyType, long
147

158

169
class EnumTests(unittest.TestCase):

src/tests/test_exceptions.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import sys
44
import unittest
55
import System
6-
import six
7-
8-
if six.PY3:
9-
unicode = str
6+
from _compat import PY2, PY3, pickle, text_type
107

118

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

1916
e = Exception('Something bad happened')
20-
if not six.PY3:
17+
if PY2:
2118
import exceptions
2219
self.assertTrue(isinstance(e, exceptions.Exception))
2320
self.assertTrue(isinstance(e, Exception))
@@ -212,9 +209,9 @@ def testCatchExceptionManagedClass(self):
212209
def testCatchExceptionPythonClass(self):
213210
"""Test catching the python class of an exception."""
214211
from System import OverflowException
215-
if six.PY3:
212+
if PY3:
216213
from builtins import Exception
217-
else:
214+
elif PY2:
218215
from exceptions import Exception
219216

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

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

300297
e = OverflowException(msg)
301298
self.assertEqual(str(e), msg)
302-
self.assertEqual(unicode(e), msg)
299+
self.assertEqual(text_type(e), msg)
303300

304301
self.assertEqual(e.args, (msg,))
305302
self.assertTrue(isinstance(e.args, tuple))
306-
if six.PY2:
307-
self.assertEqual(repr(e), "OverflowException(u'A simple message',)")
308-
else:
303+
if PY3:
309304
self.assertEqual(repr(e), "OverflowException('A simple message',)")
305+
elif PY2:
306+
self.assertEqual(repr(e), "OverflowException(u'A simple message',)")
310307

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

338335
def testPicklingExceptions(self):
339336
from System import Exception
340-
try:
341-
import cPickle as pickle
342-
except ImportError:
343-
import pickle
344337

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

351344
def testChainedExceptions(self):
352-
if six.PY3:
345+
# TODO: Why is this test PY3 only?
346+
if PY3:
353347
from Python.Test import ExceptionTest
354348

355349
try:
@@ -358,7 +352,7 @@ def testChainedExceptions(self):
358352
msgs = [
359353
"Outer exception",
360354
"Inner exception",
361-
"Innermost exception"
355+
"Innermost exception",
362356
]
363357

364358
for msg in msgs:

0 commit comments

Comments
 (0)