mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix unclosed resource warnings in fetch backend tests
This commit is contained in:
parent
d8d63646f4
commit
60555c1389
@ -102,6 +102,12 @@ class FakeResponse:
|
|||||||
def close(self):
|
def close(self):
|
||||||
self._data.close()
|
self._data.close()
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, *a):
|
||||||
|
self._data.close()
|
||||||
|
|
||||||
|
|
||||||
def shutdown_browser(bref):
|
def shutdown_browser(bref):
|
||||||
br = bref()
|
br = bref()
|
||||||
|
@ -109,10 +109,10 @@ class TestFetchBackend(unittest.TestCase):
|
|||||||
req = Request(url, headers=headers)
|
req = Request(url, headers=headers)
|
||||||
else:
|
else:
|
||||||
req = url
|
req = url
|
||||||
res = br.open(req, data=data, timeout=timeout)
|
with br.open(req, data=data, timeout=timeout) as res:
|
||||||
raw = res.read()
|
raw = res.read()
|
||||||
ans = json.loads(raw)
|
ans = json.loads(raw)
|
||||||
ans['final_url'] = res.geturl()
|
ans['final_url'] = res.geturl()
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def test_with_timeout(no_response=True):
|
def test_with_timeout(no_response=True):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user