try:
    from unittest.mock import patch
except ImportError:  # pragma: no cover
    from mock import patch

from proofreader.runner import run, _run_command


def test_it_will_return_1_exit_code_on_failure(bad_py_file):
    try:
        run(targets=[bad_py_file.strpath])
    except SystemExit as exception:
        assert exception.code == 1


def test_it_will_return_zero_exit_code_on_success(good_py_file):
    try:
        run(targets=[good_py_file.strpath])
    except SystemExit as exception:
        assert exception.code == 0


def test_it_returns_zero_exit_code_on_builtin_shadowing_fail(builtin_fail_py_file):
    try:
        run(targets=[builtin_fail_py_file.strpath])
    except SystemExit as exception:
        assert exception.code == 0


def test_run_command_will_return_a_bool():
    with patch('proofreader.runner.Popen') as mock_popen:
        mock_popen.returncode = 0
        result = _run_command('dummy_cmd', [''], [''])
        assert isinstance(result, bool)


def test_will_return_zero_on_success_with_license_check(good_py_file):
    try:
        run(targets=[good_py_file.strpath], check_licenses=True)
    except SystemExit as exception:
        assert exception.code == 0

[((11, 8, 11, 42), 'proofreader.runner.run', 'run', (), '', False, 'from proofreader.runner import run, _run_command\n'), ((18, 8, 18, 43), 'proofreader.runner.run', 'run', (), '', False, 'from proofreader.runner import run, _run_command\n'), ((25, 8, 25, 51), 'proofreader.runner.run', 'run', (), '', False, 'from proofreader.runner import run, _run_command\n'), ((31, 9, 31, 42), 'mock.patch', 'patch', ({(31, 15, 31, 41): '"""proofreader.runner.Popen"""'}, {}), "('proofreader.runner.Popen')", False, 'from mock import patch\n'), ((33, 17, 33, 54), 'proofreader.runner._run_command', '_run_command', ({(33, 30, 33, 41): '"""dummy_cmd"""', (33, 43, 33, 47): "['']", (33, 49, 33, 53): "['']"}, {}), "('dummy_cmd', [''], [''])", False, 'from proofreader.runner import run, _run_command\n'), ((39, 8, 39, 64), 'proofreader.runner.run', 'run', (), '', False, 'from proofreader.runner import run, _run_command\n')]