Skip to content

Commit

Permalink
Merge pull request #36 from certego/develop
Browse files Browse the repository at this point in the history
0.3.5
  • Loading branch information
drosetti authored Dec 1, 2022
2 parents 8f9e2bf + b305d06 commit dab61c1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ __pycache__/
venv/
.vscode
build/
.idea

# C extensions
*.so
Expand Down
17 changes: 13 additions & 4 deletions certego_saas/ext/test_utilities/no_logs_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,39 @@


class NoLogsTestCase(unittest.TestCase):
def __init__(self, *args, max_logging_level=logging.WARNING, **kwargs):
def __init__(self, *args, max_logging_level=logging.CRITICAL, **kwargs):
self._log = logging.getLogger(__name__)
self.test_method = None
self.max_logging_level = max_logging_level
super().__init__(*args, **kwargs)
self.override_local_max_logging_level = None

@contextlib.contextmanager
def assertNoLogs(self, logger=None, level=None): # pylint: disable=invalid-name
def assertNoLogs(
self, logger=None, level=logging.WARNING
): # pylint: disable=invalid-name
try:
with self.assertLogs(logger=logger, level=level) as new_log:
yield
except AssertionError as e:
if not e.args[0].startswith("no logs of level"):

if isinstance(e.args[0], str) and not e.args[0].startswith(
"no logs of level"
):
raise e
else:
for record in new_log.records:
if self.override_local_max_logging_level is not None:
level = self.override_local_max_logging_level
if record.levelno >= level:
raise AssertionError(
f"Unexpected logging message: '{record.message}' with level {record.levelname}"
f"Unexpected logging message: '{record.message}' with level {record.levelname}. Max level is {level}"
)

def no_logs(self):
with self.assertNoLogs(level=self.max_logging_level):
self.test_method()
self.override_local_max_logging_level = None

def run(self, result=None):
self.test_method = getattr(self, self._testMethodName)
Expand Down
2 changes: 1 addition & 1 deletion certego_saas/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.3.4"
VERSION = "0.3.5"

0 comments on commit dab61c1

Please sign in to comment.