Skip to content

Commit 5ce29a1

Browse files
committed
appply black
1 parent 87fdb99 commit 5ce29a1

File tree

10 files changed

+101
-115
lines changed

10 files changed

+101
-115
lines changed

pytest_httpbin/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
version_file = os.path.join(here, "version.py")
77

88
with open(version_file) as f:
9-
code = compile(f.read(), version_file, 'exec')
9+
code = compile(f.read(), version_file, "exec")
1010
exec(code)
1111

1212
use_class_based_httpbin = pytest.mark.usefixtures("class_based_httpbin")

pytest_httpbin/certs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
def where():
1616
"""Return the preferred certificate bundle."""
1717
# vendored bundle inside Requests
18-
return os.path.join(os.path.dirname(__file__), 'certs', 'cacert.pem')
18+
return os.path.join(os.path.dirname(__file__), "certs", "cacert.pem")
1919

20-
if __name__ == '__main__':
20+
21+
if __name__ == "__main__":
2122
print(where())

pytest_httpbin/plugin.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,41 @@
55

66
from . import certs, serve
77

8-
@pytest.fixture(scope='session')
8+
9+
@pytest.fixture(scope="session")
910
def httpbin(request):
1011
server = serve.Server(application=httpbin_app)
1112
server.start()
1213
request.addfinalizer(server.stop)
1314
return server
1415

1516

16-
@pytest.fixture(scope='session')
17+
@pytest.fixture(scope="session")
1718
def httpbin_secure(request):
1819
server = serve.SecureServer(application=httpbin_app)
1920
server.start()
2021
request.addfinalizer(server.stop)
2122
return server
2223

2324

24-
@pytest.fixture(scope='session', params=['http', 'https'])
25+
@pytest.fixture(scope="session", params=["http", "https"])
2526
def httpbin_both(request, httpbin, httpbin_secure):
26-
if request.param == 'http':
27+
if request.param == "http":
2728
return httpbin
28-
elif request.param == 'https':
29+
elif request.param == "https":
2930
return httpbin_secure
3031

3132

32-
@pytest.fixture(scope='class')
33+
@pytest.fixture(scope="class")
3334
def class_based_httpbin(request, httpbin):
3435
request.cls.httpbin = httpbin
3536

36-
@pytest.fixture(scope='class')
37+
38+
@pytest.fixture(scope="class")
3739
def class_based_httpbin_secure(request, httpbin_secure):
3840
request.cls.httpbin_secure = httpbin_secure
3941

4042

41-
@pytest.fixture(scope='function')
43+
@pytest.fixture(scope="function")
4244
def httpbin_ca_bundle(monkeypatch):
43-
monkeypatch.setenv('REQUESTS_CA_BUNDLE', certs.where())
45+
monkeypatch.setenv("REQUESTS_CA_BUNDLE", certs.where())

pytest_httpbin/serve.py

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,28 @@
66

77
from six.moves.urllib.parse import urljoin
88

9-
CERT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'certs')
9+
CERT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "certs")
1010

1111

1212
class ServerHandler(SimpleHandler):
1313

14-
server_software = 'Pytest-HTTPBIN/0.1.0'
15-
http_version = '1.1'
14+
server_software = "Pytest-HTTPBIN/0.1.0"
15+
http_version = "1.1"
1616

1717
def cleanup_headers(self):
1818
SimpleHandler.cleanup_headers(self)
19-
self.headers['Connection'] = 'Close'
19+
self.headers["Connection"] = "Close"
2020

2121
def close(self):
2222
try:
2323
self.request_handler.log_request(
24-
self.status.split(' ', 1)[0], self.bytes_sent
24+
self.status.split(" ", 1)[0], self.bytes_sent
2525
)
2626
finally:
2727
SimpleHandler.close(self)
2828

2929

3030
class Handler(WSGIRequestHandler):
31-
3231
def handle(self):
3332
"""Handle a single HTTP request"""
3433

@@ -39,7 +38,7 @@ def handle(self):
3938
handler = ServerHandler(
4039
self.rfile, self.wfile, self.get_stderr(), self.get_environ()
4140
)
42-
handler.request_handler = self # backpointer for logging
41+
handler.request_handler = self # backpointer for logging
4342
handler.run(self.server.get_app())
4443

4544
def get_environ(self):
@@ -49,13 +48,12 @@ def get_environ(self):
4948
"""
5049
# Note: Can't use super since this is an oldstyle class in python 2.x
5150
environ = WSGIRequestHandler.get_environ(self).copy()
52-
if self.headers.get('content-type') is None:
53-
del environ['CONTENT_TYPE']
51+
if self.headers.get("content-type") is None:
52+
del environ["CONTENT_TYPE"]
5453
return environ
5554

5655

5756
class SecureWSGIServer(WSGIServer):
58-
5957
def finish_request(self, request, client_address):
6058
"""
6159
Negotiates SSL and then mimics BaseServer behavior.
@@ -64,12 +62,12 @@ def finish_request(self, request, client_address):
6462
try:
6563
ssock = ssl.wrap_socket(
6664
request,
67-
keyfile=os.path.join(CERT_DIR, 'key.pem'),
68-
certfile=os.path.join(CERT_DIR, 'cert.pem'),
65+
keyfile=os.path.join(CERT_DIR, "key.pem"),
66+
certfile=os.path.join(CERT_DIR, "cert.pem"),
6967
server_side=True,
7068
suppress_ragged_eofs=False,
7169
)
72-
self.base_environ['HTTPS'] = 'yes'
70+
self.base_environ["HTTPS"] = "yes"
7371
self.RequestHandlerClass(ssock, client_address, self)
7472
except Exception as e:
7573
print("pytest-httpbin server hit an exception serving request: %s" % e)
@@ -83,30 +81,26 @@ class Server(object):
8381
HTTP server running a WSGI application in its own thread.
8482
"""
8583

86-
port_envvar = 'HTTPBIN_HTTP_PORT'
84+
port_envvar = "HTTPBIN_HTTP_PORT"
8785

88-
def __init__(self, host='127.0.0.1', port=0, application=None, **kwargs):
86+
def __init__(self, host="127.0.0.1", port=0, application=None, **kwargs):
8987
self.app = application
9088
if self.port_envvar in os.environ:
9189
port = int(os.environ[self.port_envvar])
9290
self._server = make_server(
93-
host,
94-
port,
95-
self.app,
96-
handler_class=Handler,
97-
**kwargs
91+
host, port, self.app, handler_class=Handler, **kwargs
9892
)
9993
self.host = self._server.server_address[0]
10094
self.port = self._server.server_address[1]
101-
self.protocol = 'http'
95+
self.protocol = "http"
10296

10397
self._thread = threading.Thread(
10498
name=self.__class__,
10599
target=self._server.serve_forever,
106100
)
107101

108102
def __del__(self):
109-
if hasattr(self, '_server'):
103+
if hasattr(self, "_server"):
110104
self.stop()
111105

112106
def start(self):
@@ -120,16 +114,16 @@ def stop(self):
120114

121115
@property
122116
def url(self):
123-
return '{0}://{1}:{2}'.format(self.protocol, self.host, self.port)
117+
return "{0}://{1}:{2}".format(self.protocol, self.host, self.port)
124118

125119
def join(self, url, allow_fragments=True):
126120
return urljoin(self.url, url, allow_fragments=allow_fragments)
127121

128122

129123
class SecureServer(Server):
130-
port_envvar = 'HTTPBIN_HTTPS_PORT'
124+
port_envvar = "HTTPBIN_HTTPS_PORT"
131125

132-
def __init__(self, host='127.0.0.1', port=0, application=None, **kwargs):
133-
kwargs['server_class'] = SecureWSGIServer
126+
def __init__(self, host="127.0.0.1", port=0, application=None, **kwargs):
127+
kwargs["server_class"] = SecureWSGIServer
134128
super(SecureServer, self).__init__(host, port, application, **kwargs)
135-
self.protocol = 'https'
129+
self.protocol = "https"

pytest_httpbin/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.0.2'
1+
__version__ = "1.0.2"

setup.py

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,54 @@
55

66
__version__ = None
77
with open("pytest_httpbin/version.py") as f:
8-
code = compile(f.read(), "pytest_httpbin/version.py", 'exec')
8+
code = compile(f.read(), "pytest_httpbin/version.py", "exec")
99
exec(code)
1010

1111
here = os.path.abspath(os.path.dirname(__file__))
1212

1313
# Get the long description from the relevant file
14-
with codecs.open(os.path.join(here, 'DESCRIPTION.rst'), encoding='utf-8') as f:
14+
with codecs.open(os.path.join(here, "DESCRIPTION.rst"), encoding="utf-8") as f:
1515
long_description = f.read()
1616

1717
setup(
1818
name="pytest-httpbin",
19-
2019
# There are various approaches to referencing the version. For a discussion,
2120
# see http://packaging.python.org/en/latest/tutorial.html#version
2221
version=__version__,
23-
2422
description="Easily test your HTTP library against a local copy of httpbin",
2523
long_description=long_description,
2624
long_description_content_type="text/x-rst",
27-
2825
# The project URL.
29-
url='https://github.com/kevin1024/pytest-httpbin',
30-
26+
url="https://github.com/kevin1024/pytest-httpbin",
3127
# Author details
32-
author='Kevin McCarthy',
33-
author_email='me@kevinmccarthy.org',
34-
28+
author="Kevin McCarthy",
29+
author_email="me@kevinmccarthy.org",
3530
# Choose your license
36-
license='MIT',
37-
31+
license="MIT",
3832
classifiers=[
39-
'Development Status :: 5 - Production/Stable',
40-
'Intended Audience :: Developers',
41-
'Topic :: Software Development :: Testing',
42-
'Topic :: Software Development :: Libraries',
43-
'License :: OSI Approved :: MIT License',
44-
'Programming Language :: Python :: 3',
45-
'Programming Language :: Python :: 3 :: Only',
46-
'Programming Language :: Python :: 3.7',
47-
'Programming Language :: Python :: 3.8',
48-
'Programming Language :: Python :: 3.9',
49-
'Programming Language :: Python :: 3.10',
33+
"Development Status :: 5 - Production/Stable",
34+
"Intended Audience :: Developers",
35+
"Topic :: Software Development :: Testing",
36+
"Topic :: Software Development :: Libraries",
37+
"License :: OSI Approved :: MIT License",
38+
"Programming Language :: Python :: 3",
39+
"Programming Language :: Python :: 3 :: Only",
40+
"Programming Language :: Python :: 3.7",
41+
"Programming Language :: Python :: 3.8",
42+
"Programming Language :: Python :: 3.9",
43+
"Programming Language :: Python :: 3.10",
5044
],
51-
5245
# What does your project relate to?
53-
keywords='pytest-httpbin testing pytest httpbin',
46+
keywords="pytest-httpbin testing pytest httpbin",
5447
packages=find_packages(exclude=["contrib", "docs", "tests*"]),
55-
include_package_data = True, # include files listed in MANIFEST.in
56-
install_requires = ['httpbin','six'],
57-
extras_require = {"test": ["requests", "pytest"]},
58-
python_requires = ">=3.7",
59-
48+
include_package_data=True, # include files listed in MANIFEST.in
49+
install_requires=["httpbin", "six"],
50+
extras_require={"test": ["requests", "pytest"]},
51+
python_requires=">=3.7",
6052
# the following makes a plugin available to pytest
61-
entry_points = {
62-
'pytest11': [
63-
'httpbin = pytest_httpbin.plugin',
53+
entry_points={
54+
"pytest11": [
55+
"httpbin = pytest_httpbin.plugin",
6456
]
6557
},
6658
)

tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22

33

4-
5-
@pytest.fixture(autouse=True, scope='function')
4+
@pytest.fixture(autouse=True, scope="function")
65
def httpbin_ca_bundle_autoused(httpbin_ca_bundle):
76
pass

tests/test_httpbin.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,48 @@ def test_httpbin_gets_injected(httpbin):
1010

1111

1212
def test_httpbin_accepts_get_requests(httpbin):
13-
assert requests.get(httpbin.url + '/get').status_code == 200
13+
assert requests.get(httpbin.url + "/get").status_code == 200
1414

1515

1616
def test_httpbin_secure_accepts_get_requests(httpbin_secure):
17-
assert requests.get(httpbin_secure.url + '/get').status_code == 200
17+
assert requests.get(httpbin_secure.url + "/get").status_code == 200
1818

1919

2020
def test_httpbin_secure_accepts_lots_of_get_requests(httpbin_secure):
2121
for i in range(10):
22-
assert requests.get(httpbin_secure.url + '/get').status_code == 200
22+
assert requests.get(httpbin_secure.url + "/get").status_code == 200
2323

2424

2525
def test_httpbin_accepts_lots_of_get_requests_in_single_session(httpbin):
2626
session = requests.Session()
2727

2828
for i in range(10):
29-
assert session.get(httpbin.url + '/get').status_code == 200
29+
assert session.get(httpbin.url + "/get").status_code == 200
3030

3131

3232
def test_httpbin_both(httpbin_both):
3333
# this test will get called twice, once with an http url, once with an
3434
# https url
35-
assert requests.get(httpbin_both.url + '/get').status_code == 200
35+
assert requests.get(httpbin_both.url + "/get").status_code == 200
3636

3737

3838
def test_httpbin_join(httpbin):
39-
assert httpbin.join('foo') == httpbin.url + '/foo'
39+
assert httpbin.join("foo") == httpbin.url + "/foo"
4040

4141

4242
def test_httpbin_str(httpbin):
43-
assert httpbin + '/foo' == httpbin.url + '/foo'
43+
assert httpbin + "/foo" == httpbin.url + "/foo"
44+
4445

4546
def test_chunked_encoding(httpbin_both):
46-
assert requests.get(httpbin_both.url + '/stream/20').status_code == 200
47+
assert requests.get(httpbin_both.url + "/stream/20").status_code == 200
48+
4749

4850
@pytest_httpbin.use_class_based_httpbin
4951
@pytest_httpbin.use_class_based_httpbin_secure
5052
class TestClassBassedTests(unittest.TestCase):
5153
def test_http(self):
52-
assert requests.get(self.httpbin.url + '/get').status_code == 200
54+
assert requests.get(self.httpbin.url + "/get").status_code == 200
5355

5456
def test_http_secure(self):
55-
assert requests.get(self.httpbin_secure.url + '/get').status_code == 200
57+
assert requests.get(self.httpbin_secure.url + "/get").status_code == 200

0 commit comments

Comments
 (0)