<commit_before>import pytest
from six import string_types

try:
    from unittest.mock import Mock
except ImportError:
    from mock import Mock

from simpletimeit import stimeit

def test_call_with_values():
    st = stimeit.SimpleTimeIt()
    args = ['foo', {'a': 1, 'b': 2}, 19]
    for a in args:
        st.call_with(a)
    assert [x.args for x in st._args_setups] == list(map(repr, args))


def test_call_with_args_length():
    for n in (1, 2, 3, 7, 39, 99):
        st = stimeit.SimpleTimeIt()
        for _ in range(n):
            st.call_with('')
        assert len(st._args_setups) == n


def test_call_with_setup_default():
    st = stimeit.SimpleTimeIt()
    args = ['foo', 'bar']
    for a in args:
        st.call_with(a)
    assert [x.setup for x in st._args_setups] == ['pass', 'pass']


def test_call_with_setup():
    st = stimeit.SimpleTimeIt()
    setups = ['import foo', 'import bar', 'import baz']
    for s in setups:
        st.call_with('', _setup=s)
    assert [x.setup for x in st._args_setups] == setups


def test_call_with_invalid_input():
    st = stimeit.SimpleTimeIt()
    with pytest.raises(ValueError):
        st.call_with(map(str, (1, 2, 4, 8, 16)))
    with pytest.raises(ValueError):
        st.call_with(lambda x: None)


def test_current_function():
    # at first, there's no _stimeit_current_function
    with pytest.raises(AttributeError):
        stimeit._stimeit_current_function

    # then it has the value of the function passed to the contextmanager
    dummy = object()
    with stimeit.current_function(dummy):
        assert stimeit._stimeit_current_function is dummy

    # then there's no _stimeit_current_function again
    with pytest.raises(AttributeError):
        stimeit._stimeit_current_function


# test _functions gets value on with time_this used as decorator
def test_time_this_length():
    for n in (1, 2, 3, 7, 42, 85):
        st = stimeit.SimpleTimeIt()
        for _ in range(n):
            @st.time_this
            def foo():
                pass
        assert len(st._functions) == n


def test_time_this_values():
    st = stimeit.SimpleTimeIt()

    @st.time_this
    def foo():
        pass
    @st.time_this
    def bar():
        pass
    @st.time_this
    def baz():
        pass

    assert st._functions == [foo, bar, baz]


def test_time_this_add_to_multiple_simpletimeits():
    st_a = stimeit.SimpleTimeIt()
    st_b = stimeit.SimpleTimeIt()

    @st_a.time_this<commit_msg>cleans up comments in tests<commit_after>import pytest
from six import string_types

try:
    from unittest.mock import Mock
except ImportError:
    from mock import Mock

from simpletimeit import stimeit

def test_call_with_values():
    st = stimeit.SimpleTimeIt()
    args = ['foo', {'a': 1, 'b': 2}, 19]
    for a in args:
        st.call_with(a)
    assert [x.args for x in st._args_setups] == list(map(repr, args))


def test_call_with_args_length():
    for n in (1, 2, 3, 7, 39, 99):
        st = stimeit.SimpleTimeIt()
        for _ in range(n):
            st.call_with('')
        assert len(st._args_setups) == n


def test_call_with_setup_default():
    st = stimeit.SimpleTimeIt()
    args = ['foo', 'bar']
    for a in args:
        st.call_with(a)
    assert [x.setup for x in st._args_setups] == ['pass', 'pass']


def test_call_with_setup():
    st = stimeit.SimpleTimeIt()
    setups = ['import foo', 'import bar', 'import baz']
    for s in setups:
        st.call_with('', _setup=s)
    assert [x.setup for x in st._args_setups] == setups


def test_call_with_invalid_input():
    st = stimeit.SimpleTimeIt()
    with pytest.raises(ValueError):
        # repr(map(...)) doesn't look like declaration of that map
        st.call_with(map(str, (1, 2, 4, 8, 16)))
    with pytest.raises(ValueError):
        st.call_with(lambda x: None)


def test_current_function():
    # at first, there's no _stimeit_current_function
    with pytest.raises(AttributeError):
        stimeit._stimeit_current_function

    # then it has the value of the function passed to the contextmanager
    dummy = object()
    with stimeit.current_function(dummy):
        assert stimeit._stimeit_current_function is dummy

    # then there's no _stimeit_current_function again
    with pytest.raises(AttributeError):
        stimeit._stimeit_current_function


def test_time_this_length():
    for n in (1, 2, 3, 7, 42, 85):
        st = stimeit.SimpleTimeIt()
        for _ in range(n):
            @st.time_this
            def foo():
                pass
        assert len(st._functions) == n


def test_time_this_values():
    st = stimeit.SimpleTimeIt()

    @st.time_this
    def foo():
        pass
    @st.time_this
    def bar():
        pass
    @st.time_this
    def baz():
        pass

    assert st._functions == [foo, bar, baz]


def test_time_this_add_to_multiple_simpletimeits():
    st_a = stimeit.SimpleTimeIt()
    st_b = stimeit.SimpleTimeIt()

    @st_a.time_this
{'fraction_non_alphanumeric': 0.10881877022653721, 'fraction_numerical': 0.010517799352750809, 'mean_word_length': 2.7805810397553516, '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': '5682594', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1688, 'n_words': 451}