<commit_before># -*- coding: utf-8 -*-

from shipit_code_coverage import utils
import time


def do_raise():
    raise Exception('Err')


def test_wait_until():
    assert utils.wait_until(lambda: False, 1, 1) is None
    assert utils.wait_until(lambda: None, 1, 1) is None
    assert utils.wait_until(lambda: '', 1, 1) is None
    assert utils.wait_until(lambda: True, 1, 1) is not None
    assert utils.wait_until(lambda: 'Prova', 1, 1) is not None

    i = {}

    def try_twice():
        if 'tried' in i:
            return True
        else:
            i['tried'] = True
            return False

    assert utils.wait_until(try_twice, 2, 1) is not None


def test_retry():
    assert utils.retry(lambda: True)
    assert utils.retry(lambda: False)
    assert not utils.retry(do_raise)

    i = {}

    def try_twice():
        if 'tried' in i:
            return
        else:
            i['tried'] = True
            raise Exception('Please try again.')

    assert utils.retry(try_twice, wait_between_retries=0)


def test_threadpoolexecutorresult():
    with utils.ThreadPoolExecutorResult() as executor:
        executor.submit(lambda: True)
        executor.submit(lambda: False)

    try:
        with utils.ThreadPoolExecutorResult() as executor:
            executor.submit(lambda: True)
            executor.submit(do_raise)
        assert False
    except:
        assert True

    try:
        now = time.time()
        with utils.ThreadPoolExecutorResult() as executor:<commit_msg>shipit_code_coverage: Don't actually wait when testing the 'retry' function from utils #768<commit_after># -*- coding: utf-8 -*-

from shipit_code_coverage import utils
import time


def do_raise():
    raise Exception('Err')


def test_wait_until():
    assert utils.wait_until(lambda: False, 1, 1) is None
    assert utils.wait_until(lambda: None, 1, 1) is None
    assert utils.wait_until(lambda: '', 1, 1) is None
    assert utils.wait_until(lambda: True, 1, 1) is not None
    assert utils.wait_until(lambda: 'Prova', 1, 1) is not None

    i = {}

    def try_twice():
        if 'tried' in i:
            return True
        else:
            i['tried'] = True
            return False

    assert utils.wait_until(try_twice, 2, 1) is not None


def test_retry():
    assert utils.retry(lambda: True)
    assert utils.retry(lambda: False)
    assert not utils.retry(do_raise, wait_between_retries=0)

    i = {}

    def try_twice():
        if 'tried' in i:
            return
        else:
            i['tried'] = True
            raise Exception('Please try again.')

    assert utils.retry(try_twice, wait_between_retries=0)


def test_threadpoolexecutorresult():
    with utils.ThreadPoolExecutorResult() as executor:
        executor.submit(lambda: True)
        executor.submit(lambda: False)

    try:
        with utils.ThreadPoolExecutorResult() as executor:
            executor.submit(lambda: True)
            executor.submit(do_raise)
        assert False
    except:
        assert True

    try:
        now = time.time()
        with utils.ThreadPoolExecutorResult() as executor:
{'fraction_non_alphanumeric': 0.10012878300064391, 'fraction_numerical': 0.0103026400515132, 'mean_word_length': 2.471508379888268, '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': '3424378', 'n_tokens_mistral': 993, 'n_tokens_neox': 981, 'n_words': 273}