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
d9e89503
Commit
d9e89503
authored
Jul 30, 2001
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #442866: Tests for codeop.py.
parent
eaa609ac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
0 deletions
+100
-0
Lib/test/output/test_codeop
Lib/test/output/test_codeop
+10
-0
Lib/test/test_codeop.py
Lib/test/test_codeop.py
+90
-0
No files found.
Lib/test/output/test_codeop
0 → 100644
View file @
d9e89503
test_codeop
test_filename (test_codeop.CodeopTests) ... ok
test_incomplete (test_codeop.CodeopTests) ... ok
test_invalid (test_codeop.CodeopTests) ... ok
test_valid (test_codeop.CodeopTests) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.052s
OK
Lib/test/test_codeop.py
0 → 100644
View file @
d9e89503
"""
Test cases for codeop.py
Nick Mathewson
"""
import
unittest
from
test_support
import
run_unittest
from
codeop
import
compile_command
class
CodeopTests
(
unittest
.
TestCase
):
def
assertValid
(
self
,
str
,
symbol
=
'single'
):
'''succeed iff str is a valid piece of code'''
expected
=
compile
(
str
,
"<input>"
,
symbol
)
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'''
self
.
assertEquals
(
compile_command
(
str
,
symbol
=
symbol
),
None
)
def
assertInvalid
(
self
,
str
,
symbol
=
'single'
,
is_syntax
=
1
):
'''succeed iff str is the start of an invalid piece of code'''
try
:
compile_command
(
str
,
symbol
=
symbol
)
self
.
fail
(
"No exception thrown for invalid code"
)
except
SyntaxError
:
self
.
assert_
(
is_syntax
)
except
OverflowError
:
self
.
assert_
(
not
is_syntax
)
def
test_valid
(
self
):
av
=
self
.
assertValid
av
(
"a = 1
\
n
"
)
av
(
"def x():
\
n
pass
\
n
"
)
av
(
"pass
\
n
"
)
av
(
"3**3
\
n
"
)
av
(
"if 9==3:
\
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'
))
av
(
"3**3"
,
"eval"
)
av
(
"(lambda z:
\
n
z**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
(
"if 9==3:
\
n
pass
\
n
else:
\
n
"
)
ai
(
"if 9==3:
\
n
pass
\
n
else:
\
n
pass"
)
ai
(
"a = ("
)
ai
(
"a = 9+
\
\
"
)
ai
(
"("
,
"eval"
)
ai
(
"(
\
n
\
n
\
n
"
,
"eval"
)
ai
(
"(9+"
,
"eval"
)
ai
(
"9+
\
\
"
,
"eval"
)
ai
(
"lambda z:
\
\
"
,
"eval"
)
def
test_invalid
(
self
):
ai
=
self
.
assertInvalid
ai
(
"a b"
)
ai
(
"a = "
)
ai
(
"a = 9 +"
)
ai
(
"a = 1"
,
"eval"
)
ai
(
"a = ("
,
"eval"
)
ai
(
"]"
,
"eval"
)
ai
(
"())"
,
"eval"
)
ai
(
"[}"
,
"eval"
)
ai
(
"9+"
,
"eval"
)
ai
(
"lambda z:"
,
"eval"
)
ai
(
"a b"
,
"eval"
)
def
test_filename
(
self
):
self
.
assertEquals
(
compile_command
(
"a = 1
\
n
"
,
"abc"
).
co_filename
,
compile
(
"a = 1
\
n
"
,
"abc"
,
'single'
).
co_filename
)
self
.
assertNotEquals
(
compile_command
(
"a = 1
\
n
"
,
"abc"
).
co_filename
,
compile
(
"a = 1
\
n
"
,
"def"
,
'single'
).
co_filename
)
run_unittest
(
CodeopTests
)
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