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) == ()
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)
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', )
def test_parse_shebang_from_file_does_not_exist(): with pytest.raises(ValueError): identify.parse_shebang_from_file('herp derp derp')
def parse_filename(filename: str) -> Tuple[str, ...]: if not os.path.exists(filename): return () else: return parse_shebang_from_file(filename)