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
5056c8c7
Commit
5056c8c7
authored
Jun 05, 2011
by
Vinay Sajip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes issue #11557: removal of non-idiomatic code in test_logging.
parent
d64b2bae
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
31 deletions
+25
-31
Lib/test/test_logging.py
Lib/test/test_logging.py
+25
-31
No files found.
Lib/test/test_logging.py
View file @
5056c8c7
...
...
@@ -158,8 +158,7 @@ class BaseTest(unittest.TestCase):
except AttributeError:
# StringIO.StringIO lacks a reset() method.
actual_lines = stream.getvalue().splitlines()
self.assertEqual(len(actual_lines), len(expected_values),
'%s vs. %s' % (actual_lines, expected_values))
self.assertEqual(len(actual_lines), len(expected_values))
for actual, expected in zip(actual_lines, expected_values):
match = pat.search(actual)
if not match:
...
...
@@ -599,8 +598,8 @@ class StreamHandlerTest(BaseTest):
h = logging.StreamHandler(BadStream())
sys.stderr = sio = io.StringIO()
h.handle(r)
self.assert
True('
\
n
RuntimeError: '
'deliberate mistake
\
n
' in
sio.getvalue())
self.assert
In('
\
n
RuntimeError: deliberate mistake
\
n
',
sio.getvalue())
logging.raiseExceptions = False
sys.stderr = sio = io.StringIO()
h.handle(r)
...
...
@@ -940,7 +939,7 @@ class SMTPHandlerTest(BaseTest):
peer, mailfrom, rcpttos, data = self.messages[0]
self.assertEqual(mailfrom, 'me')
self.assertEqual(rcpttos, ['you'])
self.assert
True('
\
n
Subject: Log
\
n
' in
data)
self.assert
In('
\
n
Subject: Log
\
n
',
data)
self.assertTrue(data.endswith('
\
n
\
n
Hello'))
h.close()
...
...
@@ -1692,7 +1691,7 @@ class WarningsTest(BaseTest):
def test_warnings(self):
with warnings.catch_warnings():
logging.captureWarnings(True)
self.addCleanup(l
ambda: logging.captureWarnings(False)
)
self.addCleanup(l
ogging.captureWarnings, False
)
warnings.filterwarnings("
always
", category=UserWarning)
stream = io.StringIO()
h = logging.StreamHandler(stream)
...
...
@@ -1716,14 +1715,14 @@ class WarningsTest(BaseTest):
def test_warnings_no_handlers(self):
with warnings.catch_warnings():
logging.captureWarnings(True)
self.addCleanup(l
ambda: logging.captureWarnings(False)
)
self.addCleanup(l
ogging.captureWarnings, False
)
# confirm our assumption: no loggers are set
logger = logging.getLogger("
py
.
warnings
")
assert logger.handlers == []
self.assertEqual(logger.handlers, [])
warnings.showwarning("
Explicit
", UserWarning, "
dummy
.
py
", 42)
self.assert
True(len(logger.handlers) ==
1)
self.assert
Equal(len(logger.handlers),
1)
self.assertIsInstance(logger.handlers[0], logging.NullHandler)
...
...
@@ -2971,7 +2970,7 @@ class ShutdownTest(BaseTest):
self.called = []
raise_exceptions = logging.raiseExceptions
self.addCleanup(
lambda: setattr(logging, 'raiseExceptions', raise_exceptions)
)
self.addCleanup(
setattr, logging, 'raiseExceptions', raise_exceptions
)
def raise_error(self, error):
def inner():
...
...
@@ -3056,8 +3055,8 @@ class ModuleLevelMiscTest(BaseTest):
def test_disable(self):
old_disable = logging.root.manager.disable
# confirm our assumptions are correct
assert old_disable == 0
self.addCleanup(l
ambda: logging.disable(old_disable)
)
self.assertEqual(old_disable, 0)
self.addCleanup(l
ogging.disable, old_disable
)
logging.disable(83)
self.assertEqual(logging.root.manager.disable, 83)
...
...
@@ -3266,7 +3265,7 @@ class BasicConfigTest(unittest.TestCase):
def test_level(self):
old_level = logging.root.level
self.addCleanup(l
ambda: logging.root.setLevel(old_level)
)
self.addCleanup(l
ogging.root.setLevel, old_level
)
logging.basicConfig(level=57)
self.assertEqual(logging.root.level, 57)
...
...
@@ -3311,7 +3310,7 @@ class BasicConfigTest(unittest.TestCase):
old_basic_config()
old_level = logging.root.level
logging.root.setLevel(100) # avoid having messages in stderr
self.addCleanup(l
ambda: logging.root.setLevel(old_level)
)
self.addCleanup(l
ogging.root.setLevel, old_level
)
called.append((a, kw))
patch(self, logging, 'basicConfig', my_basic_config)
...
...
@@ -3353,7 +3352,7 @@ class LoggerAdapterTest(unittest.TestCase):
self.recording = RecordingHandler()
self.logger = logging.root
self.logger.addHandler(self.recording)
self.addCleanup(
lambda: self.logger.removeHandler(self.recording)
)
self.addCleanup(
self.logger.removeHandler, self.recording
)
self.addCleanup(self.recording.close)
def cleanup():
...
...
@@ -3367,8 +3366,8 @@ class LoggerAdapterTest(unittest.TestCase):
msg = 'testing exception: %r'
exc = None
try:
assert False
except
Assert
ionError as e:
1 / 0
except
ZeroDivis
ionError as e:
exc = e
self.adapter.exception(msg, self.recording)
...
...
@@ -3393,8 +3392,8 @@ class LoggerAdapterTest(unittest.TestCase):
def test_is_enabled_for(self):
old_disable = self.adapter.logger.manager.disable
self.adapter.logger.manager.disable = 33
self.addCleanup(
lambda: setattr(self.adapter.logger.manager
,
'disable', old_disable)
)
self.addCleanup(
setattr, self.adapter.logger.manager, 'disable'
,
old_disable
)
self.assertFalse(self.adapter.isEnabledFor(32))
def test_has_handlers(self):
...
...
@@ -3402,8 +3401,8 @@ class LoggerAdapterTest(unittest.TestCase):
for handler in self.logger.handlers:
self.logger.removeHandler(handler)
assert not self.logger.hasHandlers()
self.assertFalse(self.logger.hasHandlers())
self.assertFalse(self.adapter.hasHandlers())
...
...
@@ -3414,7 +3413,7 @@ class LoggerTest(BaseTest):
self.recording = RecordingHandler()
self.logger = logging.Logger(name='blah')
self.logger.addHandler(self.recording)
self.addCleanup(
lambda: self.logger.removeHandler(self.recording)
)
self.addCleanup(
self.logger.removeHandler, self.recording
)
self.addCleanup(self.recording.close)
self.addCleanup(logging.shutdown)
...
...
@@ -3425,8 +3424,8 @@ class LoggerTest(BaseTest):
msg = 'testing exception: %r'
exc = None
try:
assert False
except
Assert
ionError as e:
1 / 0
except
ZeroDivis
ionError as e:
exc = e
self.logger.exception(msg, self.recording)
...
...
@@ -3440,14 +3439,14 @@ class LoggerTest(BaseTest):
def test_log_invalid_level_with_raise(self):
old_raise = logging.raiseExceptions
self.addCleanup(
lambda: setattr(logging, 'raiseExecptions', old_raise)
)
self.addCleanup(
setattr, logging, 'raiseExecptions', old_raise
)
logging.raiseExceptions = True
self.assertRaises(TypeError, self.logger.log, '10', 'test message')
def test_log_invalid_level_no_raise(self):
old_raise = logging.raiseExceptions
self.addCleanup(
lambda: setattr(logging, 'raiseExecptions', old_raise)
)
self.addCleanup(
setattr, logging, 'raiseExecptions', old_raise
)
logging.raiseExceptions = False
self.logger.log('10', 'test message') # no exception happens
...
...
@@ -3489,22 +3488,17 @@ class LoggerTest(BaseTest):
for handler in self.logger.handlers:
self.logger.removeHandler(handler)
assert not self.logger.hasHandlers()
self.assertFalse(self.logger.hasHandlers())
def test_has_handlers_no_propagate(self):
child_logger = logging.getLogger('blah.child')
child_logger.propagate = False
assert child_logger.handlers == []
self.assertFalse(child_logger.hasHandlers())
def test_is_enabled_for(self):
old_disable = self.logger.manager.disable
self.logger.manager.disable = 23
self.addCleanup(lambda: setattr(self.logger.manager,
'disable', old_disable))
self.addCleanup(setattr, self.logger.manager, 'disable', old_disable)
self.assertFalse(self.logger.isEnabledFor(22))
...
...
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