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
f15c4d37
Commit
f15c4d37
authored
Mar 30, 2017
by
Serhiy Storchaka
Committed by
GitHub
Mar 30, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-20548: Use specific asserts in warnings and exceptions tests (#788)
parent
16f85234
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
35 deletions
+35
-35
Lib/test/test_exceptions.py
Lib/test/test_exceptions.py
+9
-9
Lib/test/test_raise.py
Lib/test/test_raise.py
+6
-6
Lib/test/test_warnings/__init__.py
Lib/test/test_warnings/__init__.py
+20
-20
No files found.
Lib/test/test_exceptions.py
View file @
f15c4d37
...
...
@@ -537,7 +537,7 @@ class ExceptionTests(unittest.TestCase):
pass
obj
=
None
obj
=
wr
()
self
.
assert
True
(
obj
is
None
,
"%s"
%
obj
)
self
.
assert
IsNone
(
obj
)
# Qualified "except" without "as"
obj
=
MyObj
()
...
...
@@ -548,7 +548,7 @@ class ExceptionTests(unittest.TestCase):
pass
obj
=
None
obj
=
wr
()
self
.
assert
True
(
obj
is
None
,
"%s"
%
obj
)
self
.
assert
IsNone
(
obj
)
# Bare "except"
obj
=
MyObj
()
...
...
@@ -559,7 +559,7 @@ class ExceptionTests(unittest.TestCase):
pass
obj
=
None
obj
=
wr
()
self
.
assert
True
(
obj
is
None
,
"%s"
%
obj
)
self
.
assert
IsNone
(
obj
)
# "except" with premature block leave
obj
=
MyObj
()
...
...
@@ -571,7 +571,7 @@ class ExceptionTests(unittest.TestCase):
break
obj
=
None
obj
=
wr
()
self
.
assert
True
(
obj
is
None
,
"%s"
%
obj
)
self
.
assert
IsNone
(
obj
)
# "except" block raising another exception
obj
=
MyObj
()
...
...
@@ -592,7 +592,7 @@ class ExceptionTests(unittest.TestCase):
# guarantee no ref cycles on CPython (don't gc_collect)
if
check_impl_detail
(
cpython
=
False
):
gc_collect
()
self
.
assert
True
(
obj
is
None
,
"%s"
%
obj
)
self
.
assert
IsNone
(
obj
)
# Some complicated construct
obj
=
MyObj
()
...
...
@@ -611,7 +611,7 @@ class ExceptionTests(unittest.TestCase):
if
check_impl_detail
(
cpython
=
False
):
gc_collect
()
obj
=
wr
()
self
.
assert
True
(
obj
is
None
,
"%s"
%
obj
)
self
.
assert
IsNone
(
obj
)
# Inside an exception-silencing "with" block
class
Context
:
...
...
@@ -627,7 +627,7 @@ class ExceptionTests(unittest.TestCase):
if
check_impl_detail
(
cpython
=
False
):
gc_collect
()
obj
=
wr
()
self
.
assert
True
(
obj
is
None
,
"%s"
%
obj
)
self
.
assert
IsNone
(
obj
)
def
test_exception_target_in_nested_scope
(
self
):
# issue 4617: This used to raise a SyntaxError
...
...
@@ -779,7 +779,7 @@ class ExceptionTests(unittest.TestCase):
testfunc
(
g
)
g
=
obj
=
None
obj
=
wr
()
self
.
assertIs
(
obj
,
None
)
self
.
assertIs
None
(
obj
)
def
test_generator_throw_cleanup_exc_state
(
self
):
def
do_throw
(
g
):
...
...
@@ -904,7 +904,7 @@ class ExceptionTests(unittest.TestCase):
except
RecursionError
:
return
sys
.
exc_info
()
e
,
v
,
tb
=
g
()
self
.
assert
True
(
isinstance
(
v
,
RecursionError
)
,
type
(
v
))
self
.
assert
IsInstance
(
v
,
RecursionError
,
type
(
v
))
self
.
assertIn
(
"maximum recursion depth exceeded"
,
str
(
v
))
...
...
Lib/test/test_raise.py
View file @
f15c4d37
...
...
@@ -40,7 +40,7 @@ class TestRaise(unittest.TestCase):
exc1
=
e
raise
except
IndexError
as
exc2
:
self
.
assert
True
(
exc1
is
exc2
)
self
.
assert
Is
(
exc1
,
exc2
)
else
:
self
.
fail
(
"No exception raised"
)
...
...
@@ -84,7 +84,7 @@ class TestRaise(unittest.TestCase):
except
:
raise
ValueError
()
from
None
except
ValueError
as
e
:
self
.
assert
True
(
isinstance
(
e
.
__context__
,
TypeError
)
)
self
.
assert
IsInstance
(
e
.
__context__
,
TypeError
)
self
.
assertIsNone
(
e
.
__cause__
)
def
test_with_reraise1
(
self
):
...
...
@@ -190,7 +190,7 @@ class TestCause(unittest.TestCase):
try
:
raise
IndexError
from
cause
except
IndexError
as
e
:
self
.
assert
True
(
e
.
__cause__
is
cause
)
self
.
assert
Is
(
e
.
__cause__
,
cause
)
else
:
self
.
fail
(
"No exception raised"
)
...
...
@@ -296,7 +296,7 @@ class TestContext(unittest.TestCase):
finally
:
raise
OSError
except
OSError
as
e
:
self
.
assert
True
(
e
.
__context__
is
None
)
self
.
assert
IsNone
(
e
.
__context__
)
else
:
self
.
fail
(
"No exception raised"
)
...
...
@@ -333,7 +333,7 @@ class TestContext(unittest.TestCase):
except
ZeroDivisionError
as
e
:
raise
e
except
ZeroDivisionError
as
e
:
self
.
assert
True
(
e
.
__context__
is
None
,
e
.
__context__
)
self
.
assert
IsNone
(
e
.
__context__
)
def
test_reraise_cycle_broken
(
self
):
# Non-trivial context cycles (through re-raising a previous exception)
...
...
@@ -347,7 +347,7 @@ class TestContext(unittest.TestCase):
except
ZeroDivisionError
:
raise
a
except
NameError
as
e
:
self
.
assert
True
(
e
.
__context__
.
__context__
is
None
)
self
.
assert
IsNone
(
e
.
__context__
.
__context__
)
def
test_3118
(
self
):
# deleting the generator caused the __context__ to be cleared
...
...
Lib/test/test_warnings/__init__.py
View file @
f15c4d37
...
...
@@ -248,7 +248,7 @@ class FilterTests(BaseTest):
text
=
'handle normally'
self
.
module
.
warn
(
text
)
self
.
assertEqual
(
str
(
w
[
-
1
].
message
),
text
)
self
.
assert
True
(
w
[
-
1
].
category
is
UserWarning
)
self
.
assert
Is
(
w
[
-
1
].
category
,
UserWarning
)
self
.
module
.
filterwarnings
(
"ignore"
,
""
,
Warning
,
""
,
0
)
text
=
'filtered out'
...
...
@@ -261,7 +261,7 @@ class FilterTests(BaseTest):
text
=
'nonmatching text'
self
.
module
.
warn
(
text
)
self
.
assertEqual
(
str
(
w
[
-
1
].
message
),
text
)
self
.
assert
True
(
w
[
-
1
].
category
is
UserWarning
)
self
.
assert
Is
(
w
[
-
1
].
category
,
UserWarning
)
def
test_message_matching
(
self
):
with
original_warnings
.
catch_warnings
(
record
=
True
,
...
...
@@ -353,7 +353,7 @@ class WarnTests(BaseTest):
text
=
'multi %d'
%
i
# Different text on each call.
self
.
module
.
warn
(
text
)
self
.
assertEqual
(
str
(
w
[
-
1
].
message
),
text
)
self
.
assert
True
(
w
[
-
1
].
category
is
UserWarning
)
self
.
assert
Is
(
w
[
-
1
].
category
,
UserWarning
)
# Issue 3639
def
test_warn_nonstandard_types
(
self
):
...
...
@@ -575,7 +575,7 @@ class CWarnTests(WarnTests, unittest.TestCase):
# As an early adopter, we sanity check the
# test.support.import_fresh_module utility function
def
test_accelerated
(
self
):
self
.
assert
False
(
original_warnings
is
self
.
module
)
self
.
assert
IsNot
(
original_warnings
,
self
.
module
)
self
.
assertFalse
(
hasattr
(
self
.
module
.
warn
,
'__code__'
))
class
PyWarnTests
(
WarnTests
,
unittest
.
TestCase
):
...
...
@@ -584,7 +584,7 @@ class PyWarnTests(WarnTests, unittest.TestCase):
# As an early adopter, we sanity check the
# test.support.import_fresh_module utility function
def
test_pure_python
(
self
):
self
.
assert
False
(
original_warnings
is
self
.
module
)
self
.
assert
IsNot
(
original_warnings
,
self
.
module
)
self
.
assertTrue
(
hasattr
(
self
.
module
.
warn
,
'__code__'
))
...
...
@@ -884,20 +884,20 @@ class CatchWarningTests(BaseTest):
# Ensure both showwarning and filters are restored when recording
with
wmod
.
catch_warnings
(
module
=
wmod
,
record
=
True
):
wmod
.
filters
=
wmod
.
showwarning
=
object
()
self
.
assert
True
(
wmod
.
filters
is
orig_filters
)
self
.
assert
True
(
wmod
.
showwarning
is
orig_showwarning
)
self
.
assert
Is
(
wmod
.
filters
,
orig_filters
)
self
.
assert
Is
(
wmod
.
showwarning
,
orig_showwarning
)
# Same test, but with recording disabled
with
wmod
.
catch_warnings
(
module
=
wmod
,
record
=
False
):
wmod
.
filters
=
wmod
.
showwarning
=
object
()
self
.
assert
True
(
wmod
.
filters
is
orig_filters
)
self
.
assert
True
(
wmod
.
showwarning
is
orig_showwarning
)
self
.
assert
Is
(
wmod
.
filters
,
orig_filters
)
self
.
assert
Is
(
wmod
.
showwarning
,
orig_showwarning
)
def
test_catch_warnings_recording
(
self
):
wmod
=
self
.
module
# Ensure warnings are recorded when requested
with
wmod
.
catch_warnings
(
module
=
wmod
,
record
=
True
)
as
w
:
self
.
assertEqual
(
w
,
[])
self
.
assert
True
(
type
(
w
)
is
list
)
self
.
assert
Is
(
type
(
w
),
list
)
wmod
.
simplefilter
(
"always"
)
wmod
.
warn
(
"foo"
)
self
.
assertEqual
(
str
(
w
[
-
1
].
message
),
"foo"
)
...
...
@@ -910,8 +910,8 @@ class CatchWarningTests(BaseTest):
# Ensure warnings are not recorded when not requested
orig_showwarning
=
wmod
.
showwarning
with
wmod
.
catch_warnings
(
module
=
wmod
,
record
=
False
)
as
w
:
self
.
assert
True
(
w
is
None
)
self
.
assert
True
(
wmod
.
showwarning
is
orig_showwarning
)
self
.
assert
IsNone
(
w
)
self
.
assert
Is
(
wmod
.
showwarning
,
orig_showwarning
)
def
test_catch_warnings_reentry_guard
(
self
):
wmod
=
self
.
module
...
...
@@ -932,17 +932,17 @@ class CatchWarningTests(BaseTest):
orig_showwarning
=
wmod
.
showwarning
# Ensure default behaviour is not to record warnings
with
wmod
.
catch_warnings
(
module
=
wmod
)
as
w
:
self
.
assert
True
(
w
is
None
)
self
.
assert
True
(
wmod
.
showwarning
is
orig_showwarning
)
self
.
assert
True
(
wmod
.
filters
is
not
orig_filters
)
self
.
assert
True
(
wmod
.
filters
is
orig_filters
)
self
.
assert
IsNone
(
w
)
self
.
assert
Is
(
wmod
.
showwarning
,
orig_showwarning
)
self
.
assert
IsNot
(
wmod
.
filters
,
orig_filters
)
self
.
assert
Is
(
wmod
.
filters
,
orig_filters
)
if
wmod
is
sys
.
modules
[
'warnings'
]:
# Ensure the default module is this one
with
wmod
.
catch_warnings
()
as
w
:
self
.
assert
True
(
w
is
None
)
self
.
assert
True
(
wmod
.
showwarning
is
orig_showwarning
)
self
.
assert
True
(
wmod
.
filters
is
not
orig_filters
)
self
.
assert
True
(
wmod
.
filters
is
orig_filters
)
self
.
assert
IsNone
(
w
)
self
.
assert
Is
(
wmod
.
showwarning
,
orig_showwarning
)
self
.
assert
IsNot
(
wmod
.
filters
,
orig_filters
)
self
.
assert
Is
(
wmod
.
filters
,
orig_filters
)
def
test_record_override_showwarning_before
(
self
):
# Issue #28835: If warnings.showwarning() was overriden, make sure
...
...
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