-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathtest_regressions.py
More file actions
46 lines (35 loc) · 1.46 KB
/
test_regressions.py
File metadata and controls
46 lines (35 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import sys
import pytest
from cachecontrol import CacheControl, CacheControlAdapter
from cachecontrol.caches import FileCache
from cachecontrol.filewrapper import CallbackFileWrapper
from requests import Session
class Test39(object):
@pytest.mark.skipif(sys.version.startswith('2'),
reason='Only run this for python 3.x')
def test_file_cache_recognizes_consumed_file_handle(self):
s = CacheControl(Session(), FileCache('web_cache'))
s.get('http://httpbin.org/cache/60')
r = s.get('http://httpbin.org/cache/60')
assert r.from_cache
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
def test_handle_no_chunked_attr():
class NoChunked(CacheControlAdapter):
def build_response(self, request, response, from_cache=False,
cacheable_methods=None):
if hasattr(response, 'chunked'):
pytest.skip('Requests is new enough, test makes no sense.')
# delattr(response, 'chunked')
return super().build_response(request, response, from_cache,
cacheable_methods)
sess = Session()
sess.mount('http://', NoChunked())
sess.get('http://httpbin.org/cache/60')