Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
a7d00c20
Kaydet (Commit)
a7d00c20
authored
May 16, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Reverted issue #24134 changes (except new tests).
üst
75fb816c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
27 deletions
+11
-27
case.py
Lib/unittest/case.py
+11
-13
test_case.py
Lib/unittest/test/test_case.py
+0
-11
NEWS
Misc/NEWS
+0
-3
No files found.
Lib/unittest/case.py
Dosyayı görüntüle @
a7d00c20
...
@@ -129,17 +129,15 @@ class _BaseTestCaseContext:
...
@@ -129,17 +129,15 @@ class _BaseTestCaseContext:
msg
=
self
.
test_case
.
_formatMessage
(
self
.
msg
,
standardMsg
)
msg
=
self
.
test_case
.
_formatMessage
(
self
.
msg
,
standardMsg
)
raise
self
.
test_case
.
failureException
(
msg
)
raise
self
.
test_case
.
failureException
(
msg
)
def
_sentinel
(
*
args
,
**
kwargs
):
raise
AssertionError
(
'Should never be called'
)
class
_AssertRaisesBaseContext
(
_BaseTestCaseContext
):
class
_AssertRaisesBaseContext
(
_BaseTestCaseContext
):
def
__init__
(
self
,
expected
,
test_case
,
callable_obj
=
_sentinel
,
def
__init__
(
self
,
expected
,
test_case
,
callable_obj
=
None
,
expected_regex
=
None
):
expected_regex
=
None
):
_BaseTestCaseContext
.
__init__
(
self
,
test_case
)
_BaseTestCaseContext
.
__init__
(
self
,
test_case
)
self
.
expected
=
expected
self
.
expected
=
expected
self
.
test_case
=
test_case
self
.
test_case
=
test_case
if
callable_obj
is
not
_sentinel
:
if
callable_obj
is
not
None
:
try
:
try
:
self
.
obj_name
=
callable_obj
.
__name__
self
.
obj_name
=
callable_obj
.
__name__
except
AttributeError
:
except
AttributeError
:
...
@@ -153,11 +151,11 @@ class _AssertRaisesBaseContext(_BaseTestCaseContext):
...
@@ -153,11 +151,11 @@ class _AssertRaisesBaseContext(_BaseTestCaseContext):
def
handle
(
self
,
name
,
callable_obj
,
args
,
kwargs
):
def
handle
(
self
,
name
,
callable_obj
,
args
,
kwargs
):
"""
"""
If callable_obj is
_sentinel
, assertRaises/Warns is being used as a
If callable_obj is
None
, assertRaises/Warns is being used as a
context manager, so check for a 'msg' kwarg and return self.
context manager, so check for a 'msg' kwarg and return self.
If callable_obj is not
_sentinel
, call it passing args and kwargs.
If callable_obj is not
None
, call it passing args and kwargs.
"""
"""
if
callable_obj
is
_sentinel
:
if
callable_obj
is
None
:
self
.
msg
=
kwargs
.
pop
(
'msg'
,
None
)
self
.
msg
=
kwargs
.
pop
(
'msg'
,
None
)
return
self
return
self
with
self
:
with
self
:
...
@@ -676,7 +674,7 @@ class TestCase(object):
...
@@ -676,7 +674,7 @@ class TestCase(object):
except
UnicodeDecodeError
:
except
UnicodeDecodeError
:
return
'
%
s :
%
s'
%
(
safe_repr
(
standardMsg
),
safe_repr
(
msg
))
return
'
%
s :
%
s'
%
(
safe_repr
(
standardMsg
),
safe_repr
(
msg
))
def
assertRaises
(
self
,
excClass
,
callableObj
=
_sentinel
,
*
args
,
**
kwargs
):
def
assertRaises
(
self
,
excClass
,
callableObj
=
None
,
*
args
,
**
kwargs
):
"""Fail unless an exception of class excClass is raised
"""Fail unless an exception of class excClass is raised
by callableObj when invoked with arguments args and keyword
by callableObj when invoked with arguments args and keyword
arguments kwargs. If a different type of exception is
arguments kwargs. If a different type of exception is
...
@@ -684,7 +682,7 @@ class TestCase(object):
...
@@ -684,7 +682,7 @@ class TestCase(object):
deemed to have suffered an error, exactly as for an
deemed to have suffered an error, exactly as for an
unexpected exception.
unexpected exception.
If called with callableObj omitted, will return a
If called with callableObj omitted
or None
, will return a
context object used like this::
context object used like this::
with self.assertRaises(SomeException):
with self.assertRaises(SomeException):
...
@@ -705,7 +703,7 @@ class TestCase(object):
...
@@ -705,7 +703,7 @@ class TestCase(object):
context
=
_AssertRaisesContext
(
excClass
,
self
,
callableObj
)
context
=
_AssertRaisesContext
(
excClass
,
self
,
callableObj
)
return
context
.
handle
(
'assertRaises'
,
callableObj
,
args
,
kwargs
)
return
context
.
handle
(
'assertRaises'
,
callableObj
,
args
,
kwargs
)
def
assertWarns
(
self
,
expected_warning
,
callable_obj
=
_sentinel
,
*
args
,
**
kwargs
):
def
assertWarns
(
self
,
expected_warning
,
callable_obj
=
None
,
*
args
,
**
kwargs
):
"""Fail unless a warning of class warnClass is triggered
"""Fail unless a warning of class warnClass is triggered
by callable_obj when invoked with arguments args and keyword
by callable_obj when invoked with arguments args and keyword
arguments kwargs. If a different type of warning is
arguments kwargs. If a different type of warning is
...
@@ -713,7 +711,7 @@ class TestCase(object):
...
@@ -713,7 +711,7 @@ class TestCase(object):
warning filtering rules in effect, it might be silenced, printed
warning filtering rules in effect, it might be silenced, printed
out, or raised as an exception.
out, or raised as an exception.
If called with callable_obj omitted, will return a
If called with callable_obj omitted
or None
, will return a
context object used like this::
context object used like this::
with self.assertWarns(SomeWarning):
with self.assertWarns(SomeWarning):
...
@@ -1221,7 +1219,7 @@ class TestCase(object):
...
@@ -1221,7 +1219,7 @@ class TestCase(object):
self
.
fail
(
self
.
_formatMessage
(
msg
,
standardMsg
))
self
.
fail
(
self
.
_formatMessage
(
msg
,
standardMsg
))
def
assertRaisesRegex
(
self
,
expected_exception
,
expected_regex
,
def
assertRaisesRegex
(
self
,
expected_exception
,
expected_regex
,
callable_obj
=
_sentinel
,
*
args
,
**
kwargs
):
callable_obj
=
None
,
*
args
,
**
kwargs
):
"""Asserts that the message in a raised exception matches a regex.
"""Asserts that the message in a raised exception matches a regex.
Args:
Args:
...
@@ -1240,7 +1238,7 @@ class TestCase(object):
...
@@ -1240,7 +1238,7 @@ class TestCase(object):
return
context
.
handle
(
'assertRaisesRegex'
,
callable_obj
,
args
,
kwargs
)
return
context
.
handle
(
'assertRaisesRegex'
,
callable_obj
,
args
,
kwargs
)
def
assertWarnsRegex
(
self
,
expected_warning
,
expected_regex
,
def
assertWarnsRegex
(
self
,
expected_warning
,
expected_regex
,
callable_obj
=
_sentinel
,
*
args
,
**
kwargs
):
callable_obj
=
None
,
*
args
,
**
kwargs
):
"""Asserts that the message in a triggered warning matches a regexp.
"""Asserts that the message in a triggered warning matches a regexp.
Basic functioning is similar to assertWarns() with the addition
Basic functioning is similar to assertWarns() with the addition
that only warnings whose messages also match the regular expression
that only warnings whose messages also match the regular expression
...
...
Lib/unittest/test/test_case.py
Dosyayı görüntüle @
a7d00c20
...
@@ -1147,9 +1147,6 @@ test case
...
@@ -1147,9 +1147,6 @@ test case
# Failure when no exception is raised
# Failure when no exception is raised
with
self
.
assertRaises
(
self
.
failureException
):
with
self
.
assertRaises
(
self
.
failureException
):
self
.
assertRaises
(
ExceptionMock
,
lambda
:
0
)
self
.
assertRaises
(
ExceptionMock
,
lambda
:
0
)
# Failure when the function is None
with
self
.
assertRaises
(
TypeError
):
self
.
assertRaises
(
ExceptionMock
,
None
)
# Failure when another exception is raised
# Failure when another exception is raised
with
self
.
assertRaises
(
ExceptionMock
):
with
self
.
assertRaises
(
ExceptionMock
):
self
.
assertRaises
(
ValueError
,
Stub
)
self
.
assertRaises
(
ValueError
,
Stub
)
...
@@ -1187,8 +1184,6 @@ test case
...
@@ -1187,8 +1184,6 @@ test case
self
.
assertRaisesRegex
(
ExceptionMock
,
re
.
compile
(
'expect$'
),
Stub
)
self
.
assertRaisesRegex
(
ExceptionMock
,
re
.
compile
(
'expect$'
),
Stub
)
self
.
assertRaisesRegex
(
ExceptionMock
,
'expect$'
,
Stub
)
self
.
assertRaisesRegex
(
ExceptionMock
,
'expect$'
,
Stub
)
with
self
.
assertRaises
(
TypeError
):
self
.
assertRaisesRegex
(
ExceptionMock
,
'expect$'
,
None
)
def
testAssertNotRaisesRegex
(
self
):
def
testAssertNotRaisesRegex
(
self
):
self
.
assertRaisesRegex
(
self
.
assertRaisesRegex
(
...
@@ -1256,9 +1251,6 @@ test case
...
@@ -1256,9 +1251,6 @@ test case
# Failure when no warning is triggered
# Failure when no warning is triggered
with
self
.
assertRaises
(
self
.
failureException
):
with
self
.
assertRaises
(
self
.
failureException
):
self
.
assertWarns
(
RuntimeWarning
,
lambda
:
0
)
self
.
assertWarns
(
RuntimeWarning
,
lambda
:
0
)
# Failure when the function is None
with
self
.
assertRaises
(
TypeError
):
self
.
assertWarns
(
RuntimeWarning
,
None
)
# Failure when another warning is triggered
# Failure when another warning is triggered
with
warnings
.
catch_warnings
():
with
warnings
.
catch_warnings
():
# Force default filter (in case tests are run with -We)
# Force default filter (in case tests are run with -We)
...
@@ -1320,9 +1312,6 @@ test case
...
@@ -1320,9 +1312,6 @@ test case
with
self
.
assertRaises
(
self
.
failureException
):
with
self
.
assertRaises
(
self
.
failureException
):
self
.
assertWarnsRegex
(
RuntimeWarning
,
"o+"
,
self
.
assertWarnsRegex
(
RuntimeWarning
,
"o+"
,
lambda
:
0
)
lambda
:
0
)
# Failure when the function is None
with
self
.
assertRaises
(
TypeError
):
self
.
assertWarnsRegex
(
RuntimeWarning
,
"o+"
,
None
)
# Failure when another warning is triggered
# Failure when another warning is triggered
with
warnings
.
catch_warnings
():
with
warnings
.
catch_warnings
():
# Force default filter (in case tests are run with -We)
# Force default filter (in case tests are run with -We)
...
...
Misc/NEWS
Dosyayı görüntüle @
a7d00c20
...
@@ -48,9 +48,6 @@ Library
...
@@ -48,9 +48,6 @@ Library
- Issue #23796: peak and read1 methods of BufferedReader now raise ValueError
- Issue #23796: peak and read1 methods of BufferedReader now raise ValueError
if they called on a closed object. Patch by John Hergenroeder.
if they called on a closed object. Patch by John Hergenroeder.
- Issue #24134: assertRaises(), assertRaisesRegex(), assertWarns() and
assertWarnsRegex() checks are not longer successful if the callable is None.
- Issue #24094: Fix possible crash in json.encode with poorly behaved dict
- Issue #24094: Fix possible crash in json.encode with poorly behaved dict
subclasses.
subclasses.
...
...
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