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
dbf9c4eb
Commit
dbf9c4eb
authored
Jun 30, 2008
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
now that exec is a function, we can use the shorter assertRaises to test
parent
44edbf6d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
37 deletions
+7
-37
Lib/test/test_compile.py
Lib/test/test_compile.py
+7
-37
No files found.
Lib/test/test_compile.py
View file @
dbf9c4eb
...
...
@@ -18,21 +18,9 @@ class TestSpecifics(unittest.TestCase):
self
.
assertRaises
(
SyntaxError
,
eval
,
'lambda a,a:0'
)
self
.
assertRaises
(
SyntaxError
,
eval
,
'lambda a,a=1:0'
)
self
.
assertRaises
(
SyntaxError
,
eval
,
'lambda a=1,a=1:0'
)
try
:
exec
(
'def f(a, a): pass'
)
self
.
fail
(
"duplicate arguments"
)
except
SyntaxError
:
pass
try
:
exec
(
'def f(a = 0, a = 1): pass'
)
self
.
fail
(
"duplicate keyword arguments"
)
except
SyntaxError
:
pass
try
:
exec
(
'def f(a): global a; a = 1'
)
self
.
fail
(
"variable is global and local"
)
except
SyntaxError
:
pass
self
.
assertRaises
(
SyntaxError
,
exec
,
'def f(a, a): pass'
)
self
.
assertRaises
(
SyntaxError
,
exec
,
'def f(a = 0, a = 1): pass'
)
self
.
assertRaises
(
SyntaxError
,
exec
,
'def f(a): global a; a = 1'
)
def
test_syntax_error
(
self
):
self
.
assertRaises
(
SyntaxError
,
compile
,
"1+*3"
,
"filename"
,
"exec"
)
...
...
@@ -41,11 +29,7 @@ class TestSpecifics(unittest.TestCase):
self
.
assertRaises
(
SyntaxError
,
compile
,
"f(None=1)"
,
"<string>"
,
"exec"
)
def
test_duplicate_global_local
(
self
):
try
:
exec
(
'def f(a): global a; a = 1'
)
self
.
fail
(
"variable is global and local"
)
except
SyntaxError
:
pass
self
.
assertRaises
(
SyntaxError
,
exec
,
'def f(a): global a; a = 1'
)
def
test_exec_with_general_mapping_for_locals
(
self
):
...
...
@@ -76,23 +60,13 @@ class TestSpecifics(unittest.TestCase):
self
.
assertEqual
(
m
.
results
,
(
'z'
,
g
))
exec
(
'z = locals()'
,
g
,
m
)
self
.
assertEqual
(
m
.
results
,
(
'z'
,
m
))
try
:
exec
(
'z = b'
,
m
)
except
TypeError
:
pass
else
:
self
.
fail
(
'Did not validate globals as a real dict'
)
self
.
assertRaises
(
TypeError
,
exec
,
'z = b'
,
m
)
class
A
:
"Non-mapping"
pass
m
=
A
()
try
:
exec
(
'z = a'
,
g
,
m
)
except
TypeError
:
pass
else
:
self
.
fail
(
'Did not validate locals as a mapping'
)
self
.
assertRaises
(
TypeError
,
exec
,
'z = a'
,
g
,
m
)
# Verify that dict subclasses work as well
class
D
(
dict
):
...
...
@@ -129,11 +103,7 @@ def f(x):
self
.
assertEqual
(
g
[
'f'
](
5
),
0
)
def
test_argument_order
(
self
):
try
:
exec
(
'def f(a=1, b): pass'
)
self
.
fail
(
"non-default args after default"
)
except
SyntaxError
:
pass
self
.
assertRaises
(
SyntaxError
,
exec
,
'def f(a=1, b): pass'
)
def
test_float_literals
(
self
):
# testing bad float literals
...
...
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