<commit_before>
import time

import pydash as pyd
from .fixtures import parametrize


@parametrize('case,expected', [
    ((2, lambda: 3), 3),
    ((-1, lambda: 3), 3),
])
def test_after(case, expected):
    done = pyd.after(*case)

    # Call done() until n - 1, then check the return value for expected.

    for _ in range(case[0] - 1):
        ret = done()
        assert ret is None

    ret = done()
    assert ret == expected


@parametrize('case,args,expected', [
    ((lambda x: 'Hi {0}'.format(x), lambda x: '!!!' + x + '!!!'),
     ('Bob',),
     'Hi !!!Bob!!!')
])
def test_compose(case, args, expected):
    assert pyd.compose(*case)(*args) == expected


@parametrize('case,arglist,expected', [
    ((lambda a, b, c: a + b + c,), [(1, 1, 1)], 3),
    ((lambda a, b, c: a + b + c,), [(1,), (1, 1)], 3),
    ((lambda a, b, c: a + b + c,), [(1,), (1,), (1,)], 3),
    ((lambda *a: sum(a), 3), [(1, 1, 1)], 3),
    ((lambda *a: sum(a), 3), [(1,), (1,), (1,)], 3),
])
def test_curry(case, arglist, expected):
    curried = pyd.curry(*case)

    # Run test twice to verify curried can be reused
    for _ in range(2):
        ret = curried
        for args in arglist:
            ret = ret(*args)

        assert ret == expected


def test_debounce():
    func = lambda: pyd.now()

    wait = 250
    debounced = pyd.debounce(func, wait)

    start = pyd.now()
    present = pyd.now()

    expected = debounced()

    while (present - start) <= wait + 100:
        result = debounced()
        present = pyd.now()

    assert result == expected

    time.sleep(wait / 1000.0)
    result = debounced()

    assert result > expected


def test_debounce_max_wait():
    func = lambda: pyd.now()

    wait = 250
    max_wait = 300
    debounced = pyd.debounce(func, wait, max_wait=max_wait)

    start = pyd.now()
    present = pyd.now()

    expected = debounced()

    while (present - start) <= max_wait:
        result = debounced()
        present = pyd.now()

    assert result > expected


@parametrize('func,wait,args,kargs,expected', [
    (lambda a, b, c: (a, b, c), 250, (1, 2), {'c': 3}, (1, 2, 3))
])
def test_delay(func, wait, args, kargs, expected):
    start = time.time() * 1000
    result = pyd.delay(func, wait, *args, **kargs)
    stop = time.time() * 1000

    assert (wait - 1) <= (stop - start) <= (wait + 1)
    assert result == expected


@parametrize('case,arglist,expected', [
    (lambda a: a * a, [(2,), (4,)], 4)
])
def test_once(case, arglist, expected):
    for args in arglist:
        pyd.once(case)(*args) == expected


@parametrize('case,case_args,args,expected', [
    (lambda a, b, c: a + b + c, ('a', 'b'), ('c',), 'abc')
])
def test_partial(case, case_args, args, expected):
    assert pyd.partial(case, *case_args)(*args) == expected


@parametrize('case,case_args,args,expected', [
    (lambda a, b, c: a + b + c, ('a', 'b'), ('c',), 'cab')
])
def test_partial_right(case, case_args, args, expected):
    assert pyd.partial_right(case, *case_args)(*args) == expected


def test_throttle():
    func = lambda: pyd.now()<commit_msg>Add larger buffer to wait check.<commit_after>
import time

import pydash as pyd
from .fixtures import parametrize


@parametrize('case,expected', [
    ((2, lambda: 3), 3),
    ((-1, lambda: 3), 3),
])
def test_after(case, expected):
    done = pyd.after(*case)

    # Call done() until n - 1, then check the return value for expected.

    for _ in range(case[0] - 1):
        ret = done()
        assert ret is None

    ret = done()
    assert ret == expected


@parametrize('case,args,expected', [
    ((lambda x: 'Hi {0}'.format(x), lambda x: '!!!' + x + '!!!'),
     ('Bob',),
     'Hi !!!Bob!!!')
])
def test_compose(case, args, expected):
    assert pyd.compose(*case)(*args) == expected


@parametrize('case,arglist,expected', [
    ((lambda a, b, c: a + b + c,), [(1, 1, 1)], 3),
    ((lambda a, b, c: a + b + c,), [(1,), (1, 1)], 3),
    ((lambda a, b, c: a + b + c,), [(1,), (1,), (1,)], 3),
    ((lambda *a: sum(a), 3), [(1, 1, 1)], 3),
    ((lambda *a: sum(a), 3), [(1,), (1,), (1,)], 3),
])
def test_curry(case, arglist, expected):
    curried = pyd.curry(*case)

    # Run test twice to verify curried can be reused
    for _ in range(2):
        ret = curried
        for args in arglist:
            ret = ret(*args)

        assert ret == expected


def test_debounce():
    func = lambda: pyd.now()

    wait = 250
    debounced = pyd.debounce(func, wait)

    start = pyd.now()
    present = pyd.now()

    expected = debounced()

    while (present - start) <= wait + 100:
        result = debounced()
        present = pyd.now()

    assert result == expected

    time.sleep(wait / 1000.0)
    result = debounced()

    assert result > expected


def test_debounce_max_wait():
    func = lambda: pyd.now()

    wait = 250
    max_wait = 300
    debounced = pyd.debounce(func, wait, max_wait=max_wait)

    start = pyd.now()
    present = pyd.now()

    expected = debounced()

    while (present - start) <= max_wait:
        result = debounced()
        present = pyd.now()

    assert result > expected


@parametrize('func,wait,args,kargs,expected', [
    (lambda a, b, c: (a, b, c), 250, (1, 2), {'c': 3}, (1, 2, 3))
])
def test_delay(func, wait, args, kargs, expected):
    start = time.time() * 1000
    result = pyd.delay(func, wait, *args, **kargs)
    stop = time.time() * 1000

    assert (wait - 5) <= (stop - start) <= (wait + 5)
    assert result == expected


@parametrize('case,arglist,expected', [
    (lambda a: a * a, [(2,), (4,)], 4)
])
def test_once(case, arglist, expected):
    for args in arglist:
        pyd.once(case)(*args) == expected


@parametrize('case,case_args,args,expected', [
    (lambda a, b, c: a + b + c, ('a', 'b'), ('c',), 'abc')
])
def test_partial(case, case_args, args, expected):
    assert pyd.partial(case, *case_args)(*args) == expected


@parametrize('case,case_args,args,expected', [
    (lambda a, b, c: a + b + c, ('a', 'b'), ('c',), 'cab')
])
def test_partial_right(case, case_args, args, expected):
    assert pyd.partial_right(case, *case_args)(*args) == expected


def test_throttle():
    func = lambda: pyd.now()
{'fraction_non_alphanumeric': 0.19008264462809918, 'fraction_numerical': 0.02333495381623724, 'mean_word_length': 2.9337157425111537, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '7285241', 'n_tokens_mistral': 2438, 'n_tokens_neox': 2239, 'n_words': 648}