Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
my2to3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
my2to3
Commits
f6069026
Commit
f6069026
authored
Jul 06, 2020
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: add testFixNestedExceptTrace
parent
44942257
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
130 additions
and
6 deletions
+130
-6
my2to3/tests/__init__.py
my2to3/tests/__init__.py
+27
-0
my2to3/tests/testFixDivisionTrace.py
my2to3/tests/testFixDivisionTrace.py
+1
-6
my2to3/tests/testFixNestedExceptTrace.py
my2to3/tests/testFixNestedExceptTrace.py
+102
-0
No files found.
my2to3/tests/__init__.py
View file @
f6069026
from
lib2to3.tests.test_fixers
import
FixerTestCase
as
lib2to3FixerTestCase
class
FixerTestCase
(
lib2to3FixerTestCase
):
# Subclass to replace "fixer_pkg"
def
setUp
(
self
,
fix_list
=
None
,
fixer_pkg
=
"my2to3"
,
options
=
None
):
super
(
FixerTestCase
,
self
).
setUp
(
fix_list
,
fixer_pkg
,
options
)
if
self
.
fixer
.
endswith
(
'_trace'
):
fix_name
=
'fix_'
+
self
.
fixer
self
.
fixer_module
=
fixer_module
=
getattr
(
__import__
(
'my2to3.fixes'
,
fromlist
=
[
fix_name
]),
fix_name
)
self
.
traces
=
[]
# Wrap fixer_module.trace, to populate self.traces
self
.
old_trace
=
fixer_module
.
trace
def
decorate
(
func
):
def
call
(
*
args
):
self
.
traces
.
append
(
args
)
return
func
(
*
args
)
return
call
fixer_module
.
trace
=
decorate
(
fixer_module
.
trace
)
def
tearDown
(
self
,
*
args
,
**
kw
):
super
(
FixerTestCase
,
self
).
tearDown
(
*
args
,
**
kw
)
if
self
.
fixer
.
endswith
(
'_trace'
):
self
.
fixer_module
.
trace
=
self
.
old_trace
my2to3/tests/testFixDivisionTrace.py
View file @
f6069026
from
lib2to3.tests.test_fixers
import
FixerTestCase
as
lib2to3FixerTestCase
import
unittest
class
FixerTestCase
(
lib2to3FixerTestCase
):
# Subclass to replace "fixer_pkg"
def
setUp
(
self
,
fix_list
=
None
,
fixer_pkg
=
"my2to3"
,
options
=
None
):
super
(
FixerTestCase
,
self
).
setUp
(
fix_list
,
fixer_pkg
,
options
)
from
.
import
FixerTestCase
class
testFixDivisionTrace
(
FixerTestCase
):
...
...
my2to3/tests/testFixNestedExceptTrace.py
0 → 100644
View file @
f6069026
import
unittest
from
.
import
FixerTestCase
class
testFixNestedExceptTrace
(
FixerTestCase
):
fixer
=
"nested_except_trace"
def
test_try
(
self
):
a
=
"""
try:
try:
1
except Exception as e:
2
except Exception as e:
3
"""
self
.
assertEqual
(
self
.
traces
,
[])
self
.
unchanged
(
a
)
self
.
assertEqual
(
self
.
traces
,
[])
def
test_except
(
self
):
a
=
"""
try:
1
except Exception as e:
try:
2
except Exception as e:
3
"""
self
.
assertEqual
(
self
.
traces
,
[])
self
.
unchanged
(
a
)
self
.
assertEqual
(
self
.
traces
,
[(
u'<string>'
,
4
,
7
)])
def
test_except_2
(
self
):
a
=
"""
try:
1
except Exception as e:
try:
2
except Exception as f:
3
"""
self
.
assertEqual
(
self
.
traces
,
[])
self
.
unchanged
(
a
)
self
.
assertEqual
(
self
.
traces
,
[])
def
test_multiple_except
(
self
):
a
=
"""
try:
1
except Exception as e:
try:
2
except Exception as e:
try:
3
except Exception as e:
4
"""
self
.
assertEqual
(
self
.
traces
,
[])
self
.
unchanged
(
a
)
self
.
assertEqual
(
self
.
traces
,
[(
u'<string>'
,
7
,
10
),
(
u'<string>'
,
4
,
7
),
(
u'<string>'
,
4
,
10
)])
def
test_else
(
self
):
a
=
"""
try:
1
except Exception as e:
2
else:
try:
3
except Exception as e:
4
"""
self
.
assertEqual
(
self
.
traces
,
[])
self
.
unchanged
(
a
)
self
.
assertEqual
(
self
.
traces
,
[])
def
test_finally
(
self
):
a
=
"""
try:
1
except Exception as e:
2
finally:
try:
3
except Exception as e:
4
"""
self
.
assertEqual
(
self
.
traces
,
[])
self
.
unchanged
(
a
)
self
.
assertEqual
(
self
.
traces
,
[])
if
__name__
==
'__main__'
:
unittest
.
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