add some tests for passing in Timeout objects
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Alexander 'Leo' Bergolth · committed by Alexander 'Leo' Bergolth · parent 4c13678 · Browse files · 1 file·+42 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+42 added−0 removed
- tests:+42 added−0 removed
Provenance
- Commit
93cb1ca- Tree
256d99b- Author
Alexander 'Leo' Bergolth <leo@strike.wu.ac.at>- Committer
Alexander 'Leo' Bergolth <leo@strike.wu.ac.at>- Parent
4c13678
1 file changed+42 added−0 removed
modified:tests/test_requests.py+42 added
2023 unmodified lines2024 """2025 r = requests.get(httpbin('get'), timeout=None)2026 assert r.status_code == 2002027 2028+ def test_none_timeout_obj(self, httpbin):2029+ """Check that you can set None as a valid timeout value.2030+2031+ To actually test this behavior, we'd want to check that setting the2032+ timeout to None actually lets the request block forever. However, this2033+ would make the test suite unbearably slow.2034+ Instead we verify that setting the timeout to None does not prevent the2035+ request from succeeding.2036+ """2037+ from requests.packages.urllib3.util import Timeout2038+ r = requests.get(httpbin('get'),2039+ timeout=Timeout(connect=None, read=None))2040+ assert r.status_code == 2002041+2042 def test_read_timeout(self, httpbin):2043 try:2044 requests.get(httpbin('delay/10'), timeout=(None, 0.1))2045 pytest.fail('The recv() request should time out.')2046 except ReadTimeout:2047 pass2048 2049+ def test_read_timeout_obj(self, httpbin):2050+ from requests.packages.urllib3.util import Timeout2051+ try:2052+ requests.get(httpbin('delay/10'),2053+ timeout=Timeout(connect=None, read=0.1))2054+ pytest.fail('The recv() request should time out.')2055+ except ReadTimeout:2056+ pass2057+2058 def test_connect_timeout(self):2059 try:2060 requests.get(TARPIT, timeout=(0.1, None))2061 pytest.fail('The connect() request should time out.')2062 except ConnectTimeout as e:2063 assert isinstance(e, ConnectionError)2064 assert isinstance(e, Timeout)2065 2066+ def test_connect_timeout_obj(self):2067+ from requests.packages.urllib3.util import Timeout2068+ try:2069+ requests.get(TARPIT,2070+ timeout=Timeout(connect=0.1, read=None))2071+ pytest.fail('The connect() request should time out.')2072+ except ConnectTimeout as e:2073+ assert isinstance(e, ConnectionError)2074+ assert isinstance(e, Timeout)2075+2076 def test_total_timeout_connect(self):2077 try:2078 requests.get(TARPIT, timeout=(0.1, 0.1))2079 pytest.fail('The connect() request should time out.')2080 except ConnectTimeout:2081 pass2082 2083+ def test_total_timeout_connect_obj(self):2084+ from requests.packages.urllib3.util import Timeout2085+ try:2086+ requests.get(TARPIT,2087+ timeout=Timeout(connect=0.1, read=0.1))2088+ pytest.fail('The connect() request should time out.')2089+ except ConnectTimeout:2090+ pass2091+2092 def test_encoded_methods(self, httpbin):2093 """See: https://github.com/kennethreitz/requests/issues/2316"""2094 r = requests.request(b'GET', httpbin('get'))2095 assert r.ok301 unmodified lines