summaryrefslogtreecommitdiffstats
path: root/tests/languages/docker_test.py
blob: 171a3f7326cf19ae08ec89953862e3f558c9911f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from unittest import mock

from pre_commit.languages import docker
from pre_commit.util import CalledProcessError


def test_docker_is_running_process_error():
    with mock.patch(
        'pre_commit.languages.docker.cmd_output_b',
        side_effect=CalledProcessError(1, (), 0, b'', None),
    ):
        assert docker.docker_is_running() is False


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() == '1000:1000'