Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
de9a0d31
Commit
de9a0d31
authored
May 17, 2003
by
Samuele Pedroni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
beefed up version: jython support, covers now fixed differences between CPython/Jython.
parent
eb1a4960
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
11 deletions
+105
-11
Lib/test/test_codeop.py
Lib/test/test_codeop.py
+105
-11
No files found.
Lib/test/test_codeop.py
View file @
de9a0d31
...
...
@@ -3,17 +3,43 @@
Nick Mathewson
"""
import
unittest
from
test.test_support
import
run_unittest
from
test.test_support
import
run_unittest
,
is_jython
from
codeop
import
compile_command
,
PyCF_DONT_IMPLY_DEDENT
if
is_jython
:
import
sys
import
cStringIO
def
unify_callables
(
d
):
for
n
,
v
in
d
.
items
():
if
callable
(
v
):
d
[
n
]
=
callable
return
d
class
CodeopTests
(
unittest
.
TestCase
):
def
assertValid
(
self
,
str
,
symbol
=
'single'
):
'''succeed iff str is a valid piece of code'''
expected
=
compile
(
str
,
"<input>"
,
symbol
,
PyCF_DONT_IMPLY_DEDENT
)
self
.
assertEquals
(
compile_command
(
str
,
"<input>"
,
symbol
),
expected
)
if
is_jython
:
code
=
compile_command
(
str
,
"<input>"
,
symbol
)
self
.
assert_
(
code
)
if
symbol
==
"single"
:
d
,
r
=
{},{}
sys
.
stdout
=
cStringIO
.
StringIO
()
try
:
exec
code
in
d
exec
compile
(
str
,
"<input>"
,
"single"
)
in
r
finally
:
sys
.
stdout
=
sys
.
__stdout__
elif
symbol
==
'eval'
:
ctx
=
{
'a'
:
2
}
d
=
{
'value'
:
eval
(
code
,
ctx
)
}
r
=
{
'value'
:
eval
(
str
,
ctx
)
}
self
.
assertEquals
(
unify_callables
(
r
),
unify_callables
(
d
))
else
:
expected
=
compile
(
str
,
"<input>"
,
symbol
,
PyCF_DONT_IMPLY_DEDENT
)
self
.
assertEquals
(
compile_command
(
str
,
"<input>"
,
symbol
),
expected
)
def
assertIncomplete
(
self
,
str
,
symbol
=
'single'
):
'''succeed iff str is the start of a valid piece of code'''
...
...
@@ -31,36 +57,91 @@ class CodeopTests(unittest.TestCase):
def
test_valid
(
self
):
av
=
self
.
assertValid
# special case
if
not
is_jython
:
self
.
assertEquals
(
compile_command
(
""
),
compile
(
"pass"
,
"<input>"
,
'single'
,
PyCF_DONT_IMPLY_DEDENT
))
self
.
assertEquals
(
compile_command
(
"
\
n
"
),
compile
(
"pass"
,
"<input>"
,
'single'
,
PyCF_DONT_IMPLY_DEDENT
))
else
:
av
(
""
)
av
(
"
\
n
"
)
av
(
"a = 1"
)
av
(
"
\
n
a = 1"
)
av
(
"a = 1
\
n
"
)
av
(
"a = 1
\
n
\
n
"
)
av
(
"
\
n
\
n
a = 1
\
n
\
n
"
)
av
(
"def x():
\
n
pass
\
n
"
)
av
(
"if 1:
\
n
pass
\
n
"
)
av
(
"
\
n
\
n
if 1: pass
\
n
"
)
av
(
"
\
n
\
n
if 1: pass
\
n
\
n
"
)
av
(
"def x():
\
n
\
n
pass
\
n
"
)
av
(
"def x():
\
n
pass
\
n
\
n
"
)
av
(
"def x():
\
n
pass
\
n
\
n
"
)
av
(
"pass
\
n
"
)
av
(
"3**3
\
n
"
)
av
(
"if 9==3:
\
n
pass
\
n
else:
\
n
pass
\
n
"
)
av
(
"if 1:
\
n
pass
\
n
if 1:
\
n
pass
\
n
else:
\
n
pass
\
n
"
)
av
(
"#a
\
n
#b
\
n
a = 3
\
n
"
)
av
(
"#a
\
n
\
n
\
n
a=3
\
n
"
)
av
(
"a=3
\
n
\
n
"
)
# special case
self
.
assertEquals
(
compile_command
(
""
),
compile
(
"pass"
,
"<input>"
,
'single'
,
PyCF_DONT_IMPLY_DEDENT
))
av
(
"a = 9+
\
\
\
n
3"
)
av
(
"3**3"
,
"eval"
)
av
(
"(lambda z:
\
n
z**3)"
,
"eval"
)
av
(
"9+
\
\
\
n
3"
,
"eval"
)
av
(
"9+
\
\
\
n
3
\
n
"
,
"eval"
)
av
(
"
\
n
\
n
a**3"
,
"eval"
)
av
(
"
\
n
\
n
a**3"
,
"eval"
)
av
(
"#a
\
n
#b
\
n
a**3"
,
"eval"
)
def
test_incomplete
(
self
):
ai
=
self
.
assertIncomplete
ai
(
"(a **"
)
ai
(
"def x():
\
n
"
)
ai
(
"(a,b,"
)
ai
(
"(a,b,("
)
ai
(
"(a,b,("
)
ai
(
"a = ("
)
ai
(
"a = {"
)
ai
(
"b + {"
)
ai
(
"if 9==3:
\
n
pass
\
n
else:"
)
ai
(
"if 9==3:
\
n
pass
\
n
else:
\
n
"
)
ai
(
"if 9==3:
\
n
pass
\
n
else:
\
n
pass"
)
ai
(
"a = ("
)
ai
(
"if 1:"
)
ai
(
"if 1:
\
n
"
)
ai
(
"if 1:
\
n
pass
\
n
if 1:
\
n
pass
\
n
else:"
)
ai
(
"if 1:
\
n
pass
\
n
if 1:
\
n
pass
\
n
else:
\
n
"
)
ai
(
"if 1:
\
n
pass
\
n
if 1:
\
n
pass
\
n
else:
\
n
pass"
)
ai
(
"def x():"
)
ai
(
"def x():
\
n
"
)
ai
(
"def x():
\
n
\
n
"
)
ai
(
"def x():
\
n
pass"
)
ai
(
"def x():
\
n
pass
\
n
"
)
ai
(
"def x():
\
n
pass
\
n
"
)
ai
(
"
\
n
\
n
def x():
\
n
pass"
)
ai
(
"a = 9+
\
\
"
)
ai
(
"a = 'a
\
\
"
)
ai
(
"a = '''xy"
)
ai
(
""
,
"eval"
)
ai
(
"
\
n
"
,
"eval"
)
ai
(
"("
,
"eval"
)
ai
(
"(
\
n
\
n
\
n
"
,
"eval"
)
ai
(
"(9+"
,
"eval"
)
...
...
@@ -70,9 +151,22 @@ class CodeopTests(unittest.TestCase):
def
test_invalid
(
self
):
ai
=
self
.
assertInvalid
ai
(
"a b"
)
ai
(
"a @"
)
ai
(
"a b @"
)
ai
(
"a ** @"
)
ai
(
"a = "
)
ai
(
"a = 9 +"
)
ai
(
"def x():
\
n
\
n
pass
\
n
"
)
ai
(
"
\
n
\
n
if 1: pass
\
n
\
n
pass"
)
ai
(
"a = 9+
\
\
\
n
"
)
ai
(
"a = 'a
\
\
"
)
ai
(
"a = 'a
\
\
\
n
"
)
ai
(
"a = 1"
,
"eval"
)
ai
(
"a = ("
,
"eval"
)
ai
(
"]"
,
"eval"
)
...
...
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