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
129fd044
Kaydet (Commit)
129fd044
authored
Ara 10, 2010
tarafından
Vinay Sajip
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
test.support: Added TestHandler and Matcher classes for better support of assertions about logging.
üst
dfa0a2ab
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
2 deletions
+71
-2
support.py
Lib/test/support.py
+68
-2
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/support.py
Dosyayı görüntüle @
129fd044
...
...
@@ -21,7 +21,7 @@ import subprocess
import
imp
import
time
import
sysconfig
import
logging.handlers
try
:
import
_thread
...
...
@@ -42,7 +42,8 @@ __all__ = [
"set_memlimit"
,
"bigmemtest"
,
"bigaddrspacetest"
,
"BasicTestRunner"
,
"run_unittest"
,
"run_doctest"
,
"threading_setup"
,
"threading_cleanup"
,
"reap_children"
,
"cpython_only"
,
"check_impl_detail"
,
"get_attribute"
,
"swap_item"
,
"swap_attr"
,
"requires_IEEE_754"
]
"swap_item"
,
"swap_attr"
,
"requires_IEEE_754"
,
"TestHandler"
,
"Matr]
class Error(Exception):
...
...
@@ -1343,3 +1344,68 @@ def args_from_interpreter_flags():
if
v
>
0
:
args
.
append
(
'-'
+
opt
*
v
)
return
args
#============================================================
# Support for assertions about logging.
#============================================================
class
TestHandler
(
logging
.
handlers
.
BufferingHandler
):
def
__init__
(
self
,
matcher
):
# BufferingHandler takes a "capacity" argument
# so as to know when to flush. As we're overriding
# shouldFlush anyway, we can set a capacity of zero.
# You can call flush() manually to clear out the
# buffer.
logging
.
handlers
.
BufferingHandler
.
__init__
(
self
,
0
)
self
.
matcher
=
matcher
def
shouldFlush
(
self
):
return
False
def
emit
(
self
,
record
):
self
.
format
(
record
)
self
.
buffer
.
append
(
record
.
__dict__
)
def
matches
(
self
,
**
kwargs
):
"""
Look for a saved dict whose keys/values match the supplied arguments.
"""
result
=
False
for
d
in
self
.
buffer
:
if
self
.
matcher
.
matches
(
d
,
**
kwargs
):
result
=
True
break
return
result
class
Matcher
(
object
):
_partial_matches
=
(
'msg'
,
'message'
)
def
matches
(
self
,
d
,
**
kwargs
):
"""
Try to match a single dict with the supplied arguments.
Keys whose values are strings and which are in self._partial_matches
will be checked for partial (i.e. substring) matches. You can extend
this scheme to (for example) do regular expression matching, etc.
"""
result
=
True
for
k
in
kwargs
:
v
=
kwargs
[
k
]
dv
=
d
.
get
(
k
)
if
not
self
.
match_value
(
k
,
dv
,
v
):
result
=
False
break
return
result
def
match_value
(
self
,
k
,
dv
,
v
):
"""
Try to match a single stored value (dv) with a supplied value (v).
"""
if
type
(
v
)
!=
type
(
dv
):
result
=
False
elif
type
(
dv
)
is
not
str
or
k
not
in
self
.
_partial_matches
:
result
=
(
v
==
dv
)
else
:
result
=
dv
.
find
(
v
)
>=
0
return
result
Misc/NEWS
Dosyayı görüntüle @
129fd044
...
...
@@ -63,6 +63,9 @@ Core and Builtins
Library
-------
- test.support: Added TestHandler and Matcher classes for better support of
assertions about logging.
- Issue #4391: Use proper plural forms in argparse.
- Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
...
...
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