<commit_before>import tempfile

import pytest

from ..util import split, _get_fn

def test_split_empty():
    '''
    An error should be raised when you try to split an empty path.
    '''
    with pytest.raises(ValueError):
        split('')

testcases_split = [
    ('/', ('/',)),
    ('/abc', ('/', 'abc',)),
    ('123/abc', ('123', 'abc',)),
]

@pytest.mark.parametrize('path,expected', testcases_split)
def test_split(path, expected):
    assert split(path) == expected

def test_get_fn_success():
    with tempfile.NamedTemporaryFile('w') as tmp:
        tmp.file.write('abc')
        tmp.file.close()
        assert 'abc' == _get_fn(tmp.name, 'r', lambda fp: fp.read())

def test_get_fn_fail():
    def f(fp):
        with open(fp.name, 'w') as fp2:
            fp2.write('other-process')
        return fp.read()
<commit_msg>test _get_fn<commit_after>import tempfile, time

import pytest

from ..util import split, _get_fn

def test_split_empty():
    '''
    An error should be raised when you try to split an empty path.
    '''
    with pytest.raises(ValueError):
        split('')

testcases_split = [
    ('/', ('/',)),
    ('/abc', ('/', 'abc',)),
    ('123/abc', ('123', 'abc',)),
]

@pytest.mark.parametrize('path,expected', testcases_split)
def test_split(path, expected):
    assert split(path) == expected

def test_get_fn_success():
    with tempfile.NamedTemporaryFile('w') as tmp:
        tmp.file.write('abc')
        tmp.file.close()
        assert 'abc' == _get_fn(tmp.name, 'r', lambda fp: fp.read())

def test_get_fn_fail():
    def f(fp):
        time.sleep(0.1) # so mtime changes
        with open(fp.name, 'w') as fp2:
            fp2.write('other-process')
        return fp.read()

{'fraction_non_alphanumeric': 0.17152858809801633, 'fraction_numerical': 0.010501750291715286, 'mean_word_length': 2.9699074074074074, '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': '3186914', 'n_tokens_mistral': 604, 'n_tokens_neox': 597, 'n_words': 142}