<commit_before>import io
from slug import Tee, Valve, Pipe


def test_tee_basics():
    pin = Pipe()
    pout = Pipe()
    buf = io.BytesIO()
    t = Tee(  # noqa
        side_in=pin.side_out,
        side_out=pout.side_in,
        callback=buf.write,
        # Closing a BytesIO disables getting the value
        # eof=buf.close,
    )
    pin.side_in.write(b'foobar')
    pin.side_in.close()

    assert buf.getvalue() == b'foobar'
    roundtrip = pout.side_out.read()
    assert roundtrip == b'foobar'


def test_valve_basics():
    pin = Pipe()
    pout = Pipe()
    v = Valve(  # noqa
        side_in=pin.side_out,
        side_out=pout.side_in,
    )
    v.turn_on()

    pin.side_in.write(b'spameggs')
    pin.side_in.close()

    # FIXME: Actually test turning on and off

    roundtrip = pout.side_out.read()<commit_msg>Fix some tests<commit_after>import io
from slug import Tee, Valve, Pipe


def test_tee_basics():
    pin = Pipe()
    pout = Pipe()
    buf = io.BytesIO()
    t = Tee(  # noqa
        side_in=pin.side_out,
        side_out=pout.side_in,
        callback=buf.write,
        # Closing a BytesIO disables getting the value
        # eof=buf.close,
    )
    pin.side_in.write(b'foobar')
    pin.side_in.close()

    roundtrip = pout.side_out.read()
    assert roundtrip == b'foobar'
    # This is only guarenteed _after_ it appears on the pipe
    assert buf.getvalue() == b'foobar'


def test_valve_through():
    pin = Pipe()
    pout = Pipe()
    v = Valve(  # noqa
        side_in=pin.side_out,
        side_out=pout.side_in,
    )
    v.turn_on()

    pin.side_in.write(b'spameggs')
    pin.side_in.close()

    roundtrip = pout.side_out.read()
{'fraction_non_alphanumeric': 0.11992840095465394, 'fraction_numerical': 0.0, 'mean_word_length': 2.415478615071283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3791316', 'n_tokens_mistral': 666, 'n_tokens_neox': 641, 'n_words': 130}