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
Gwenaël Samain
cython
Commits
fd79a738
Commit
fd79a738
authored
Mar 21, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make f-string tests work in Py2
parent
033344ce
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
+20
-2
tests/run/test_fstring.pyx
tests/run/test_fstring.pyx
+20
-2
No files found.
tests/run/test_fstring.pyx
View file @
fd79a738
...
...
@@ -7,6 +7,9 @@ import types
import
decimal
import
unittest
import
sys
IS_PY2
=
sys
.
version_info
[
0
]
<
3
from
Cython.Build.Inline
import
cython_inline
from
Cython.TestUtils
import
CythonTest
from
Cython.Compiler.Errors
import
CompileError
,
hold_errors
,
release_errors
,
error_stack
...
...
@@ -45,7 +48,21 @@ class TestCase(CythonTest):
if
error_stack
:
release_errors
(
ignore
=
True
)
if
IS_PY2
:
def
assertEqual
(
self
,
first
,
second
,
msg
=
None
):
# strip u'' string prefixes in Py2
if
first
!=
second
and
isinstance
(
first
,
unicode
):
stripped_first
=
first
.
replace
(
"u'"
,
"'"
).
replace
(
'u"'
,
'"'
)
if
stripped_first
==
second
:
first
=
stripped_first
elif
stripped_first
.
decode
(
'unicode_escape'
)
==
second
:
first
=
stripped_first
.
decode
(
'unicode_escape'
)
super
(
TestCase
,
self
).
assertEqual
(
first
,
second
,
msg
)
def
test__format__lookup
(
self
):
if
IS_PY2
:
raise
unittest
.
SkipTest
(
"Py3-only"
)
# Make sure __format__ is looked up on the type, not the instance.
class
X
:
def
__format__
(
self
,
spec
):
...
...
@@ -376,6 +393,7 @@ f'{a * x()}'"""
def
test_lambda
(
self
):
x
=
5
self
.
assertEqual
(
f'
{
(
lambda
y
:
x
*
y
)(
"8"
)
!
r
}
'
,
"'88888'"
)
if
not
IS_PY2
:
self
.
assertEqual
(
f'
{
(
lambda
y
:
x
*
y
)(
"8"
)
!
r
:
10
}
'
,
"'88888' "
)
self
.
assertEqual
(
f'
{
(
lambda
y
:
x
*
y
)(
"8"
):
10
}
'
,
"88888 "
)
...
...
@@ -720,7 +738,7 @@ f'{a * x()}'"""
def test_errors(self):
# see issue 26287
self.assertAllRaise(
TypeError, '
non
-
empty
',
self.assertAllRaise(
(TypeError, ValueError), '
non
-
empty
', # TypeError in Py3
[r"f'
{
(
lambda
:
0
):
x
}
'",
r"f'
{
(
0
,):
x
}
'",
])
...
...
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