# Path: pre_commit_hooks/check_executables_have_shebangs.py
# EXECUTABLE_VALUES = frozenset(('1', '3', '5', '7'))
# def check_executables(paths: list[str]) -> int:
# def git_ls_files(paths: Sequence[str]) -> Generator[GitLsFile, None, None]:
# def _check_git_filemode(paths: Sequence[str]) -> int:
# def has_shebang(path: str) -> int:
# def _message(path: str) -> None:
# def main(argv: Sequence[str] | None = None) -> int:
# class GitLsFile(NamedTuple):
# 
# Path: pre_commit_hooks/check_executables_have_shebangs.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser(description=__doc__)
#     parser.add_argument('filenames', nargs='*')
#     args = parser.parse_args(argv)
# 
#     return check_executables(args.filenames)
# 
# Path: pre_commit_hooks/util.py
# def cmd_output(*cmd: str, retcode: int | None = 0, **kwargs: Any) -> str:
#     kwargs.setdefault('stdout', subprocess.PIPE)
#     kwargs.setdefault('stderr', subprocess.PIPE)
#     proc = subprocess.Popen(cmd, **kwargs)
#     stdout, stderr = proc.communicate()
#     stdout = stdout.decode()
#     if retcode is not None and proc.returncode != retcode:
#         raise CalledProcessError(cmd, retcode, proc.returncode, stdout, stderr)
#     return stdout


import os
import sys
import pytest
from pre_commit_hooks import check_executables_have_shebangs
from pre_commit_hooks.check_executables_have_shebangs import main
from pre_commit_hooks.util import cmd_output
from __future__ import annotations




skip_win32 = pytest.mark.skipif(
    sys.platform == 'win32',
    reason="non-git checks aren't relevant on windows",
)


@skip_win32  # pragma: win32 no cover
@pytest.mark.parametrize(
    'content', (
        b'#!/bin/bash\nhello world\n',
        b'#!/usr/bin/env python3.6',
        b'#!python',
        '#!☃'.encode(),
    ),
)
def test_has_shebang(content, tmpdir):
    path = tmpdir.join('path')
    path.write(content, 'wb')

# Path: pre_commit_hooks/check_executables_have_shebangs.py
# EXECUTABLE_VALUES = frozenset(('1', '3', '5', '7'))
# def check_executables(paths: list[str]) -> int:
# def git_ls_files(paths: Sequence[str]) -> Generator[GitLsFile, None, None]:
# def _check_git_filemode(paths: Sequence[str]) -> int:
# def has_shebang(path: str) -> int:
# def _message(path: str) -> None:
# def main(argv: Sequence[str] | None = None) -> int:
# class GitLsFile(NamedTuple):
# 
# Path: pre_commit_hooks/check_executables_have_shebangs.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser(description=__doc__)
#     parser.add_argument('filenames', nargs='*')
#     args = parser.parse_args(argv)
# 
#     return check_executables(args.filenames)
# 
# Path: pre_commit_hooks/util.py
# def cmd_output(*cmd: str, retcode: int | None = 0, **kwargs: Any) -> str:
#     kwargs.setdefault('stdout', subprocess.PIPE)
#     kwargs.setdefault('stderr', subprocess.PIPE)
#     proc = subprocess.Popen(cmd, **kwargs)
#     stdout, stderr = proc.communicate()
#     stdout = stdout.decode()
#     if retcode is not None and proc.returncode != retcode:
#         raise CalledProcessError(cmd, retcode, proc.returncode, stdout, stderr)
#     return stdout


# Path: tests/check_executables_have_shebangs_test.py
import os
import sys
import pytest
from pre_commit_hooks import check_executables_have_shebangs
from pre_commit_hooks.check_executables_have_shebangs import main
from pre_commit_hooks.util import cmd_output

from __future__ import annotations




skip_win32 = pytest.mark.skipif(
    sys.platform == 'win32',
    reason="non-git checks aren't relevant on windows",
)


@skip_win32  # pragma: win32 no cover
@pytest.mark.parametrize(
    'content', (
        b'#!/bin/bash\nhello world\n',
        b'#!/usr/bin/env python3.6',
        b'#!python',
        '#!☃'.encode(),
    ),
)
def test_has_shebang(content, tmpdir):
    path = tmpdir.join('path')
    path.write(content, 'wb')

    assert main((str(path),)) == 0