File tree Expand file tree Collapse file tree 2 files changed +30
-29
lines changed Expand file tree Collapse file tree 2 files changed +30
-29
lines changed Original file line number Diff line number Diff line change
1
+ import logging .handlers
2
+
3
+ class TestHandler (logging .handlers .BufferingHandler ):
4
+ def __init__ (self , matcher ):
5
+ # BufferingHandler takes a "capacity" argument
6
+ # so as to know when to flush. As we're overriding
7
+ # shouldFlush anyway, we can set a capacity of zero.
8
+ # You can call flush() manually to clear out the
9
+ # buffer.
10
+ logging .handlers .BufferingHandler .__init__ (self , 0 )
11
+ self .matcher = matcher
12
+
13
+ def shouldFlush (self ):
14
+ return False
15
+
16
+ def emit (self , record ):
17
+ self .format (record )
18
+ self .buffer .append (record .__dict__ )
19
+
20
+ def matches (self , ** kwargs ):
21
+ """
22
+ Look for a saved dict whose keys/values match the supplied arguments.
23
+ """
24
+ result = False
25
+ for d in self .buffer :
26
+ if self .matcher .matches (d , ** kwargs ):
27
+ result = True
28
+ break
29
+ return result
Original file line number Diff line number Diff line change 43
43
import tempfile
44
44
from test .support .script_helper import assert_python_ok , assert_python_failure
45
45
from test import support
46
+ from test .support .logging_helper import TestHandler
46
47
import textwrap
47
48
import threading
48
49
import time
@@ -3477,35 +3478,6 @@ def test_logrecord_class(self):
3477
3478
])
3478
3479
3479
3480
3480
- class TestHandler (logging .handlers .BufferingHandler ):
3481
- def __init__ (self , matcher ):
3482
- # BufferingHandler takes a "capacity" argument
3483
- # so as to know when to flush. As we're overriding
3484
- # shouldFlush anyway, we can set a capacity of zero.
3485
- # You can call flush() manually to clear out the
3486
- # buffer.
3487
- logging .handlers .BufferingHandler .__init__ (self , 0 )
3488
- self .matcher = matcher
3489
-
3490
- def shouldFlush (self ):
3491
- return False
3492
-
3493
- def emit (self , record ):
3494
- self .format (record )
3495
- self .buffer .append (record .__dict__ )
3496
-
3497
- def matches (self , ** kwargs ):
3498
- """
3499
- Look for a saved dict whose keys/values match the supplied arguments.
3500
- """
3501
- result = False
3502
- for d in self .buffer :
3503
- if self .matcher .matches (d , ** kwargs ):
3504
- result = True
3505
- break
3506
- return result
3507
-
3508
-
3509
3481
class QueueHandlerTest (BaseTest ):
3510
3482
# Do not bother with a logger name group.
3511
3483
expected_log_pat = r"^[\w.]+ -> (\w+): (\d+)$"
You can’t perform that action at this time.
0 commit comments