-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include option to stream print to stderr
Now directs all print output through new `utils.print_it` function. In turn that prints to a stream, either stdout or stderr, as dictated by global variable `_print_stdout` on new config module. `_print_stdout` takes a bool and is set and accessed via methods on `config.py`. Can also set print stream to stderr from the cli by passing --print_stderr or -p flag. Tests included. Documented to README to new 'Developers' section.
- Loading branch information
Showing
12 changed files
with
224 additions
and
25 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
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,22 @@ | ||
"""Configuration file for options.""" | ||
|
||
import sys | ||
|
||
_print_stdout = True | ||
|
||
|
||
def set_print_stdout(): | ||
"""Set output stream for print to stdout.""" | ||
global _print_stdout | ||
_print_stdout = True | ||
|
||
|
||
def set_print_stderr(): | ||
"""Set output stream for print to stderr.""" | ||
global _print_stdout | ||
_print_stdout = False | ||
|
||
|
||
def get_print_file(): | ||
"""Get stream to print to.""" | ||
return sys.stdout if _print_stdout else sys.stderr |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""Tests for `config` module.""" | ||
|
||
import sys | ||
|
||
from beanahead import config as m | ||
|
||
from .conftest import also_get_stdout, also_get_stderr | ||
|
||
# pylint: disable=missing-function-docstring, missing-type-doc, missing-class-docstring | ||
# pylint: disable=missing-param-doc, missing-any-param-doc, redefined-outer-name | ||
# pylint: disable=too-many-public-methods, too-many-arguments, too-many-locals | ||
# pylint: disable=too-many-statements | ||
# pylint: disable=protected-access, line-too-long, unused-argument, invalid-name | ||
# missing-fuction-docstring: doc not required for all tests | ||
# protected-access: not required for tests | ||
# not compatible with use of fixtures to parameterize tests: | ||
# too-many-arguments, too-many-public-methods | ||
# not compatible with pytest fixtures: | ||
# redefined-outer-name, missing-any-param-doc, missing-type-doc | ||
# unused-argument: not compatible with pytest fixtures, caught by pylance anyway. | ||
# invalid-name: names in tests not expected to strictly conform with snake_case. | ||
|
||
|
||
def test_print_stream(): | ||
"""Tests output of print stream between stdout and stderr.""" | ||
assert m._print_stdout is True | ||
assert m.get_print_file() is sys.stdout | ||
|
||
def print_something(): | ||
print("something", file=m.get_print_file()) | ||
|
||
_, prnt = also_get_stdout(print_something) | ||
assert prnt == "something\n" | ||
_, prnt = also_get_stderr(print_something) | ||
assert not prnt | ||
|
||
m.set_print_stderr() | ||
_, prnt = also_get_stdout(print_something) | ||
assert not prnt | ||
_, prnt = also_get_stderr(print_something) | ||
assert prnt == "something\n" | ||
|
||
m.set_print_stdout() | ||
_, prnt = also_get_stdout(print_something) | ||
assert prnt == "something\n" | ||
_, prnt = also_get_stderr(print_something) | ||
assert not prnt |
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
Oops, something went wrong.