# Path: plumbing/redirect.py
# class RedirectStdStreams(object):
#     """
#     See file `plumbing/test/redirect/test_redirect.py`
#     """
# 
#     def __init__(self, stdout=None, stderr=None):
#         self._stdout = stdout or sys.stdout
#         self._stderr = stderr or sys.stderr
# 
#     def __enter__(self):
#         # Save old ones #
#         self.old_stdout = sys.stdout
#         self.old_stderr = sys.stderr
#         # Flush everything #
#         self.old_stdout.flush()
#         self.old_stderr.flush()
#         # Redirect #
#         sys.stdout = self._stdout
#         sys.stderr = self._stderr
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         # Flush #
#         self._stdout.flush()
#         self._stderr.flush()
#         # Restore #
#         sys.stdout = self.old_stdout
#         sys.stderr = self.old_stderr


import inspect, os
from plumbing.redirect import RedirectStdStreams
# Built-in module #

# Internal modules #

# Constants #
file_name = inspect.getframeinfo(inspect.currentframe()).filename
this_dir  = os.path.dirname(os.path.abspath(file_name)) + '/'

# Test #
print('I should be in the standard out')
with open(this_dir + 'test_redirect.log', 'w') as log_handle:

# Path: plumbing/redirect.py
# class RedirectStdStreams(object):
#     """
#     See file `plumbing/test/redirect/test_redirect.py`
#     """
# 
#     def __init__(self, stdout=None, stderr=None):
#         self._stdout = stdout or sys.stdout
#         self._stderr = stderr or sys.stderr
# 
#     def __enter__(self):
#         # Save old ones #
#         self.old_stdout = sys.stdout
#         self.old_stderr = sys.stderr
#         # Flush everything #
#         self.old_stdout.flush()
#         self.old_stderr.flush()
#         # Redirect #
#         sys.stdout = self._stdout
#         sys.stderr = self._stderr
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         # Flush #
#         self._stdout.flush()
#         self._stderr.flush()
#         # Restore #
#         sys.stdout = self.old_stdout
#         sys.stderr = self.old_stderr


# Path: testing/redirect/test_redirect.py
import inspect, os
from plumbing.redirect import RedirectStdStreams

# Built-in module #

# Internal modules #

# Constants #
file_name = inspect.getframeinfo(inspect.currentframe()).filename
this_dir  = os.path.dirname(os.path.abspath(file_name)) + '/'

# Test #
print('I should be in the standard out')
with open(this_dir + 'test_redirect.log', 'w') as log_handle:

    with RedirectStdStreams(stdout=log_handle, stderr=log_handle):