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
6fac8171
Kaydet (Commit)
6fac8171
authored
Eki 19, 2010
tarafından
Vinay Sajip
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
logging: Added tests for _logRecordClass changes.
üst
7004bd1a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
2 deletions
+51
-2
__init__.py
Lib/logging/__init__.py
+8
-0
test_logging.py
Lib/test/test_logging.py
+41
-2
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/logging/__init__.py
Dosyayı görüntüle @
6fac8171
...
...
@@ -973,6 +973,7 @@ class Manager(object):
self
.
emittedNoHandlerWarning
=
0
self
.
loggerDict
=
{}
self
.
loggerClass
=
None
self
.
logRecordClass
=
None
def
getLogger
(
self
,
name
):
"""
...
...
@@ -1016,6 +1017,13 @@ class Manager(object):
+
klass
.
__name__
)
self
.
loggerClass
=
klass
def
setLogRecordClass
(
self
,
cls
):
"""
Set the class to be used when instantiating a log record with this
Manager.
"""
self
.
logRecordClass
=
cls
def
_fixupParents
(
self
,
alogger
):
"""
Ensure that there are either loggers or placeholders all the way
...
...
Lib/test/test_logging.py
Dosyayı görüntüle @
6fac8171
...
...
@@ -127,7 +127,8 @@ class BaseTest(unittest.TestCase):
except
AttributeError
:
# StringIO.StringIO lacks a reset() method.
actual_lines
=
stream
.
getvalue
()
.
splitlines
()
self
.
assertEquals
(
len
(
actual_lines
),
len
(
expected_values
))
self
.
assertEquals
(
len
(
actual_lines
),
len
(
expected_values
),
'
%
s vs.
%
s'
%
(
actual_lines
,
expected_values
))
for
actual
,
expected
in
zip
(
actual_lines
,
expected_values
):
match
=
pat
.
search
(
actual
)
if
not
match
:
...
...
@@ -1766,6 +1767,44 @@ class ChildLoggerTest(BaseTest):
self
.
assertTrue
(
c2
is
c3
)
class
DerivedLogRecord
(
logging
.
LogRecord
):
pass
class
LogRecordClassTest
(
BaseTest
):
def
setUp
(
self
):
class
CheckingFilter
(
logging
.
Filter
):
def
__init__
(
self
,
cls
):
self
.
cls
=
cls
def
filter
(
self
,
record
):
t
=
type
(
record
)
if
t
is
not
self
.
cls
:
msg
=
'Unexpected LogRecord type
%
s, expected
%
s'
%
(
t
,
self
.
cls
)
raise
TypeError
(
msg
)
return
True
BaseTest
.
setUp
(
self
)
self
.
filter
=
CheckingFilter
(
DerivedLogRecord
)
self
.
root_logger
.
addFilter
(
self
.
filter
)
self
.
orig_cls
=
logging
.
getLogRecordClass
()
def
tearDown
(
self
):
self
.
root_logger
.
removeFilter
(
self
.
filter
)
BaseTest
.
tearDown
(
self
)
logging
.
setLogRecordClass
(
self
.
orig_cls
)
def
test_logrecord_class
(
self
):
self
.
assertRaises
(
TypeError
,
self
.
root_logger
.
warning
,
self
.
next_message
())
logging
.
setLogRecordClass
(
DerivedLogRecord
)
self
.
root_logger
.
error
(
self
.
next_message
())
self
.
assert_log_lines
([
(
'root'
,
'ERROR'
,
'2'
),
])
class
QueueHandlerTest
(
BaseTest
):
# Do not bother with a logger name group.
expected_log_pat
=
r"^[\w.]+ -> ([\w]+): ([\d]+)$"
...
...
@@ -1877,7 +1916,7 @@ def test_main():
CustomLevelsAndFiltersTest
,
MemoryHandlerTest
,
ConfigFileTest
,
SocketHandlerTest
,
MemoryTest
,
EncodingTest
,
WarningsTest
,
ConfigDictTest
,
ManagerTest
,
ChildLoggerTest
,
QueueHandlerTest
,
LogRecordClassTest
,
ChildLoggerTest
,
QueueHandlerTest
,
RotatingFileHandlerTest
,
#TimedRotatingFileHandlerTest
)
...
...
Misc/NEWS
Dosyayı görüntüle @
6fac8171
...
...
@@ -34,6 +34,8 @@ Core and Builtins
Library
-------
- logging: Added tests for _logRecordClass changes.
- Issue #10092: Properly reset locale in calendar.Locale*Calendar classes.
- logging: Added _logRecordClass, getLogRecordClass, setLogRecordClass to
...
...
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