# Path: pre_commit/parse_shebang.py
# class ExecutableNotFoundError(OSError):
#     def to_output(self) -> tuple[int, bytes, None]:
# def parse_filename(filename: str) -> tuple[str, ...]:
# def find_executable(
#         exe: str, _environ: Mapping[str, str] | None = None,
# ) -> str | None:
# def normexe(orig: str) -> str:
#     def _error(msg: str) -> NoReturn:
# def normalize_cmd(cmd: tuple[str, ...]) -> tuple[str, ...]:
# 
# Path: pre_commit/util.py
# class CalledProcessError(RuntimeError):
#     def __init__(
#             self,
#             returncode: int,
#             cmd: tuple[str, ...],
#             expected_returncode: int,
#             stdout: bytes,
#             stderr: bytes | None,
#     ) -> None:
#         super().__init__(returncode, cmd, expected_returncode, stdout, stderr)
#         self.returncode = returncode
#         self.cmd = cmd
#         self.expected_returncode = expected_returncode
#         self.stdout = stdout
#         self.stderr = stderr
# 
#     def __bytes__(self) -> bytes:
#         def _indent_or_none(part: bytes | None) -> bytes:
#             if part:
#                 return b'\n    ' + part.replace(b'\n', b'\n    ')
#             else:
#                 return b' (none)'
# 
#         return b''.join((
#             f'command: {self.cmd!r}\n'.encode(),
#             f'return code: {self.returncode}\n'.encode(),
#             f'expected return code: {self.expected_returncode}\n'.encode(),
#             b'stdout:', _indent_or_none(self.stdout), b'\n',
#             b'stderr:', _indent_or_none(self.stderr),
#         ))
# 
#     def __str__(self) -> str:
#         return self.__bytes__().decode()
# 
# Path: pre_commit/util.py
# def cmd_output(*cmd: str, **kwargs: Any) -> tuple[int, str, str | None]:
#     returncode, stdout_b, stderr_b = cmd_output_b(*cmd, **kwargs)
#     stdout = stdout_b.decode() if stdout_b is not None else None
#     stderr = stderr_b.decode() if stderr_b is not None else None
#     return returncode, stdout, stderr
# 
# Path: pre_commit/util.py
# def cmd_output_b(
#         *cmd: str,
#         retcode: int | None = 0,
#         **kwargs: Any,
# ) -> tuple[int, bytes, bytes | None]:
#     _setdefault_kwargs(kwargs)
# 
#     try:
#         cmd = parse_shebang.normalize_cmd(cmd)
#     except parse_shebang.ExecutableNotFoundError as e:
#         returncode, stdout_b, stderr_b = e.to_output()
#     else:
#         try:
#             proc = subprocess.Popen(cmd, **kwargs)
#         except OSError as e:
#             returncode, stdout_b, stderr_b = _oserror_to_output(e)
#         else:
#             stdout_b, stderr_b = proc.communicate()
#             returncode = proc.returncode
# 
#     if retcode is not None and retcode != returncode:
#         raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
# 
#     return returncode, stdout_b, stderr_b
# 
# Path: testing/auto_namedtuple.py
# def auto_namedtuple(classname='auto_namedtuple', **kwargs):
#     """Returns an automatic namedtuple object.
# 
#     Args:
#         classname - The class name for the returned object.
#         **kwargs - Properties to give the returned object.
#     """
#     return (collections.namedtuple(classname, kwargs.keys())(**kwargs))


import contextlib
import os.path
import subprocess
import pytest
from pre_commit import parse_shebang
from pre_commit.util import CalledProcessError
from pre_commit.util import cmd_output
from pre_commit.util import cmd_output_b
from testing.auto_namedtuple import auto_namedtuple
from __future__ import annotations





TESTING_DIR = os.path.abspath(os.path.dirname(__file__))


def docker_is_running() -> bool:  # pragma: win32 no cover
    try:
        cmd_output_b('docker', 'ps')

# Path: pre_commit/parse_shebang.py
# class ExecutableNotFoundError(OSError):
#     def to_output(self) -> tuple[int, bytes, None]:
# def parse_filename(filename: str) -> tuple[str, ...]:
# def find_executable(
#         exe: str, _environ: Mapping[str, str] | None = None,
# ) -> str | None:
# def normexe(orig: str) -> str:
#     def _error(msg: str) -> NoReturn:
# def normalize_cmd(cmd: tuple[str, ...]) -> tuple[str, ...]:
# 
# Path: pre_commit/util.py
# class CalledProcessError(RuntimeError):
#     def __init__(
#             self,
#             returncode: int,
#             cmd: tuple[str, ...],
#             expected_returncode: int,
#             stdout: bytes,
#             stderr: bytes | None,
#     ) -> None:
#         super().__init__(returncode, cmd, expected_returncode, stdout, stderr)
#         self.returncode = returncode
#         self.cmd = cmd
#         self.expected_returncode = expected_returncode
#         self.stdout = stdout
#         self.stderr = stderr
# 
#     def __bytes__(self) -> bytes:
#         def _indent_or_none(part: bytes | None) -> bytes:
#             if part:
#                 return b'\n    ' + part.replace(b'\n', b'\n    ')
#             else:
#                 return b' (none)'
# 
#         return b''.join((
#             f'command: {self.cmd!r}\n'.encode(),
#             f'return code: {self.returncode}\n'.encode(),
#             f'expected return code: {self.expected_returncode}\n'.encode(),
#             b'stdout:', _indent_or_none(self.stdout), b'\n',
#             b'stderr:', _indent_or_none(self.stderr),
#         ))
# 
#     def __str__(self) -> str:
#         return self.__bytes__().decode()
# 
# Path: pre_commit/util.py
# def cmd_output(*cmd: str, **kwargs: Any) -> tuple[int, str, str | None]:
#     returncode, stdout_b, stderr_b = cmd_output_b(*cmd, **kwargs)
#     stdout = stdout_b.decode() if stdout_b is not None else None
#     stderr = stderr_b.decode() if stderr_b is not None else None
#     return returncode, stdout, stderr
# 
# Path: pre_commit/util.py
# def cmd_output_b(
#         *cmd: str,
#         retcode: int | None = 0,
#         **kwargs: Any,
# ) -> tuple[int, bytes, bytes | None]:
#     _setdefault_kwargs(kwargs)
# 
#     try:
#         cmd = parse_shebang.normalize_cmd(cmd)
#     except parse_shebang.ExecutableNotFoundError as e:
#         returncode, stdout_b, stderr_b = e.to_output()
#     else:
#         try:
#             proc = subprocess.Popen(cmd, **kwargs)
#         except OSError as e:
#             returncode, stdout_b, stderr_b = _oserror_to_output(e)
#         else:
#             stdout_b, stderr_b = proc.communicate()
#             returncode = proc.returncode
# 
#     if retcode is not None and retcode != returncode:
#         raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
# 
#     return returncode, stdout_b, stderr_b
# 
# Path: testing/auto_namedtuple.py
# def auto_namedtuple(classname='auto_namedtuple', **kwargs):
#     """Returns an automatic namedtuple object.
# 
#     Args:
#         classname - The class name for the returned object.
#         **kwargs - Properties to give the returned object.
#     """
#     return (collections.namedtuple(classname, kwargs.keys())(**kwargs))


# Path: testing/util.py
import contextlib
import os.path
import subprocess
import pytest
from pre_commit import parse_shebang
from pre_commit.util import CalledProcessError
from pre_commit.util import cmd_output
from pre_commit.util import cmd_output_b
from testing.auto_namedtuple import auto_namedtuple

from __future__ import annotations





TESTING_DIR = os.path.abspath(os.path.dirname(__file__))


def docker_is_running() -> bool:  # pragma: win32 no cover
    try:
        cmd_output_b('docker', 'ps')

    except CalledProcessError:  # pragma: no cover