Skip to content

Commit 5adee64

Browse files
committed
tests: fix unicode issues
1 parent 294b0f5 commit 5adee64

7 files changed

+25
-16
lines changed

src/pyrobase/testing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
from contextlib import contextmanager
2323

2424
try:
25-
from io import StringIO
26-
except ImportError:
2725
from StringIO import StringIO
26+
except ImportError:
27+
from io import StringIO
2828

2929
try:
3030
import mock

src/tests/test_bencode.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# You should have received a copy of the GNU General Public License along
1818
# with this program; if not, write to the Free Software Foundation, Inc.,
1919
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20-
from __future__ import with_statement
20+
from __future__ import absolute_import, print_function #, unicode_literals
2121

2222
import logging
2323
import unittest

src/tests/test_fmt.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
with this program; if not, write to the Free Software Foundation, Inc.,
1717
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1818
"""
19+
from __future__ import absolute_import, print_function, unicode_literals
20+
1921
import time
2022
import logging
2123
import unittest
@@ -92,13 +94,13 @@ def test_to_unicode(self):
9294
(u"", u""),
9395
(False, False),
9496
(None, None),
95-
("\xc3\xaa", u"\xea"),
96-
("\x80", u"\u20ac"),
97-
("\x81", "\x81"),
98-
("\x8d", "\x8d"),
99-
("\x8f", "\x8f"),
100-
("\x90", "\x90"),
101-
("\x9d", "\x9d"),
97+
(b"\xc3\xaa", u"\xea"),
98+
(b"\x80", u"\u20ac"),
99+
(b"\x81", b"\x81"),
100+
(b"\x8d", b"\x8d"),
101+
(b"\x8f", b"\x8f"),
102+
(b"\x90", b"\x90"),
103+
(b"\x9d", b"\x9d"),
102104
]
103105
for val, expected in cases:
104106
result = fmt.to_unicode(val)
@@ -110,9 +112,9 @@ def test_to_utf8(self):
110112
(u"", u""),
111113
(False, False),
112114
(None, None),
113-
(u"\xea", "\xc3\xaa",),
114-
(u"\u20ac", "\xe2\x82\xac"),
115-
("\xc3\xaa", "\xc3\xaa"),
115+
(u"\xea", b"\xc3\xaa",),
116+
(u"\u20ac", b"\xe2\x82\xac"),
117+
(b"\xc3\xaa", b"\xc3\xaa"),
116118
(b"\xfe\xff\x00\x20", u" "),
117119
(b"\xff\xfe\x20\x00", u" "),
118120
(b"\xef\xbb\xbf\x20", u" "),
@@ -128,7 +130,7 @@ def test_to_console(self):
128130
(u"", b""),
129131
(u"\xea", b"\xc3\xaa",),
130132
(u"\u20ac", b"\xe2\x82\xac"),
131-
("\xc3\xaa", b"\xc3\xaa"),
133+
(b"\xc3\xaa", b"\xc3\xaa"),
132134
(b"\xfe\xff\x00\x20", b"\xfe\xff\x00\x20"),
133135
(b"\xef\xbb\xbf\x20", b"\xef\xbb\xbf\x20"),
134136
(b"\xc3\xc3\x81", b"\xc3\xc3\x81"),

src/tests/test_iterutil.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
with this program; if not, write to the Free Software Foundation, Inc.,
1717
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1818
"""
19+
from __future__ import absolute_import, print_function, unicode_literals
20+
1921
import logging
2022
import unittest
2123

@@ -31,7 +33,7 @@ def test_flatten(self):
3133
def yielding():
3234
yield 1
3335
yield (2, "3")
34-
36+
3537
cases = [
3638
([], []),
3739
((1, "2"), [1, "2"]),
@@ -41,4 +43,3 @@ def yielding():
4143
for val, expected in cases:
4244
result = list(iterutil.flatten(val))
4345
assert result == expected
44-

src/tests/test_osutil.py

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
with this program; if not, write to the Free Software Foundation, Inc.,
1717
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1818
"""
19+
from __future__ import absolute_import, print_function, unicode_literals
20+
1921
import unittest
2022

2123
from pyrobase import osutil

src/tests/test_parts.py

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
with this program; if not, write to the Free Software Foundation, Inc.,
1717
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1818
"""
19+
from __future__ import absolute_import, print_function, unicode_literals
20+
1921
import logging
2022
import unittest
2123

src/tests/test_xmlrpc2scgi.py

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# You should have received a copy of the GNU General Public License along
1818
# with this program; if not, write to the Free Software Foundation, Inc.,
1919
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20+
from __future__ import absolute_import, print_function, unicode_literals
21+
2022
import time
2123
import socket
2224
import logging

0 commit comments

Comments
 (0)