mirror of
https://github.com/httpie/cli.git
synced 2024-11-21 23:33:12 +01:00
Fix several ResourceWarning: unclosed file (#741)
Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
This commit is contained in:
parent
b7c8bf0800
commit
3a46149de1
@ -752,7 +752,7 @@ def parse_items(items,
|
||||
|
||||
def readable_file_arg(filename):
|
||||
try:
|
||||
open(filename, 'rb')
|
||||
with open(filename, 'rb'):
|
||||
return filename
|
||||
except IOError as ex:
|
||||
raise ArgumentTypeError('%s: %s' % (filename, ex.args[1]))
|
||||
return filename
|
||||
|
@ -131,35 +131,38 @@ class TestDownloads:
|
||||
assert body == r
|
||||
|
||||
def test_download_with_Content_Length(self, httpbin_both):
|
||||
devnull = open(os.devnull, 'w')
|
||||
downloader = Downloader(output_file=devnull, progress_file=devnull)
|
||||
downloader.start(Response(
|
||||
url=httpbin_both.url + '/',
|
||||
headers={'Content-Length': 10}
|
||||
))
|
||||
time.sleep(1.1)
|
||||
downloader.chunk_downloaded(b'12345')
|
||||
time.sleep(1.1)
|
||||
downloader.chunk_downloaded(b'12345')
|
||||
downloader.finish()
|
||||
assert not downloader.interrupted
|
||||
with open(os.devnull, 'w') as devnull:
|
||||
downloader = Downloader(output_file=devnull, progress_file=devnull)
|
||||
downloader.start(Response(
|
||||
url=httpbin_both.url + '/',
|
||||
headers={'Content-Length': 10}
|
||||
))
|
||||
time.sleep(1.1)
|
||||
downloader.chunk_downloaded(b'12345')
|
||||
time.sleep(1.1)
|
||||
downloader.chunk_downloaded(b'12345')
|
||||
downloader.finish()
|
||||
assert not downloader.interrupted
|
||||
downloader._progress_reporter.join()
|
||||
|
||||
def test_download_no_Content_Length(self, httpbin_both):
|
||||
devnull = open(os.devnull, 'w')
|
||||
downloader = Downloader(output_file=devnull, progress_file=devnull)
|
||||
downloader.start(Response(url=httpbin_both.url + '/'))
|
||||
time.sleep(1.1)
|
||||
downloader.chunk_downloaded(b'12345')
|
||||
downloader.finish()
|
||||
assert not downloader.interrupted
|
||||
with open(os.devnull, 'w') as devnull:
|
||||
downloader = Downloader(output_file=devnull, progress_file=devnull)
|
||||
downloader.start(Response(url=httpbin_both.url + '/'))
|
||||
time.sleep(1.1)
|
||||
downloader.chunk_downloaded(b'12345')
|
||||
downloader.finish()
|
||||
assert not downloader.interrupted
|
||||
downloader._progress_reporter.join()
|
||||
|
||||
def test_download_interrupted(self, httpbin_both):
|
||||
devnull = open(os.devnull, 'w')
|
||||
downloader = Downloader(output_file=devnull, progress_file=devnull)
|
||||
downloader.start(Response(
|
||||
url=httpbin_both.url + '/',
|
||||
headers={'Content-Length': 5}
|
||||
))
|
||||
downloader.chunk_downloaded(b'1234')
|
||||
downloader.finish()
|
||||
assert downloader.interrupted
|
||||
with open(os.devnull, 'w') as devnull:
|
||||
downloader = Downloader(output_file=devnull, progress_file=devnull)
|
||||
downloader.start(Response(
|
||||
url=httpbin_both.url + '/',
|
||||
headers={'Content-Length': 5}
|
||||
))
|
||||
downloader.chunk_downloaded(b'1234')
|
||||
downloader.finish()
|
||||
assert downloader.interrupted
|
||||
downloader._progress_reporter.join()
|
||||
|
@ -62,6 +62,8 @@ class MockEnvironment(Environment):
|
||||
return super(MockEnvironment, self).config
|
||||
|
||||
def cleanup(self):
|
||||
self.stdout.close()
|
||||
self.stderr.close()
|
||||
if self._delete_config_dir:
|
||||
assert self.config_dir.startswith(tempfile.gettempdir())
|
||||
from shutil import rmtree
|
||||
|
Loading…
Reference in New Issue
Block a user