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
cda145d2
Commit
cda145d2
authored
Feb 18, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests for MethodDispatcherTransform
parent
f0298152
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
Cython/Compiler/Tests/TestVisitor.py
Cython/Compiler/Tests/TestVisitor.py
+61
-0
No files found.
Cython/Compiler/Tests/TestVisitor.py
0 → 100644
View file @
cda145d2
from
Cython.Compiler.ModuleNode
import
ModuleNode
from
Cython.Compiler.Symtab
import
ModuleScope
from
Cython.TestUtils
import
TransformTest
from
Cython.Compiler.Visitor
import
MethodDispatcherTransform
from
Cython.Compiler.ParseTreeTransforms
import
(
NormalizeTree
,
AnalyseDeclarationsTransform
,
AnalyseExpressionsTransform
,
InterpretCompilerDirectives
)
class
TestMethodDispatcherTransform
(
TransformTest
):
_tree
=
None
def
_build_tree
(
self
):
if
self
.
_tree
is
None
:
context
=
None
def
fake_module
(
node
):
scope
=
ModuleScope
(
'test'
,
None
,
None
)
return
ModuleNode
(
node
.
pos
,
doc
=
None
,
body
=
node
,
scope
=
scope
,
full_module_name
=
'test'
,
directive_comments
=
{})
pipeline
=
[
fake_module
,
NormalizeTree
(
context
),
InterpretCompilerDirectives
(
context
,
{}),
AnalyseDeclarationsTransform
(
context
),
AnalyseExpressionsTransform
(
context
),
]
self
.
_tree
=
self
.
run_pipeline
(
pipeline
,
u"""
cdef bytes s = b'asdfg'
cdef dict d = {1:2}
x = s * 3
d.get('test')
"""
)
return
self
.
_tree
def
test_builtin_method
(
self
):
calls
=
[
0
]
class
Test
(
MethodDispatcherTransform
):
def
_handle_simple_method_dict_get
(
self
,
node
,
args
,
unbound
):
calls
[
0
]
+=
1
return
node
tree
=
self
.
_build_tree
()
Test
(
None
)(
tree
)
self
.
assertEqual
(
1
,
calls
[
0
])
def
test_binop_method
(
self
):
calls
=
{
'bytes'
:
0
,
'object'
:
0
}
class
Test
(
MethodDispatcherTransform
):
def
_handle_simple_method_bytes___mul__
(
self
,
node
,
args
,
unbound
):
calls
[
'bytes'
]
+=
1
return
node
def
_handle_simple_method_object___mul__
(
self
,
node
,
args
,
unbound
):
calls
[
'object'
]
+=
1
return
node
tree
=
self
.
_build_tree
()
Test
(
None
)(
tree
)
self
.
assertEqual
(
1
,
calls
[
'bytes'
])
self
.
assertEqual
(
0
,
calls
[
'object'
])
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