Skip to content

Commit

Permalink
fix LoggerConfig inconsistency bug (#233)
Browse files Browse the repository at this point in the history
* fix LoggerConfig

* add comment
  • Loading branch information
mski-iksm authored Aug 10, 2021
1 parent 55bf7c4 commit 1654f00
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions gokart/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def __init__(self, level: int = logging.CRITICAL):
self.level = level

def __enter__(self):
logging.disable(self.level)
logging.disable(self.level - 10) # subtract 10 to disable below self.level
self.logger.setLevel(self.level)
return self

def __exit__(self, exception_type, exception_value, traceback):
logging.disable(self.default_level)
logging.disable(self.default_level - 10) # subtract 10 to disable below self.level
self.logger.setLevel(self.default_level)


Expand Down
11 changes: 8 additions & 3 deletions test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,15 @@ def test_build_dict_outputs(self):

class LoggerConfigTest(unittest.TestCase):
def test_logger_config(self):
for level, expected in ((logging.INFO, logging.INFO), (logging.DEBUG, logging.DEBUG), (logging.CRITICAL, logging.CRITICAL)):
with self.subTest(level=level, expected=expected):
for level, enable_expected, disable_expected in (
(logging.INFO, logging.INFO, logging.DEBUG),
(logging.DEBUG, logging.DEBUG, logging.NOTSET),
(logging.CRITICAL, logging.CRITICAL, logging.ERROR),
):
with self.subTest(level=level, enable_expected=enable_expected, disable_expected=disable_expected):
with LoggerConfig(level) as lc:
self.assertEqual(lc.logger.level, expected)
self.assertTrue(lc.logger.isEnabledFor(enable_expected))
self.assertTrue(not lc.logger.isEnabledFor(disable_expected))


if __name__ == '__main__':
Expand Down

0 comments on commit 1654f00

Please sign in to comment.