Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
d9dcbc32
Commit
d9dcbc32
authored
May 13, 2011
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Py3 test fixes
parent
11a35a32
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
22 deletions
+31
-22
tests/run/reversed_iteration.pyx
tests/run/reversed_iteration.pyx
+31
-22
No files found.
tests/run/reversed_iteration.pyx
View file @
d9dcbc32
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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment