# Path: sacred/stdout_capturing.py
# def get_stdcapturer(mode=None):
#     mode = mode if mode is not None else SETTINGS.CAPTURE_MODE
#     capture_options = {"no": no_tee, "fd": tee_output_fd, "sys": tee_output_python}
#     if mode not in capture_options:
#         raise KeyError(
#             "Unknown capture mode '{}'. Available options are {}".format(
#                 mode, sorted(capture_options.keys())
#             )
#         )
#     return mode, capture_options[mode]
# 
# Path: sacred/optional.py
# def optional_import(*package_names):
# def get_tensorflow():


import os
import sys
import pytest
from sacred.stdout_capturing import get_stdcapturer
from sacred.optional import libc
            print("captured stderr")
        output = out.get()

        print("after (stdout)")
        print("after (stderr)")

        assert set(output.strip().split("\n")) == expected_lines


@pytest.mark.skipif(sys.platform.startswith("win"), reason="does not run on windows")
def test_fd_tee_output(capsys):
    expected_lines = {
        "captured stdout",
        "captured stderr",
        "stdout from C",
        "and this is from echo",
        "keep\rcarriage\rreturns",
    }

    capture_mode, capture_stdout = get_stdcapturer("fd")
    output = ""
    with capsys.disabled():
        print("before (stdout)")
        print("before (stderr)")
        with capture_stdout() as out:
            print("captured stdout")
            print("captured stderr", file=sys.stderr)
            print("keep\rcarriage\rreturns")
            output += out.get()
            libc.puts(b"stdout from C")

# Path: sacred/stdout_capturing.py
# def get_stdcapturer(mode=None):
#     mode = mode if mode is not None else SETTINGS.CAPTURE_MODE
#     capture_options = {"no": no_tee, "fd": tee_output_fd, "sys": tee_output_python}
#     if mode not in capture_options:
#         raise KeyError(
#             "Unknown capture mode '{}'. Available options are {}".format(
#                 mode, sorted(capture_options.keys())
#             )
#         )
#     return mode, capture_options[mode]
# 
# Path: sacred/optional.py
# def optional_import(*package_names):
# def get_tensorflow():


# Path: tests/test_stdout_capturing.py
import os
import sys
import pytest
from sacred.stdout_capturing import get_stdcapturer
from sacred.optional import libc

            print("captured stderr")
        output = out.get()

        print("after (stdout)")
        print("after (stderr)")

        assert set(output.strip().split("\n")) == expected_lines


@pytest.mark.skipif(sys.platform.startswith("win"), reason="does not run on windows")
def test_fd_tee_output(capsys):
    expected_lines = {
        "captured stdout",
        "captured stderr",
        "stdout from C",
        "and this is from echo",
        "keep\rcarriage\rreturns",
    }

    capture_mode, capture_stdout = get_stdcapturer("fd")
    output = ""
    with capsys.disabled():
        print("before (stdout)")
        print("before (stderr)")
        with capture_stdout() as out:
            print("captured stdout")
            print("captured stderr", file=sys.stderr)
            print("keep\rcarriage\rreturns")
            output += out.get()
            libc.puts(b"stdout from C")

            libc.fflush(None)