mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Added unit testing utility to redirect print output to help validate some functions.
This commit is contained in:
parent
33cb8826ad
commit
757eca26f1
14
graphs_trees/utils/captured_output.py
Normal file
14
graphs_trees/utils/captured_output.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import sys
|
||||||
|
from contextlib import contextmanager
|
||||||
|
from StringIO import StringIO
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def captured_output():
|
||||||
|
new_out, new_err = StringIO(), StringIO()
|
||||||
|
old_out, old_err = sys.stdout, sys.stderr
|
||||||
|
try:
|
||||||
|
sys.stdout, sys.stderr = new_out, new_err
|
||||||
|
yield sys.stdout, sys.stderr
|
||||||
|
finally:
|
||||||
|
sys.stdout, sys.stderr = old_out, old_err
|
Loading…
Reference in New Issue
Block a user