Commit d9dcbc32 authored by Stefan Behnel's avatar Stefan Behnel

Py3 test fixes

parent 11a35a32
cimport cython cimport cython
import sys
IS_PY3 = sys.version_info[0] >= 3
def _reversed(it): def _reversed(it):
return list(it)[::-1] return list(it)[::-1]
...@@ -19,15 +22,13 @@ def reversed_list(list l): ...@@ -19,15 +22,13 @@ def reversed_list(list l):
@cython.test_assert_path_exists('//ForFromStatNode') @cython.test_assert_path_exists('//ForFromStatNode')
def reversed_range(int N): def reversed_range(int N):
""" """
>>> i = 99 >>> [ i for i in _reversed(range(5)) ]
>>> [ i for i in _reversed(range(5)) ], i [4, 3, 2, 1, 0]
([4, 3, 2, 1, 0], 0)
>>> reversed_range(5) >>> reversed_range(5)
([4, 3, 2, 1, 0], 0) ([4, 3, 2, 1, 0], 0)
>>> i = 99 >>> [ i for i in _reversed(range(0)) ]
>>> ([ i for i in _reversed(range(0)) ], i) []
([], 99)
>>> reversed_range(0) >>> reversed_range(0)
([], 99) ([], 99)
""" """
...@@ -135,11 +136,13 @@ join_bytes = b''.join ...@@ -135,11 +136,13 @@ join_bytes = b''.join
@cython.test_assert_path_exists('//ForFromStatNode') @cython.test_assert_path_exists('//ForFromStatNode')
def reversed_bytes(bytes s): def reversed_bytes(bytes s):
""" """
>>> print(join_bytes(_reversed(bytes_string)).decode('ASCII')) >>> b = IS_PY3 and bytes_string or map(ord, bytes_string)
FEDcba >>> list(_reversed(b))
>>> print(join_bytes(reversed_bytes(bytes_string)).decode('ASCII')) [70, 69, 68, 99, 98, 97]
FEDcba >>> reversed_bytes(bytes_string)
[70, 69, 68, 99, 98, 97]
""" """
cdef char c
result = [] result = []
for c in reversed(s): for c in reversed(s):
result.append(c) result.append(c)
...@@ -148,11 +151,13 @@ def reversed_bytes(bytes s): ...@@ -148,11 +151,13 @@ def reversed_bytes(bytes s):
@cython.test_assert_path_exists('//ForFromStatNode') @cython.test_assert_path_exists('//ForFromStatNode')
def reversed_bytes_slice(bytes s): def reversed_bytes_slice(bytes s):
""" """
>>> print(join_bytes(_reversed(bytes_string[1:-2])).decode('ASCII')) >>> b = IS_PY3 and bytes_string or map(ord, bytes_string)
Dcb >>> list(_reversed(b[1:-2]))
>>> print(join_bytes(reversed_bytes_slice(bytes_string)).decode('ASCII')) [68, 99, 98]
Dcb >>> reversed_bytes_slice(bytes_string)
[68, 99, 98]
""" """
cdef char c
result = [] result = []
for c in reversed(s[1:-2]): for c in reversed(s[1:-2]):
result.append(c) result.append(c)
...@@ -161,11 +166,13 @@ def reversed_bytes_slice(bytes s): ...@@ -161,11 +166,13 @@ def reversed_bytes_slice(bytes s):
@cython.test_assert_path_exists('//ForFromStatNode') @cython.test_assert_path_exists('//ForFromStatNode')
def reversed_bytes_slice_step(bytes s): def reversed_bytes_slice_step(bytes s):
""" """
>>> print(join_bytes(_reversed(bytes_string[-2:1:-1])).decode('ASCII')) >>> b = IS_PY3 and bytes_string or map(ord, bytes_string)
cDE >>> list(_reversed(b[-2:1:-1]))
>>> print(join_bytes(reversed_bytes_slice_step(bytes_string)).decode('ASCII')) [99, 68, 69]
cDE >>> reversed_bytes_slice_step(bytes_string)
[99, 68, 69]
""" """
cdef char c
result = [] result = []
for c in reversed(s[-2:1:-1]): for c in reversed(s[-2:1:-1]):
result.append(c) result.append(c)
...@@ -174,11 +181,13 @@ def reversed_bytes_slice_step(bytes s): ...@@ -174,11 +181,13 @@ def reversed_bytes_slice_step(bytes s):
@cython.test_assert_path_exists('//ForFromStatNode') @cython.test_assert_path_exists('//ForFromStatNode')
def reversed_bytes_slice_step_only(bytes s): def reversed_bytes_slice_step_only(bytes s):
""" """
>>> print(join_bytes(_reversed(bytes_string[::-1])).decode('ASCII')) >>> b = IS_PY3 and bytes_string or map(ord, bytes_string)
abcDEF >>> list(_reversed(b[::-1]))
>>> print(join_bytes(reversed_bytes_slice_step_only(bytes_string)).decode('ASCII')) [97, 98, 99, 68, 69, 70]
abcDEF >>> reversed_bytes_slice_step_only(bytes_string)
[97, 98, 99, 68, 69, 70]
""" """
cdef char c
result = [] result = []
for c in reversed(s[::-1]): for c in reversed(s[::-1]):
result.append(c) result.append(c)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment