# Path: pre_commit/languages/docker.py
# ENVIRONMENT_DIR = 'docker'
# PRE_COMMIT_LABEL = 'PRE_COMMIT'
# def _is_in_docker() -> bool:
# def _get_container_id() -> str:
# def _get_docker_path(path: str) -> str:
# def md5(s: str) -> str:  # pragma: win32 no cover
# def docker_tag(prefix: Prefix) -> str:  # pragma: win32 no cover
# def build_docker_image(
#         prefix: Prefix,
#         *,
#         pull: bool,
# ) -> None:  # pragma: win32 no cover
# def install_environment(
#         prefix: Prefix, version: str, additional_dependencies: Sequence[str],
# ) -> None:  # pragma: win32 no cover
# def get_docker_user() -> tuple[str, ...]:  # pragma: win32 no cover
# def docker_cmd() -> tuple[str, ...]:  # pragma: win32 no cover
# def run_hook(
#         hook: Hook,
#         file_args: Sequence[str],
#         color: bool,
# ) -> tuple[int, bytes]:  # pragma: win32 no cover
# 
# 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()


import builtins
import json
import ntpath
import os.path
import posixpath
import pytest
from unittest import mock
from pre_commit.languages import docker
from pre_commit.util import CalledProcessError

# The ID should match the above cgroup example.
CONTAINER_ID = 'c33988ec7651ebc867cb24755eaf637a6734088bc7eef59d5799293a9e5450f7'  # noqa: E501

NON_DOCKER_CGROUP_EXAMPLE = b'''\
12:perf_event:/
11:hugetlb:/
10:devices:/
9:blkio:/
8:rdma:/
7:cpuset:/
6:cpu,cpuacct:/
5:freezer:/
4:memory:/
3:pids:/
2:net_cls,net_prio:/
1:name=systemd:/init.scope
0::/init.scope
'''


def test_docker_fallback_user():
    def invalid_attribute():
        raise AttributeError

    with mock.patch.multiple(
            'os', create=True,
            getuid=invalid_attribute,
            getgid=invalid_attribute,
    ):

# Path: pre_commit/languages/docker.py
# ENVIRONMENT_DIR = 'docker'
# PRE_COMMIT_LABEL = 'PRE_COMMIT'
# def _is_in_docker() -> bool:
# def _get_container_id() -> str:
# def _get_docker_path(path: str) -> str:
# def md5(s: str) -> str:  # pragma: win32 no cover
# def docker_tag(prefix: Prefix) -> str:  # pragma: win32 no cover
# def build_docker_image(
#         prefix: Prefix,
#         *,
#         pull: bool,
# ) -> None:  # pragma: win32 no cover
# def install_environment(
#         prefix: Prefix, version: str, additional_dependencies: Sequence[str],
# ) -> None:  # pragma: win32 no cover
# def get_docker_user() -> tuple[str, ...]:  # pragma: win32 no cover
# def docker_cmd() -> tuple[str, ...]:  # pragma: win32 no cover
# def run_hook(
#         hook: Hook,
#         file_args: Sequence[str],
#         color: bool,
# ) -> tuple[int, bytes]:  # pragma: win32 no cover
# 
# 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: tests/languages/docker_test.py
import builtins
import json
import ntpath
import os.path
import posixpath
import pytest
from unittest import mock
from pre_commit.languages import docker
from pre_commit.util import CalledProcessError


# The ID should match the above cgroup example.
CONTAINER_ID = 'c33988ec7651ebc867cb24755eaf637a6734088bc7eef59d5799293a9e5450f7'  # noqa: E501

NON_DOCKER_CGROUP_EXAMPLE = b'''\
12:perf_event:/
11:hugetlb:/
10:devices:/
9:blkio:/
8:rdma:/
7:cpuset:/
6:cpu,cpuacct:/
5:freezer:/
4:memory:/
3:pids:/
2:net_cls,net_prio:/
1:name=systemd:/init.scope
0::/init.scope
'''


def test_docker_fallback_user():
    def invalid_attribute():
        raise AttributeError

    with mock.patch.multiple(
            'os', create=True,
            getuid=invalid_attribute,
            getgid=invalid_attribute,
    ):

        assert docker.get_docker_user() == ()