mirror of https://github.com/docker/docker-py.git
fix(store): warn on init instead of throw (#3080)
Signed-off-by: yanlong.wang <yanlong.wang@naiver.org>
This commit is contained in:
parent
d38b41a13c
commit
22718ba59a
|
|
@ -2,6 +2,7 @@ import errno
|
||||||
import json
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import warnings
|
||||||
|
|
||||||
from . import constants
|
from . import constants
|
||||||
from . import errors
|
from . import errors
|
||||||
|
|
@ -18,7 +19,7 @@ class Store:
|
||||||
self.exe = shutil.which(self.program)
|
self.exe = shutil.which(self.program)
|
||||||
self.environment = environment
|
self.environment = environment
|
||||||
if self.exe is None:
|
if self.exe is None:
|
||||||
raise errors.InitializationError(
|
warnings.warn(
|
||||||
'{} not installed or not available in PATH'.format(
|
'{} not installed or not available in PATH'.format(
|
||||||
self.program
|
self.program
|
||||||
)
|
)
|
||||||
|
|
@ -70,6 +71,12 @@ class Store:
|
||||||
return json.loads(data.decode('utf-8'))
|
return json.loads(data.decode('utf-8'))
|
||||||
|
|
||||||
def _execute(self, subcmd, data_input):
|
def _execute(self, subcmd, data_input):
|
||||||
|
if self.exe is None:
|
||||||
|
raise errors.StoreError(
|
||||||
|
'{} not installed or not available in PATH'.format(
|
||||||
|
self.program
|
||||||
|
)
|
||||||
|
)
|
||||||
output = None
|
output = None
|
||||||
env = create_environment_dict(self.environment)
|
env = create_environment_dict(self.environment)
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -84,3 +84,10 @@ class TestStore:
|
||||||
data = self.store._execute('--null', '')
|
data = self.store._execute('--null', '')
|
||||||
assert b'\0FOO=bar\0' in data
|
assert b'\0FOO=bar\0' in data
|
||||||
assert 'FOO' not in os.environ
|
assert 'FOO' not in os.environ
|
||||||
|
|
||||||
|
def test_unavailable_store(self):
|
||||||
|
some_unavailable_store = None
|
||||||
|
with pytest.warns(UserWarning):
|
||||||
|
some_unavailable_store = Store('that-does-not-exist')
|
||||||
|
with pytest.raises(StoreError):
|
||||||
|
some_unavailable_store.get('anything-this-does-not-matter')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue