-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from jedie/dev
Use: cli_base.cli_tools.test_utils.logs.AssertLogs
- Loading branch information
Showing
12 changed files
with
75 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,17 @@ | ||
import logging | ||
from pathlib import Path | ||
from unittest import TestCase | ||
import warnings | ||
|
||
from cli_base.cli_tools.test_utils.logs import AssertLogs as OriginalAssertLogs | ||
|
||
class AssertLogs: | ||
|
||
class AssertLogs(OriginalAssertLogs): | ||
""" | ||
Capture and assert log output from different loggers. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
test_case: TestCase, | ||
loggers: tuple[str, ...] = ('manageprojects', 'cookiecutter'), | ||
level=logging.DEBUG, | ||
): | ||
assertLogs = test_case.assertLogs | ||
|
||
self.logs = [] | ||
for logger in loggers: | ||
self.logs.append(assertLogs(logger, level=level)) | ||
|
||
self.context_managers = None | ||
|
||
def __enter__(self): | ||
self.context_managers = [log.__enter__() for log in self.logs] | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
for log in self.logs: | ||
log.__exit__(exc_type, exc_val, exc_tb) | ||
|
||
def assert_in(self, *test_parts): | ||
outputs = [] | ||
for cm in self.context_managers: | ||
outputs.extend(cm.output) | ||
|
||
output = '\n'.join(outputs) | ||
for part in test_parts: | ||
if isinstance(part, Path): | ||
part = str(part) | ||
assert part in output, f'Log part {part!r} not found in:\n{output}' | ||
def __init__(self, *args, **kwargs): | ||
warnings.warn( | ||
'Migrate to: cli_base.cli_tools.test_utils.logs.AssertLogs !', | ||
DeprecationWarning, | ||
stacklevel=2, | ||
) | ||
super().__init__(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters