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

from os.path import curdir, devnull
from subprocess import check_call

from pytest import fixture, mark, raises

from csft import __main__ as main


@fixture
def null():
    with open(devnull, 'w') as fobj:
        yield fobj


def test_call(null):
    check_call(['python', '-m', 'csft', 'csft'], stdout=null, stderr=null)


@mark.parametrize('argv', [None, [], ['csft'], ])
def test_main(argv, mocker):
    obj = object()
    mocker.patch('sys.argv', ['csft'])
    csft2data = mocker.patch('csft.__main__.csft2data', return_value=obj)
    pr = mocker.patch('builtins.print')
    assert 0 == main.main(argv=argv)
    if argv:
        csft2data.assert_called_once_with(main._dir(argv[0]))
    else:
        csft2data.assert_called_once_with(main._dir(curdir))
    pr.assert_called_once_with(obj)


def test_wrong_path(capsys):
    with raises(SystemExit):
        main.main(argv=['path/is/not/a/directory'])
    assert capsys.readouterr()


def test_show_version(capsys):
    try:
        main.main(argv=['-V'])
    except SystemExit as err:
        assert 0 == err.code

    from csft import __version__
    assert __version__ == capsys.readouterr().out.strip()<commit_msg>Fix compatible error about capsys.<commit_after># -*- coding:utf-8 -*-

from os.path import curdir, devnull
from subprocess import check_call

from pytest import fixture, mark, raises

from csft import __main__ as main


@fixture
def null():
    with open(devnull, 'w') as fobj:
        yield fobj


def test_call(null):
    check_call(['python', '-m', 'csft', 'csft'], stdout=null, stderr=null)


@mark.parametrize('argv', [None, [], ['csft'], ])
def test_main(argv, mocker):
    obj = object()
    mocker.patch('sys.argv', ['csft'])
    csft2data = mocker.patch('csft.__main__.csft2data', return_value=obj)
    pr = mocker.patch('builtins.print')
    assert 0 == main.main(argv=argv)
    if argv:
        csft2data.assert_called_once_with(main._dir(argv[0]))
    else:
        csft2data.assert_called_once_with(main._dir(curdir))
    pr.assert_called_once_with(obj)


def test_wrong_path(capsys):
    with raises(SystemExit):
        main.main(argv=['path/is/not/a/directory'])
    assert capsys.readouterr()


def test_show_version(capsys):
    try:
        main.main(argv=['-V'])
    except SystemExit as err:
        assert 0 == err.code

    from csft import __version__
    out = capsys.readouterr()[0]
    assert __version__ == out.strip()
{'fraction_non_alphanumeric': 0.14268292682926828, 'fraction_numerical': 0.006910569105691057, 'mean_word_length': 3.6609848484848486, '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': '613247', 'n_tokens_mistral': 874, 'n_tokens_neox': 857, 'n_words': 185}