Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove unneeded new lines after with statements #1702

Merged
merged 1 commit into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 0 additions & 8 deletions test/contrib/test_socks.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ def request_handler(listener):
self._start_server(request_handler)
proxy_url = "socks5h://%s:%s" % (self.host, self.port)
with socks.SOCKSProxyManager(proxy_url) as pm:

with pytest.raises(ConnectTimeoutError):
pm.request("GET", "http://example.com", timeout=0.001, retries=False)
event.set()
Expand All @@ -328,7 +327,6 @@ def request_handler(listener):
self._start_server(request_handler)
proxy_url = "socks5h://%s:%s" % (self.host, self.port)
with socks.SOCKSProxyManager(proxy_url) as pm:

event.wait()
with pytest.raises(NewConnectionError):
pm.request("GET", "http://example.com", retries=False)
Expand All @@ -349,7 +347,6 @@ def request_handler(listener):
self._start_server(request_handler)
proxy_url = "socks5h://%s:%s" % (self.host, self.port)
with socks.SOCKSProxyManager(proxy_url) as pm:

with pytest.raises(NewConnectionError):
pm.request("GET", "http://example.com", retries=False)
evt.set()
Expand Down Expand Up @@ -383,7 +380,6 @@ def request_handler(listener):
self._start_server(request_handler)
proxy_url = "socks5://%s:%s" % (self.host, self.port)
with socks.SOCKSProxyManager(proxy_url, username="user", password="pass") as pm:

response = pm.request("GET", "http://16.17.18.19")

assert response.status == 200
Expand Down Expand Up @@ -424,7 +420,6 @@ def request_handler(listener):
self._start_server(request_handler)
proxy_url = "socks5://user:pass@%s:%s" % (self.host, self.port)
with socks.SOCKSProxyManager(proxy_url) as pm:

response = pm.request("GET", "http://16.17.18.19")

assert response.status == 200
Expand All @@ -445,7 +440,6 @@ def request_handler(listener):
with socks.SOCKSProxyManager(
proxy_url, username="user", password="badpass"
) as pm:

try:
pm.request("GET", "http://example.com", retries=False)
except NewConnectionError as e:
Expand Down Expand Up @@ -614,7 +608,6 @@ def request_handler(listener):
self._start_server(request_handler)
proxy_url = "socks4a://%s:%s" % (self.host, self.port)
with socks.SOCKSProxyManager(proxy_url) as pm:

with pytest.raises(NewConnectionError):
pm.request("GET", "http://example.com", retries=False)
evt.set()
Expand Down Expand Up @@ -662,7 +655,6 @@ def request_handler(listener):
self._start_server(request_handler)
proxy_url = "socks4a://%s:%s" % (self.host, self.port)
with socks.SOCKSProxyManager(proxy_url, username="baduser") as pm:

try:
pm.request("GET", "http://example.com", retries=False)
except NewConnectionError as e:
Expand Down
1 change: 0 additions & 1 deletion test/test_connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ def __call__(self, *args, **kwargs):

def _test(exception):
with HTTPConnectionPool(host="localhost", maxsize=1, block=True) as pool:

# Verify that the request succeeds after two attempts, and that the
# connection is left on the response object, instead of being
# released back into the pool.
Expand Down
1 change: 0 additions & 1 deletion test/test_proxymanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class TestProxyManager(object):
def test_proxy_headers(self):
url = "http://pypi.org/project/urllib3/"
with ProxyManager("http://something:1234") as p:

# Verify default headers
default_headers = {"Accept": "*/*", "Host": "pypi.org"}
headers = p._set_proxy_headers(url)
Expand Down
1 change: 0 additions & 1 deletion test/with_dummyserver/test_chunked_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def test_chunks(self):
def _test_body(self, data):
self.start_chunked_handler()
with HTTPConnectionPool(self.host, self.port, retries=False) as pool:

pool.urlopen("GET", "/", data, chunked=True)
header, body = self.buffer.split(b"\r\n\r\n", 1)

Expand Down
4 changes: 0 additions & 4 deletions test/with_dummyserver/test_connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def test_timeout(self):
with HTTPConnectionPool(
self.host, self.port, timeout=timeout, retries=False
) as pool:

wait_for_socket(ready_event)
conn = pool._get_conn()
with pytest.raises(ReadTimeoutError):
Expand All @@ -112,7 +111,6 @@ def test_timeout(self):
with HTTPConnectionPool(
self.host, self.port, timeout=LONG_TIMEOUT, retries=False
) as pool:

conn = pool._get_conn()
wait_for_socket(ready_event)
now = time.time()
Expand Down Expand Up @@ -460,7 +458,6 @@ def test_keepalive_close(self):
with HTTPConnectionPool(
self.host, self.port, block=True, maxsize=1, timeout=2
) as pool:

r = pool.request(
"GET", "/keepalive?close=1", retries=0, headers={"Connection": "close"}
)
Expand Down Expand Up @@ -624,7 +621,6 @@ def test_lazy_load_twice(self):
with HTTPConnectionPool(
self.host, self.port, block=True, maxsize=1, timeout=2
) as pool:

payload_size = 1024 * 2
first_chunk = 512

Expand Down
22 changes: 0 additions & 22 deletions test/with_dummyserver/test_https.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ def test_client_encrypted_key_requires_password(self):
cert_file=client_cert,
key_password=None,
) as https_pool:

with pytest.raises(MaxRetryError) as e:
https_pool.request("GET", "/certificate")

Expand All @@ -190,7 +189,6 @@ def test_verified(self):
with HTTPSConnectionPool(
self.host, self.port, cert_reqs="CERT_REQUIRED", ca_certs=DEFAULT_CA
) as https_pool:

conn = https_pool._new_conn()
assert conn.__class__ == VerifiedHTTPSConnection

Expand Down Expand Up @@ -219,7 +217,6 @@ def test_verified_with_context(self):
ctx = util.ssl_.create_urllib3_context(cert_reqs=ssl.CERT_REQUIRED)
ctx.load_verify_locations(cafile=DEFAULT_CA)
with HTTPSConnectionPool(self.host, self.port, ssl_context=ctx) as https_pool:

conn = https_pool._new_conn()
assert conn.__class__ == VerifiedHTTPSConnection

Expand Down Expand Up @@ -249,7 +246,6 @@ def test_context_combines_with_ca_certs(self):
with HTTPSConnectionPool(
self.host, self.port, ca_certs=DEFAULT_CA, ssl_context=ctx
) as https_pool:

conn = https_pool._new_conn()
assert conn.__class__ == VerifiedHTTPSConnection

Expand Down Expand Up @@ -281,7 +277,6 @@ def test_ca_dir_verified(self):
with HTTPSConnectionPool(
self.host, self.port, cert_reqs="CERT_REQUIRED", ca_cert_dir=DEFAULT_CA_DIR
) as https_pool:

conn = https_pool._new_conn()
assert conn.__class__ == VerifiedHTTPSConnection

Expand All @@ -294,7 +289,6 @@ def test_invalid_common_name(self):
with HTTPSConnectionPool(
"127.0.0.1", self.port, cert_reqs="CERT_REQUIRED", ca_certs=DEFAULT_CA
) as https_pool:

try:
https_pool.request("GET", "/")
self.fail("Didn't raise SSL invalid common name")
Expand All @@ -308,7 +302,6 @@ def test_verified_with_bad_ca_certs(self):
with HTTPSConnectionPool(
self.host, self.port, cert_reqs="CERT_REQUIRED", ca_certs=DEFAULT_CA_BAD
) as https_pool:

try:
https_pool.request("GET", "/")
self.fail("Didn't raise SSL error with bad CA certs")
Expand All @@ -323,7 +316,6 @@ def test_verified_without_ca_certs(self):
with HTTPSConnectionPool(
self.host, self.port, cert_reqs="CERT_REQUIRED"
) as https_pool:

try:
https_pool.request("GET", "/")
self.fail(
Expand Down Expand Up @@ -358,7 +350,6 @@ def test_no_ssl(self):
def test_unverified_ssl(self):
""" Test that bare HTTPSConnection can connect, make requests """
with HTTPSConnectionPool(self.host, self.port, cert_reqs=ssl.CERT_NONE) as pool:

with mock.patch("warnings.warn") as warn:
r = pool.request("GET", "/")
assert r.status == 200
Expand All @@ -374,7 +365,6 @@ def test_ssl_unverified_with_ca_certs(self):
with HTTPSConnectionPool(
self.host, self.port, cert_reqs="CERT_NONE", ca_certs=DEFAULT_CA_BAD
) as pool:

with mock.patch("warnings.warn") as warn:
r = pool.request("GET", "/")
assert r.status == 200
Expand All @@ -400,15 +390,13 @@ def test_assert_hostname_false(self):
with HTTPSConnectionPool(
"localhost", self.port, cert_reqs="CERT_REQUIRED", ca_certs=DEFAULT_CA
) as https_pool:

https_pool.assert_hostname = False
https_pool.request("GET", "/")

def test_assert_specific_hostname(self):
with HTTPSConnectionPool(
"localhost", self.port, cert_reqs="CERT_REQUIRED", ca_certs=DEFAULT_CA
) as https_pool:

https_pool.assert_hostname = "localhost"
https_pool.request("GET", "/")

Expand All @@ -420,7 +408,6 @@ def test_server_hostname(self):
ca_certs=DEFAULT_CA,
server_hostname="localhost",
) as https_pool:

conn = https_pool._new_conn()
conn.request("GET", "/")

Expand All @@ -435,7 +422,6 @@ def test_assert_fingerprint_md5(self):
with HTTPSConnectionPool(
"localhost", self.port, cert_reqs="CERT_REQUIRED", ca_certs=DEFAULT_CA
) as https_pool:

https_pool.assert_fingerprint = (
"F2:06:5A:42:10:3F:45:1C:17:FE:E6:07:1E:8A:86:E5"
)
Expand All @@ -446,7 +432,6 @@ def test_assert_fingerprint_sha1(self):
with HTTPSConnectionPool(
"localhost", self.port, cert_reqs="CERT_REQUIRED", ca_certs=DEFAULT_CA
) as https_pool:

https_pool.assert_fingerprint = (
"92:81:FE:85:F7:0C:26:60:EC:D6:B3:BF:93:CF:F9:71:CC:07:7D:0A"
)
Expand All @@ -456,7 +441,6 @@ def test_assert_fingerprint_sha256(self):
with HTTPSConnectionPool(
"localhost", self.port, cert_reqs="CERT_REQUIRED", ca_certs=DEFAULT_CA
) as https_pool:

https_pool.assert_fingerprint = (
"C5:4D:0B:83:84:89:2E:AE:B4:58:BB:12:"
"F7:A6:C4:76:05:03:88:D8:57:65:51:F3:"
Expand All @@ -468,7 +452,6 @@ def test_assert_invalid_fingerprint(self):
with HTTPSConnectionPool(
"127.0.0.1", self.port, cert_reqs="CERT_REQUIRED", ca_certs=DEFAULT_CA
) as https_pool:

https_pool.assert_fingerprint = (
"AA:AA:AA:AA:AA:AAAA:AA:AAAA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA"
)
Expand All @@ -494,7 +477,6 @@ def test_verify_none_and_bad_fingerprint(self):
with HTTPSConnectionPool(
"127.0.0.1", self.port, cert_reqs="CERT_NONE", ca_certs=DEFAULT_CA_BAD
) as https_pool:

https_pool.assert_fingerprint = (
"AA:AA:AA:AA:AA:AAAA:AA:AAAA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA"
)
Expand All @@ -506,7 +488,6 @@ def test_verify_none_and_good_fingerprint(self):
with HTTPSConnectionPool(
"127.0.0.1", self.port, cert_reqs="CERT_NONE", ca_certs=DEFAULT_CA_BAD
) as https_pool:

https_pool.assert_fingerprint = (
"92:81:FE:85:F7:0C:26:60:EC:D6:B3:BF:93:CF:F9:71:CC:07:7D:0A"
)
Expand All @@ -521,7 +502,6 @@ def test_good_fingerprint_and_hostname_mismatch(self):
with HTTPSConnectionPool(
"127.0.0.1", self.port, cert_reqs="CERT_REQUIRED", ca_certs=DEFAULT_CA
) as https_pool:

https_pool.assert_fingerprint = (
"92:81:FE:85:F7:0C:26:60:EC:D6:B3:BF:93:CF:F9:71:CC:07:7D:0A"
)
Expand Down Expand Up @@ -566,7 +546,6 @@ def test_tunnel(self):
with HTTPSConnectionPool(
self.host, self.port, timeout=timeout, cert_reqs="CERT_NONE"
) as https_pool:

conn = https_pool._new_conn()
try:
conn.set_tunnel(self.host, self.port)
Expand Down Expand Up @@ -630,7 +609,6 @@ def test_enhanced_ssl_connection(self):
ca_certs=DEFAULT_CA,
assert_fingerprint=fingerprint,
) as https_pool:

r = https_pool.request("GET", "/")
assert r.status == 200

Expand Down
13 changes: 0 additions & 13 deletions test/with_dummyserver/test_poolmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def test_redirect(self):

def test_redirect_twice(self):
with PoolManager() as http:

r = http.request(
"GET",
"%s/redirect" % self.base_url,
Expand All @@ -62,7 +61,6 @@ def test_redirect_twice(self):

def test_redirect_to_relative_url(self):
with PoolManager() as http:

r = http.request(
"GET",
"%s/redirect" % self.base_url,
Expand All @@ -81,7 +79,6 @@ def test_redirect_to_relative_url(self):

def test_cross_host_redirect(self):
with PoolManager() as http:

cross_host_location = "%s/echo?a=b" % self.base_url_alt
try:
http.request(
Expand Down Expand Up @@ -110,7 +107,6 @@ def test_cross_host_redirect(self):

def test_too_many_redirects(self):
with PoolManager() as http:

try:
r = http.request(
"GET",
Expand Down Expand Up @@ -145,7 +141,6 @@ def test_too_many_redirects(self):

def test_redirect_cross_host_remove_headers(self):
with PoolManager() as http:

r = http.request(
"GET",
"%s/redirect" % self.base_url,
Expand Down Expand Up @@ -175,7 +170,6 @@ def test_redirect_cross_host_remove_headers(self):

def test_redirect_cross_host_no_remove_headers(self):
with PoolManager() as http:

r = http.request(
"GET",
"%s/redirect" % self.base_url,
Expand All @@ -192,7 +186,6 @@ def test_redirect_cross_host_no_remove_headers(self):

def test_redirect_cross_host_set_removed_headers(self):
with PoolManager() as http:

r = http.request(
"GET",
"%s/redirect" % self.base_url,
Expand Down Expand Up @@ -226,7 +219,6 @@ def test_redirect_cross_host_set_removed_headers(self):

def test_raise_on_redirect(self):
with PoolManager() as http:

r = http.request(
"GET",
"%s/redirect" % self.base_url,
Expand All @@ -240,7 +232,6 @@ def test_raise_on_redirect(self):

def test_raise_on_status(self):
with PoolManager() as http:

try:
# the default is to raise
r = http.request(
Expand Down Expand Up @@ -288,7 +279,6 @@ def test_missing_port(self):
# will all such URLs fail with an error?

with PoolManager() as http:

# By globally adjusting `port_by_scheme` we pretend for a moment
# that HTTP's default port is not 80, but is the port at which
# our test server happens to be listening.
Expand All @@ -303,7 +293,6 @@ def test_missing_port(self):

def test_headers(self):
with PoolManager(headers={"Foo": "bar"}) as http:

r = http.request("GET", "%s/headers" % self.base_url)
returned_headers = json.loads(r.data.decode())
assert returned_headers.get("Foo") == "bar"
Expand Down Expand Up @@ -336,13 +325,11 @@ def test_headers(self):

def test_http_with_ssl_keywords(self):
with PoolManager(ca_certs="REQUIRED") as http:

r = http.request("GET", "http://%s:%s/" % (self.host, self.port))
assert r.status == 200

def test_http_with_ca_cert_dir(self):
with PoolManager(ca_certs="REQUIRED", ca_cert_dir="/nosuchdir") as http:

r = http.request("GET", "http://%s:%s/" % (self.host, self.port))
assert r.status == 200

Expand Down
Loading