add lru_cache to docker_is_running

This commit is contained in:
Ruairidh MacLeod 2020-08-22 21:44:49 +00:00
parent f1de792877
commit b34b1a0ab3
2 changed files with 3 additions and 0 deletions

View file

@ -1,3 +1,4 @@
import functools
import hashlib
import os
from typing import Sequence
@ -26,6 +27,7 @@ def docker_tag(prefix: Prefix) -> str: # pragma: win32 no cover
return f'pre-commit-{md5sum}'
@functools.lru_cache(maxsize=1)
def docker_is_running() -> bool: # pragma: win32 no cover
try:
cmd_output_b('docker', 'ps')

View file

@ -5,6 +5,7 @@ from pre_commit.util import CalledProcessError
def test_docker_is_running_process_error():
docker.docker_is_running.cache_clear()
with mock.patch(
'pre_commit.languages.docker.cmd_output_b',
side_effect=CalledProcessError(1, (), 0, b'', None),