Skip to content

Commit a28a7a3

Browse files
authored
Merge pull request #68 from kevin1024/configure-pre-commit
drop support for Python 3.6 with pyupgrade and other pre-commit tools
2 parents 61c5d91 + e76d250 commit a28a7a3

File tree

14 files changed

+296
-222
lines changed

14 files changed

+296
-222
lines changed

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
python-version: [3.7, 3.8, 3.9, '3.10']
16+
python-version: [3.7, 3.8, 3.9, "3.10"]
1717
os: [macOS-latest, ubuntu-latest, windows-latest]
1818

1919
steps:

.pre-commit-config.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
repos:
2+
- repo: https://github.com/asottile/pyupgrade
3+
rev: v2.31.0
4+
hooks:
5+
- id: pyupgrade
6+
args: ["--py37-plus"]
7+
8+
- repo: https://github.com/psf/black
9+
rev: 22.1.0
10+
hooks:
11+
- id: black
12+
args: ["--target-version", "py37"]
13+
14+
- repo: https://github.com/pycqa/isort
15+
rev: 5.10.1
16+
hooks:
17+
- id: isort
18+
19+
- repo: https://github.com/pre-commit/pygrep-hooks
20+
rev: v1.9.0
21+
hooks:
22+
- id: python-check-blanket-noqa
23+
24+
- repo: https://github.com/pre-commit/pre-commit-hooks
25+
rev: v4.1.0
26+
hooks:
27+
- id: check-merge-conflict
28+
- id: check-toml
29+
- id: check-yaml
30+
- id: mixed-line-ending
31+
32+
- repo: https://github.com/pre-commit/mirrors-prettier
33+
rev: v2.5.1
34+
hooks:
35+
- id: prettier
36+
args: [--prose-wrap=always, --print-width=88]
37+
38+
- repo: https://github.com/myint/autoflake
39+
rev: v1.4
40+
hooks:
41+
- id: autoflake
42+
args:
43+
- --in-place
44+
- --remove-all-unused-imports
45+
- --expand-star-imports
46+
- --remove-duplicate-keys
47+
- --remove-unused-variables
48+
49+
- repo: https://gitlab.com/pycqa/flake8
50+
rev: 3.9.2
51+
hooks:
52+
- id: flake8
53+
additional_dependencies: [flake8-2020]

README.md

Lines changed: 119 additions & 89 deletions
Large diffs are not rendered by default.

pytest_httpbin/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import pytest
44

5-
65
here = os.path.dirname(__file__)
76
version_file = os.path.join(here, "version.py")
87

98
with open(version_file) as f:
10-
code = compile(f.read(), version_file, 'exec')
9+
code = compile(f.read(), version_file, "exec")
1110
exec(code)
1211

1312
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: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
1-
from __future__ import absolute_import
21
import pytest
32
from httpbin import app as httpbin_app
4-
from . import serve, certs
53

6-
@pytest.fixture(scope='session')
4+
from . import certs, serve
5+
6+
7+
@pytest.fixture(scope="session")
78
def httpbin(request):
89
server = serve.Server(application=httpbin_app)
910
server.start()
1011
request.addfinalizer(server.stop)
1112
return server
1213

1314

14-
@pytest.fixture(scope='session')
15+
@pytest.fixture(scope="session")
1516
def httpbin_secure(request):
1617
server = serve.SecureServer(application=httpbin_app)
1718
server.start()
1819
request.addfinalizer(server.stop)
1920
return server
2021

2122

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

2930

30-
@pytest.fixture(scope='class')
31+
@pytest.fixture(scope="class")
3132
def class_based_httpbin(request, httpbin):
3233
request.cls.httpbin = httpbin
3334

34-
@pytest.fixture(scope='class')
35+
36+
@pytest.fixture(scope="class")
3537
def class_based_httpbin_secure(request, httpbin_secure):
3638
request.cls.httpbin_secure = httpbin_secure
3739

3840

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

pytest_httpbin/serve.py

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
import os
2-
import threading
32
import ssl
4-
from wsgiref.simple_server import WSGIServer, make_server, WSGIRequestHandler
3+
import threading
54
from wsgiref.handlers import SimpleHandler
6-
from six.moves.urllib.parse import urljoin
5+
from wsgiref.simple_server import WSGIRequestHandler, WSGIServer, make_server
76

7+
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)
@@ -78,35 +76,31 @@ def finish_request(self, request, client_address):
7876
# Thanks, WSGIRequestHandler!!
7977

8078

81-
class Server(object):
79+
class Server:
8280
"""
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 f"{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
134-
super(SecureServer, self).__init__(host, port, application, **kwargs)
135-
self.protocol = 'https'
126+
def __init__(self, host="127.0.0.1", port=0, application=None, **kwargs):
127+
kwargs["server_class"] = SecureWSGIServer
128+
super().__init__(host, port, application, **kwargs)
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.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33
# 3. If at all possible, it is good practice to do this. If you cannot, you
44
# will need to generate wheels for each Python version that you support.
55
universal=1
6+
7+
[flake8]
8+
disable-noqa = True
9+
max-line-length = 88
10+
extend-ignore =
11+
E203, # whitespace before : is not PEP8 compliant (& conflicts with black)

setup.py

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,58 @@
1-
from setuptools import setup, find_packages
21
import codecs
32
import os
4-
import re
53

4+
from setuptools import find_packages, setup
5+
6+
__version__ = None
67
with open("pytest_httpbin/version.py") as f:
7-
code = compile(f.read(), "pytest_httpbin/version.py", 'exec')
8+
code = compile(f.read(), "pytest_httpbin/version.py", "exec")
89
exec(code)
910

1011
here = os.path.abspath(os.path.dirname(__file__))
1112

1213
# Get the long description from the relevant file
13-
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:
1415
long_description = f.read()
1516

1617
setup(
1718
name="pytest-httpbin",
18-
1919
# There are various approaches to referencing the version. For a discussion,
2020
# see http://packaging.python.org/en/latest/tutorial.html#version
2121
version=__version__,
22-
2322
description="Easily test your HTTP library against a local copy of httpbin",
2423
long_description=long_description,
2524
long_description_content_type="text/x-rst",
26-
2725
# The project URL.
28-
url='https://github.com/kevin1024/pytest-httpbin',
29-
26+
url="https://github.com/kevin1024/pytest-httpbin",
3027
# Author details
31-
author='Kevin McCarthy',
32-
author_email='me@kevinmccarthy.org',
33-
28+
author="Kevin McCarthy",
29+
author_email="me@kevinmccarthy.org",
3430
# Choose your license
35-
license='MIT',
36-
31+
license="MIT",
3732
classifiers=[
38-
'Development Status :: 5 - Production/Stable',
39-
'Intended Audience :: Developers',
40-
'Topic :: Software Development :: Testing',
41-
'Topic :: Software Development :: Libraries',
42-
'License :: OSI Approved :: MIT License',
43-
'Programming Language :: Python :: 2',
44-
'Programming Language :: Python :: 2.6',
45-
'Programming Language :: Python :: 2.7',
46-
'Programming Language :: Python :: 3',
47-
'Programming Language :: Python :: 3.4',
48-
'Programming Language :: Python :: 3.5',
49-
'Programming Language :: Python :: 3.6',
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-
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",
5952
# the following makes a plugin available to pytest
60-
entry_points = {
61-
'pytest11': [
62-
'httpbin = pytest_httpbin.plugin',
53+
entry_points={
54+
"pytest11": [
55+
"httpbin = pytest_httpbin.plugin",
6356
]
6457
},
6558
)

0 commit comments

Comments
 (0)