Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cachecontrol/filewrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,9 @@ def _safe_read(self, amt: int) -> bytes:
self._close()

return data

def close(self) -> None:
try:
self.__fp.close()
finally:
self.__buf.close()
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ module = "msgpack"
ignore_missing_imports = true

[tool.pytest.ini_options]
addopts = "--strict-markers --strict-config"
norecursedirs = ["bin", "lib", "include", "build"]
filterwarnings = ["error"]
7 changes: 3 additions & 4 deletions tests/test_chunked_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def test_stream_is_cached(self, url, sess):
assert content_1 == content_2

def test_stream_is_not_cached_when_content_is_not_read(self, url, sess):
sess.get(url + "stream", stream=True)
resp = sess.get(url + "stream", stream=True)

assert not resp.from_cache
with sess.get(url + "stream", stream=True):
with sess.get(url + "stream", stream=True) as resp:
assert not resp.from_cache
17 changes: 9 additions & 8 deletions tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ def test_file_cache_recognizes_consumed_file_handle(self, url):

def test_getattr_during_gc():
s = CallbackFileWrapper(None, None)
# normal behavior:
with pytest.raises(AttributeError):
s.x

# this previously had caused an infinite recursion
vars(s).clear() # gc does this.
with pytest.raises(AttributeError):
s.x
with s._CallbackFileWrapper__buf:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems NamedTemporaryFile only issues a ResourceWarning on windows python/cpython#126639

# normal behavior:
with pytest.raises(AttributeError):
s.x

# this previously had caused an infinite recursion
vars(s).clear() # gc does this.
with pytest.raises(AttributeError):
s.x
Loading