Exemple #1
0
def test_parse_shebang_open_raises_einval(tmpdir):
    x = tmpdir.join('f')
    x.write('#!/usr/bin/env not-expected\n')
    make_executable(x)
    error = OSError(errno.EINVAL, f'Invalid argument {x}')
    with mock.patch.object(builtins, 'open', side_effect=error):
        assert identify.parse_shebang_from_file(x.strpath) == ()
Exemple #2
0
def language_for(path):
    if os.access(path, os.X_OK):
        return identify.parse_shebang_from_file(path)[0]
    try:
        return RUNNER_TO_LANGUAGE[path.name](path)
    except subprocess.CalledProcessError:
        return "unknown"
def parse_filename(filename):
    if not os.path.exists(filename):
        return ()
    else:
        return parse_shebang_from_file(filename)
Exemple #4
0
def test_parse_shebang_from_file_simple(tmpdir):
    x = tmpdir.join('f')
    x.write_text('#!/usr/bin/env python', encoding='UTF-8')
    make_executable(x.strpath)
    assert identify.parse_shebang_from_file(x.strpath) == ('python', )
Exemple #5
0
def test_parse_shebang_from_file_does_not_exist():
    with pytest.raises(ValueError):
        identify.parse_shebang_from_file('herp derp derp')
Exemple #6
0
def parse_filename(filename):
    if not os.path.exists(filename):
        return ()
    else:
        return parse_shebang_from_file(filename)
def parse_filename(filename: str) -> Tuple[str, ...]:
    if not os.path.exists(filename):
        return ()
    else:
        return parse_shebang_from_file(filename)