This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement custom print collector * added doc strings and minor cleanup * catch syntax warning incorrect syntax warning * tests * bump version * pep8 * pep8++ * Merge branch 'development' into PrintCollector_improvements * minor changes + remove clean log function as no longer needed * improvements to log output * separated tests and added new test * refactored log printing
- Loading branch information
1 parent
7ca8879
commit 8c20d4c
Showing
4 changed files
with
114 additions
and
39 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class LogManager(object): | ||
""" Wrapper for the PrintCollector which allows logs to have | ||
state. The class definition for the PrintCollector is | ||
passed into the globals for the user's code before execution. """ | ||
def __init__(self): | ||
class PrintCollector(object): | ||
""" Collect written text, and return it when called. """ | ||
|
||
def __init__(print_collector, _getattr_=None): | ||
print_collector.logs = self.logs | ||
print_collector._getattr_ = _getattr_ | ||
|
||
def write(print_collector, text): | ||
print_collector.logs.append(text) | ||
|
||
def __call__(print_collector): | ||
return ''.join(print_collector.logs) | ||
|
||
def _call_print(print_collector, *objects, **kwargs): | ||
if kwargs.get('file', None) is None: | ||
kwargs['file'] = print_collector | ||
else: | ||
print_collector._getattr_(kwargs['file'], 'write') | ||
|
||
print(*objects, **kwargs) | ||
|
||
self.logs = [] | ||
self.print_collector = PrintCollector | ||
|
||
def get_print_collector(self): | ||
return self.print_collector | ||
|
||
def get_logs(self): | ||
return ''.join(self.logs) | ||
|
||
def is_empty(self): | ||
return self.logs == [] | ||
|
||
def clear_logs(self): | ||
self.logs = [] |
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 +1 @@ | ||
0.4.2 | ||
0.4.3 |