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
e18e4644
Commit
e18e4644
authored
Mar 19, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tighten PEP 515 test to make sure the underscore literals have the correct node type
parent
53fc37a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
+18
-3
Cython/Compiler/Tests/TestGrammar.py
Cython/Compiler/Tests/TestGrammar.py
+18
-3
No files found.
Cython/Compiler/Tests/TestGrammar.py
View file @
e18e4644
...
...
@@ -9,6 +9,7 @@ from __future__ import absolute_import
from
...TestUtils
import
CythonTest
from
..Errors
import
CompileError
from
..
import
ExprNodes
# Copied from CPython's test_grammar.py
VALID_UNDERSCORE_LITERALS
=
[
...
...
@@ -21,6 +22,8 @@ VALID_UNDERSCORE_LITERALS = [
'1_00_00.5'
,
'1e1_0'
,
'.1_4'
,
'.1_4e1'
,
'.1_4j'
,
]
# Copied from CPython's test_grammar.py
...
...
@@ -90,11 +93,23 @@ class TestGrammar(CythonTest):
def
test_valid_number_literals
(
self
):
for
literal
in
VALID_UNDERSCORE_LITERALS
:
for
expression
in
[
'%s'
,
'1 + %s'
,
'%s + 1'
,
'2 * %s'
,
'%s * 2'
]
:
for
i
,
expression
in
enumerate
([
'%s'
,
'1 + %s'
,
'%s + 1'
,
'2 * %s'
,
'%s * 2'
])
:
code
=
'x = '
+
expression
%
literal
assert
self
.
fragment
(
u'''
\
node
=
self
.
fragment
(
u'''
\
# cython: language_level=3
'''
+
code
)
is
not
None
'''
+
code
).
root
assert
node
is
not
None
literal_node
=
node
.
stats
[
0
].
rhs
# StatListNode([SingleAssignmentNode('x', expr)])
if
i
>
0
:
# Add/MulNode() -> literal is first or second operand
literal_node
=
literal_node
.
operand2
if
i
%
2
else
literal_node
.
operand1
if
'j'
in
literal
or
'J'
in
literal
:
assert
isinstance
(
literal_node
,
ExprNodes
.
ImagNode
)
elif
'.'
in
literal
or
'e'
in
literal
or
'E'
in
literal
and
not
(
'0x'
in
literal
or
'0X'
in
literal
):
assert
isinstance
(
literal_node
,
ExprNodes
.
FloatNode
)
else
:
assert
isinstance
(
literal_node
,
ExprNodes
.
IntNode
)
if
__name__
==
"__main__"
:
...
...
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