Issue #134: use requests.get as a context manager
This commit is contained in:
@ -29,8 +29,7 @@ def execute(path, *args, **kwargs):
|
|||||||
raise ValueError('download command currently supports examples only')
|
raise ValueError('download command currently supports examples only')
|
||||||
examples_path = re.sub('^examples/', '', path)
|
examples_path = re.sub('^examples/', '', path)
|
||||||
output_path = bonobo.get_examples_path(examples_path)
|
output_path = bonobo.get_examples_path(examples_path)
|
||||||
response = _open_url(EXAMPLES_BASE_URL + examples_path)
|
with _open_url(EXAMPLES_BASE_URL + examples_path) as response, open(output_path, 'wb') as fout:
|
||||||
with open(output_path, 'wb') as fout:
|
|
||||||
_write_response(response, fout)
|
_write_response(response, fout)
|
||||||
print('saved to {}'.format(output_path))
|
print('saved to {}'.format(output_path))
|
||||||
|
|
||||||
|
|||||||
@ -164,6 +164,12 @@ def test_download_works_for_examples(runner):
|
|||||||
def iter_content(self, *args, **kwargs):
|
def iter_content(self, *args, **kwargs):
|
||||||
return [expected_bytes]
|
return [expected_bytes]
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
fout = io.BytesIO()
|
fout = io.BytesIO()
|
||||||
fout.close = lambda: None
|
fout.close = lambda: None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user