Skip to content

Commit f30a095

Browse files
committed
Add some linter to pre-commit configuration and format the code
1 parent ce8bf4e commit f30a095

File tree

12 files changed

+71
-25
lines changed

12 files changed

+71
-25
lines changed

.pre-commit-config.yaml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,41 @@ repos:
33
rev: 22.3.0
44
hooks:
55
- id: black
6-
args: [--safe, --quiet]
6+
args: [--safe, --quiet]
7+
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v4.2.0
10+
hooks:
11+
- id: trailing-whitespace
12+
- id: end-of-file-fixer
13+
- id: fix-encoding-pragma
14+
args: [--remove]
15+
- id: check-yaml
16+
language_version: python3
17+
18+
- repo: https://github.com/myint/autoflake
19+
rev: v1.4
20+
hooks:
21+
- id: autoflake
22+
name: autoflake
23+
args: ["--in-place", "--remove-unused-variables", "--remove-all-unused-imports"]
24+
language: python
25+
files: \.py$
26+
27+
- repo: https://github.com/PyCQA/flake8
28+
rev: 4.0.1
29+
hooks:
30+
- id: flake8
31+
language_version: python3
32+
33+
- repo: https://github.com/asottile/reorder_python_imports
34+
rev: v3.1.0
35+
hooks:
36+
- id: reorder-python-imports
37+
args: [--py3-plus]
38+
39+
- repo: https://github.com/asottile/pyupgrade
40+
rev: v2.32.1
41+
hooks:
42+
- id: pyupgrade
43+
args: [--py3-plus]

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
1010
:target: https://github.com/psf/black
1111

12+
.. image:: https://results.pre-commit.ci/badge/github/pytest-dev/pytest-localserver/master.svg
13+
:target: https://results.pre-commit.ci/latest/github/pytest-dev/pytest-localserver/master
14+
:alt: pre-commit.ci status
15+
1216
==================
1317
pytest-localserver
1418
==================

pytest_localserver/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from pytest_localserver._version import version as VERSION
1+
from pytest_localserver._version import version as VERSION # noqa

pytest_localserver/http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# This program is release under the MIT license. You can find the full text of
44
# the license in the LICENSE file.
5-
65
import enum
76
import itertools
87
import json
@@ -11,7 +10,8 @@
1110

1211
from werkzeug.datastructures import Headers
1312
from werkzeug.serving import make_server
14-
from werkzeug.wrappers import Response, Request
13+
from werkzeug.wrappers import Request
14+
from werkzeug.wrappers import Response
1515

1616

1717
class WSGIServer(threading.Thread):

pytest_localserver/https.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# This program is release under the MIT license. You can find the full text of
44
# the license in the LICENSE file.
5-
65
import os.path
76

87
from pytest_localserver.http import ContentServer
@@ -108,7 +107,7 @@ class SecureContentServer(ContentServer):
108107
109108
A more advanced tutorial can be found `here`_.
110109
111-
.. _pytest-localserver CA: https://raw.githubusercontent.com/pytest-dev/pytest-localserver/master/pytest_localserver/ca.crt
110+
.. _pytest-localserver CA: https://raw.githubusercontent.com/pytest-dev/pytest-localserver/master/pytest_localserver/ca.crt # noqa: E501
112111
.. _pyOpenSSH: https://launchpad.net/pyopenssl
113112
"""
114113

pytest_localserver/smtp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
# SmtpMailsink Copyright 2005 Aviarc Corporation
66
# Written by Adam Feuer, Matt Branthwaite, and Troy Frever
77
# which is Licensed under the PSF License
8+
import email
89

910
import aiosmtpd.controller
10-
import email
11-
import sys
1211

1312

1413
class MessageDetails:

runtests.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,10 +2658,9 @@
26582658
p2dPWv10xmXLnHQLlQrVD1yYQwb9/yTK0Oq4oxv6j0jKNxLPbTMi6d3/e5X+FyKT7kc=
26592659
"""
26602660

2661-
import sys
2662-
import base64
2663-
import zlib
2664-
import imp
2661+
import sys # noqa: E402
2662+
import base64 # noqa: E402
2663+
import zlib # noqa: E402
26652664

26662665

26672666
class DictImporter:
@@ -2693,7 +2692,7 @@ def load_module(self, fullname):
26932692
if is_pkg:
26942693
module.__path__ = [fullname]
26952694

2696-
do_exec(co, module.__dict__)
2695+
do_exec(co, module.__dict__) # noqa: F821
26972696
return sys.modules[fullname]
26982697

26992698
def get_source(self, name):
@@ -2714,4 +2713,4 @@ def get_source(self, name):
27142713
sys.meta_path.insert(0, importer)
27152714

27162715
entry = "import py; raise SystemExit(py.test.cmdline.main())"
2717-
do_exec(entry, locals())
2716+
do_exec(entry, locals()) # noqa: F821

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from setuptools import setup, Command
2-
import sys
1+
from setuptools import Command
2+
from setuptools import setup
33

44

55
def read(fname):
@@ -20,7 +20,8 @@ def finalize_options(self):
2020
pass
2121

2222
def run(self):
23-
import sys, subprocess
23+
import subprocess
24+
import sys
2425

2526
errno = subprocess.call([sys.executable, "runtests.py"])
2627
raise SystemExit(errno)

tests/test_http.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import itertools
2+
23
import pytest
34
import requests
45

5-
from pytest_localserver import http, plugin
6+
from pytest_localserver import http
7+
from pytest_localserver import plugin
68

79

810
# define test fixture here again in order to run tests without having to
@@ -36,7 +38,7 @@ def test_some_content_retrieval(httpserver):
3638
def test_request_is_stored(httpserver):
3739
httpserver.serve_content("TEST!")
3840
assert len(httpserver.requests) == 0
39-
resp = requests.get(httpserver.url)
41+
requests.get(httpserver.url)
4042
assert len(httpserver.requests) == 1
4143

4244

@@ -160,7 +162,7 @@ def test_GET_request_not_chunked(httpserver, transfer_encoding_header):
160162
chunked=http.Chunked.NO,
161163
)
162164
with pytest.raises(requests.exceptions.ChunkedEncodingError):
163-
resp = requests.get(httpserver.url, headers={"User-Agent": "Test method"})
165+
requests.get(httpserver.url, headers={"User-Agent": "Test method"})
164166

165167

166168
@pytest.mark.parametrize("chunked_flag", [http.Chunked.NO, http.Chunked.AUTO])

tests/test_https.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import sys
2-
3-
import pytest
41
import requests
52

6-
from pytest_localserver import https, plugin
3+
from pytest_localserver import https
4+
from pytest_localserver import plugin
75

86

97
# define test fixture here again in order to run tests without having to

0 commit comments

Comments
 (0)