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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
225da25f
Commit
225da25f
authored
Jul 22, 2018
by
cjgibson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing test cases for Python3, added unicode.
parent
3a810f55
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
264 additions
and
161 deletions
+264
-161
tests/run/typed_slice.pyx
tests/run/typed_slice.pyx
+264
-161
No files found.
tests/run/typed_slice.pyx
View file @
225da25f
...
...
@@ -208,31 +208,35 @@ ctypedef fused slicable:
list
tuple
bytes
unicode
def
slice_fused_type_start
(
slicable
seq
,
start
):
"""
>>> l = [1,2,3,4,5]
>>> t = tuple(l)
>>> b = ''.join(map(str, l)).encode('ASCII')
>>> for o in (l, t, b):
... for s in (0, 4, 5, -5, None):
... slice_fused_type_start(o, s)
>>> u = b.decode('ASCII')
>>> p = lambda o: o.decode() if isinstance(o, type(b)) else str(o)
>>> for o in (l, t, b, u):
... for s in (0, 4, 5, -5):
... print(p(slice_fused_type_start(o, s)))
...
[1, 2, 3, 4, 5]
[5]
[]
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5]
(1, 2, 3, 4, 5)
(5,)
()
(1, 2, 3, 4, 5)
(1, 2, 3, 4, 5)
'12345'
'5'
''
'12345'
'12345'
12345
5
<BLANKLINE>
12345
12345
5
<BLANKLINE>
12345
"""
obj
=
seq
[
start
:]
return
obj
...
...
@@ -242,9 +246,11 @@ def slice_fused_type_stop(slicable seq, stop):
>>> l = [1,2,3,4,5]
>>> t = tuple(l)
>>> b = ''.join(map(str, l)).encode('ASCII')
>>> for o in (l, t, b):
>>> u = b.decode('ASCII')
>>> p = lambda o: o.decode() if isinstance(o, type(b)) else str(o)
>>> for o in (l, t, b, u):
... for s in (0, 4, 5, -5, None):
...
slice_fused_type_stop(o, s
)
...
print(p(slice_fused_type_stop(o, s))
)
...
[]
[1, 2, 3, 4]
...
...
@@ -256,11 +262,16 @@ def slice_fused_type_stop(slicable seq, stop):
(1, 2, 3, 4, 5)
()
(1, 2, 3, 4, 5)
''
'1234'
'12345'
''
'12345'
<BLANKLINE>
1234
12345
<BLANKLINE>
12345
<BLANKLINE>
1234
12345
<BLANKLINE>
12345
"""
obj
=
seq
[:
stop
]
return
obj
...
...
@@ -270,10 +281,12 @@ def slice_fused_type_start_and_stop(slicable seq, start, stop):
>>> l = [1,2,3,4,5]
>>> t = tuple(l)
>>> b = ''.join(map(str, l)).encode('ASCII')
>>> for o in (l, t, b):
>>> u = b.decode('ASCII')
>>> p = lambda o: o.decode() if isinstance(o, type(b)) else str(o)
>>> for o in (l, t, b, u):
... for start in (0, 1, 4, 5, -5, None):
... for stop in (0, 4, 5, 10, -10, None):
...
slice_fused_type_start_and_stop(o, start, stop
)
...
print(p(slice_fused_type_start_and_stop(o, start, stop))
)
...
[]
[1, 2, 3, 4]
...
...
@@ -347,42 +360,78 @@ def slice_fused_type_start_and_stop(slicable seq, start, stop):
(1, 2, 3, 4, 5)
()
(1, 2, 3, 4, 5)
''
'1234'
'12345'
'12345'
''
'12345'
''
'234'
'2345'
'2345'
''
'2345'
''
''
'5'
'5'
''
'5'
''
''
''
''
''
''
''
'1234'
'12345'
'12345'
''
'12345'
''
'1234'
'12345'
'12345'
''
'12345'
<BLANKLINE>
1234
12345
12345
<BLANKLINE>
12345
<BLANKLINE>
234
2345
2345
<BLANKLINE>
2345
<BLANKLINE>
<BLANKLINE>
5
5
<BLANKLINE>
5
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
1234
12345
12345
<BLANKLINE>
12345
<BLANKLINE>
1234
12345
12345
<BLANKLINE>
12345
<BLANKLINE>
1234
12345
12345
<BLANKLINE>
12345
<BLANKLINE>
234
2345
2345
<BLANKLINE>
2345
<BLANKLINE>
<BLANKLINE>
5
5
<BLANKLINE>
5
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
1234
12345
12345
<BLANKLINE>
12345
<BLANKLINE>
1234
12345
12345
<BLANKLINE>
12345
"""
obj
=
seq
[
start
:
stop
]
return
obj
...
...
@@ -392,9 +441,11 @@ def slice_fused_type_step(slicable seq, step):
>>> l = [1,2,3,4,5]
>>> t = tuple(l)
>>> b = ''.join(map(str, l)).encode('ASCII')
>>> for o in (l, t, b):
>>> u = b.decode('ASCII')
>>> p = lambda o: o.decode() if isinstance(o, type(b)) else str(o)
>>> for o in (l, t, b, u):
... for s in (1, -1, 2, -3, 10, -10, None):
...
slice_fused_type_step(o, s
)
...
print(p(slice_fused_type_step(o, s))
)
...
[1, 2, 3, 4, 5]
[5, 4, 3, 2, 1]
...
...
@@ -410,13 +461,20 @@ def slice_fused_type_step(slicable seq, step):
(1,)
(5,)
(1, 2, 3, 4, 5)
'12345'
'54321'
'135'
'52'
'1'
'5'
'12345'
12345
54321
135
52
1
5
12345
12345
54321
135
52
1
5
12345
>>> for o in (l, t, b):
... try: slice_fused_type_step(o, 0)
... except ValueError: pass
...
...
@@ -429,10 +487,12 @@ def slice_fused_type_start_and_step(slicable seq, start, step):
>>> l = [1,2,3,4,5]
>>> t = tuple(l)
>>> b = ''.join(map(str, l)).encode('ASCII')
>>> for o in (l, t, b):
>>> u = b.decode('ASCII')
>>> p = lambda o: o.decode() if isinstance(o, type(b)) else str(o)
>>> for o in (l, t, b, u):
... for start in (0, 2, 5, -5, None):
... for step in (1, -1, 2, -3, None):
...
slice_fused_type_start_and_step(o, start, step
)
...
print(p(slice_fused_type_start_and_step(o, start, step))
)
...
[1, 2, 3, 4, 5]
[1]
...
...
@@ -484,31 +544,56 @@ def slice_fused_type_start_and_step(slicable seq, start, step):
(1, 3, 5)
(5, 2)
(1, 2, 3, 4, 5)
'12345'
'1'
'135'
'1'
'12345'
'345'
'321'
'35'
'3'
'345'
''
'54321'
''
'52'
''
'12345'
'1'
'135'
'1'
'12345'
'12345'
'54321'
'135'
'52'
'12345'
12345
1
135
1
12345
345
321
35
3
345
<BLANKLINE>
54321
<BLANKLINE>
52
<BLANKLINE>
12345
1
135
1
12345
12345
54321
135
52
12345
12345
1
135
1
12345
345
321
35
3
345
<BLANKLINE>
54321
<BLANKLINE>
52
<BLANKLINE>
12345
1
135
1
12345
12345
54321
135
52
12345
>>> for o in (l, t, b):
... try: slice_fused_type_start_and_step(o, 0, 0)
... except ValueError: pass
...
...
@@ -521,10 +606,12 @@ def slice_fused_type_stop_and_step(slicable seq, stop, step):
>>> l = [1,2,3,4,5]
>>> t = tuple(l)
>>> b = ''.join(map(str, l)).encode('ASCII')
>>> for o in (l, t, b):
>>> u = b.decode('ASCII')
>>> p = lambda o: o.decode() if isinstance(o, type(b)) else str(o)
>>> for o in (l, t, b, u):
... for stop in (5, 10, 3, -10, None):
... for step in (1, -1, 2, -3, None):
...
slice_fused_type_stop_and_step(o, stop, step
)
...
print(p(slice_fused_type_stop_and_step(o, stop, step))
)
...
[1, 2, 3, 4, 5]
[]
...
...
@@ -576,31 +663,56 @@ def slice_fused_type_stop_and_step(slicable seq, stop, step):
(1, 3, 5)
(5, 2)
(1, 2, 3, 4, 5)
'12345'
''
'135'
''
'12345'
'12345'
''
'135'
''
'12345'
'123'
'5'
'13'
'5'
'123'
''
'54321'
''
'52'
''
'12345'
'54321'
'135'
'52'
'12345'
12345
<BLANKLINE>
135
<BLANKLINE>
12345
12345
<BLANKLINE>
135
<BLANKLINE>
12345
123
5
13
5
123
<BLANKLINE>
54321
<BLANKLINE>
52
<BLANKLINE>
12345
54321
135
52
12345
12345
<BLANKLINE>
135
<BLANKLINE>
12345
12345
<BLANKLINE>
135
<BLANKLINE>
12345
123
5
13
5
123
<BLANKLINE>
54321
<BLANKLINE>
52
<BLANKLINE>
12345
54321
135
52
12345
>>> for o in (l, t, b):
... try: slice_fused_type_stop_and_step(o, 5, 0)
... except ValueError: pass
...
...
@@ -612,55 +724,46 @@ def slice_fused_type_all(slicable seq, start, stop, step):
"""
>>> l = [1,2,3,4,5]
>>> t = tuple(l)
>>> s = ''.join(map(str, l)).encode('ASCII')
>>> for o in (l, t, s):
... slice_fused_type_all(o, 0, 5, 1)
>>> b = ''.join(map(str, l)).encode('ASCII')
>>> u = b.decode('ASCII')
>>> p = lambda o: o.decode() if isinstance(o, type(b)) else str(o)
>>> for o in (l, t, b, u):
... for args in ((0, 5, 1), (5, 0, -1), (None, 5, 1), (5, None, -1),
... (-100, 100, None), (None, None, None), (1, 3, 2), (5, 1, -3)):
... print(p(slice_fused_type_all(o, *args)))
...
[1, 2, 3, 4, 5]
(1, 2, 3, 4, 5)
'12345'
>>> for o in (l, t, s):
... slice_fused_type_all(o, 5, 0, -1)
...
[5, 4, 3, 2]
(5, 4, 3, 2)
'5432'
>>> for o in (l, t, s):
... slice_fused_type_all(o, None, 5, 1)
...
[1, 2, 3, 4, 5]
(1, 2, 3, 4, 5)
'12345'
>>> for o in (l, t, s):
... slice_fused_type_all(o, 5, None, -1)
...
[5, 4, 3, 2, 1]
(5, 4, 3, 2, 1)
'54321'
>>> for o in (l, t, s):
... slice_fused_type_all(o, -100, 100, None)
...
[1, 2, 3, 4, 5]
(1, 2, 3, 4, 5)
'12345'
>>> for o in (l, t, s):
... slice_fused_type_all(o, None, None, None)
...
[1, 2, 3, 4, 5]
(1, 2, 3, 4, 5)
'12345'
>>> for o in (l, t, s):
... slice_fused_type_all(o, 1, 3, 2)
...
[2]
(2,)
'2'
>>> for o in (l, t, s):
... slice_fused_type_all(o, 5, 1, -3)
...
[5]
(1, 2, 3, 4, 5)
(5, 4, 3, 2)
(1, 2, 3, 4, 5)
(5, 4, 3, 2, 1)
(1, 2, 3, 4, 5)
(1, 2, 3, 4, 5)
(2,)
(5,)
'5'
12345
5432
12345
54321
12345
12345
2
5
12345
5432
12345
54321
12345
12345
2
5
"""
obj
=
seq
[
start
:
stop
:
step
]
return
obj
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