Skip to content

Commit 89dbc86

Browse files
committed
Pylint part 2,
1 parent 1f1c4d9 commit 89dbc86

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

logwrap/_alogwrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def wrapper(*args, **kwargs):
9797
return wrapper
9898

9999

100-
# pylint: disable=unexpected-keyword-arg
100+
# pylint: disable=unexpected-keyword-arg, no-value-for-parameter
101101
def async_logwrap(
102102
log: logging.Logger=_log_wrap_shared.logger,
103103
log_level: int=logging.DEBUG,
@@ -152,4 +152,4 @@ def async_logwrap(
152152
log_call_args_on_exc=log_call_args_on_exc,
153153
log_result_obj=log_result_obj
154154
)
155-
# pylint: enable=unexpected-keyword-arg
155+
# pylint: enable=unexpected-keyword-arg, no-value-for-parameter

logwrap/_log_wrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def wrapper(*args, **kwargs):
104104
return wrapper
105105

106106

107-
# pylint: disable=unexpected-keyword-arg
107+
# pylint: disable=unexpected-keyword-arg, no-value-for-parameter
108108
def logwrap(
109109
log=_log_wrap_shared.logger,
110110
log_level=logging.DEBUG,
@@ -159,4 +159,4 @@ def logwrap(
159159
log_call_args_on_exc=log_call_args_on_exc,
160160
log_result_obj=log_result_obj
161161
)
162-
# pylint: enable=unexpected-keyword-arg
162+
# pylint: enable=unexpected-keyword-arg, no-value-for-parameter

test/test_log_wrap.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,29 @@ def func(test_arg1, test_arg2):
477477
),
478478
))
479479

480+
def test_exceptions_blacklist(self, logger):
481+
new_logger = mock.Mock(spec=logging.Logger, name='logger')
482+
log = mock.Mock(name='log')
483+
new_logger.attach_mock(log, 'log')
484+
485+
@logwrap.logwrap(log=new_logger, blacklisted_exceptions=[TypeError])
486+
def func():
487+
raise TypeError('Blacklisted')
488+
489+
with self.assertRaises(TypeError):
490+
func()
491+
492+
self.assertEqual(len(logger.mock_calls), 0)
493+
self.assertEqual(
494+
log.mock_calls,
495+
[
496+
mock.call(
497+
level=logging.DEBUG,
498+
msg="Calling: \n'func'()"
499+
),
500+
]
501+
)
502+
480503

481504
@mock.patch('logwrap._log_wrap_shared.logger', autospec=True)
482505
@unittest.skipUnless(
@@ -647,3 +670,42 @@ def func():
647670
msg="Done: 'func' with result:\nNone"
648671
)
649672
))
673+
674+
def test_exceptions_blacklist(self, logger):
675+
new_logger = mock.Mock(spec=logging.Logger, name='logger')
676+
log = mock.Mock(name='log')
677+
new_logger.attach_mock(log, 'log')
678+
679+
namespace = {
680+
'logwrap': logwrap,
681+
'loop': self.loop,
682+
'new_logger': new_logger,
683+
'assertRaises': self.assertRaises
684+
}
685+
686+
exec("""
687+
import asyncio
688+
689+
@logwrap.async_logwrap(log=new_logger, blacklisted_exceptions=[TypeError])
690+
@asyncio.coroutine
691+
def func():
692+
raise TypeError('Blacklisted')
693+
694+
with assertRaises(TypeError):
695+
loop.run_until_complete(func())
696+
""",
697+
namespace
698+
)
699+
# While we're not expanding result coroutine object from namespace,
700+
# do not check execution result
701+
702+
self.assertEqual(len(logger.mock_calls), 0)
703+
self.assertEqual(
704+
log.mock_calls,
705+
[
706+
mock.call(
707+
level=logging.DEBUG,
708+
msg="Awaiting: \n'func'()"
709+
),
710+
]
711+
)

0 commit comments

Comments
 (0)