Skip to content

Commit

Permalink
Use ruff as linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jairhenrique committed Jun 26, 2023
1 parent ad1010d commit c83c35a
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 43 deletions.
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ ignore-regex = "\\\\[fnrstv]"
markers = [
"online",
]

[tool.ruff]
select = ["I", "RUF", "UP"]
line-length = 110
target-version = "py38"

[tool.ruff.isort]
known-first-party = [ "vcr" ]
4 changes: 2 additions & 2 deletions tests/integration/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
asyncio = pytest.importorskip("asyncio")
aiohttp = pytest.importorskip("aiohttp")

import vcr # noqa: E402
import vcr

from .aiohttp_utils import aiohttp_app, aiohttp_request # noqa: E402
from .aiohttp_utils import aiohttp_app, aiohttp_request


def run_in_loop(fn):
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/test_boto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

boto = pytest.importorskip("boto")

from configparser import DuplicateSectionError # NOQA
from configparser import DuplicateSectionError

import boto # NOQA
import boto.iam # NOQA
from boto.s3.connection import S3Connection # NOQA
from boto.s3.key import Key # NOQA
import boto
import boto.iam
from boto.s3.connection import S3Connection
from boto.s3.key import Key

import vcr # NOQA
import vcr


def test_boto_stubs(tmpdir):
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

boto3 = pytest.importorskip("boto3")

import boto3 # NOQA
import botocore # NOQA
import boto3
import botocore

import vcr # NOQA
import vcr

try:
from botocore import awsrequest # NOQA
from botocore import awsrequest

botocore_awsrequest = True
except ImportError:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
asyncio = pytest.importorskip("asyncio")
httpx = pytest.importorskip("httpx")

import vcr # noqa: E402
from vcr.stubs.httpx_stubs import HTTPX_REDIRECT_PARAM # noqa: E402
import vcr
from vcr.stubs.httpx_stubs import HTTPX_REDIRECT_PARAM


class BaseDoRequest:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import vcr

requests = pytest.importorskip("requests")
from requests.exceptions import ConnectionError # noqa E402
from requests.exceptions import ConnectionError # E402


def test_status_code(httpbin_both, tmpdir):
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_wild.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

requests = pytest.importorskip("requests")

import vcr # NOQA
import vcr


def test_domain_redirect():
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def test_CannotOverwriteExistingCassetteException_get_message(
failed_request = "request"
exception_message = errors.CannotOverwriteExistingCassetteException._get_message(cassette, "request")
expected = (
"Can't overwrite existing cassette (%r) in your current record mode (%r).\n"
"No match for the request (%r) was found.\n"
"%s" % (cassette._path, cassette.record_mode, failed_request, expected_message)
"Can't overwrite existing cassette ({!r}) in your current record mode ({!r}).\n"
"No match for the request ({!r}) was found.\n"
"{}".format(cassette._path, cassette.record_mode, failed_request, expected_message)
)
assert exception_message == expected
2 changes: 1 addition & 1 deletion tests/unit/test_vcr_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def test_vcr_import_deprecation(recwarn):
# Remove imported module entry if already loaded in another test
del sys.modules["vcr"]

import vcr # noqa: F401
import vcr

if sys.version_info[0] == 2:
assert len(recwarn) == 1
Expand Down
11 changes: 3 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,11 @@ skipsdist = True
commands =
black --version
black --check --diff .
isort --version
isort . --check --diff
flake8 --version
flake8 --exclude=./docs/conf.py,./.tox/,./venv/
pyflakes ./docs/conf.py
ruff check .
deps =
flake8
black
isort
basepython = python3.10
ruff
basepython = python3.8

[testenv:docs]
# Running sphinx from inside the "docs" directory
Expand Down
2 changes: 1 addition & 1 deletion vcr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from logging import NullHandler

from .config import VCR
from .record_mode import RecordMode as mode # noqa import is not used in this file
from .record_mode import RecordMode as mode # import is not used in this file

__version__ = "4.4.0"

Expand Down
4 changes: 2 additions & 2 deletions vcr/_handle_coroutine.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
async def handle_coroutine(vcr, fn): # noqa: E999
async def handle_coroutine(vcr, fn):
with vcr as cassette:
return await fn(cassette) # noqa: E999
return await fn(cassette)
16 changes: 8 additions & 8 deletions vcr/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ def _get_message(cassette, failed_request):
for idx, best_match in enumerate(best_matches, start=1):
request, succeeded_matchers, failed_matchers_assertion_msgs = best_match
best_matches_msg += (
"\n%s - (%r).\n"
"Matchers succeeded : %s\n"
"Matchers failed :\n" % (idx, request, succeeded_matchers)
"\n{} - ({!r}).\n"
"Matchers succeeded : {}\n"
"Matchers failed :\n".format(idx, request, succeeded_matchers)
)
for failed_matcher, assertion_msg in failed_matchers_assertion_msgs:
best_matches_msg += "%s - assertion failure :\n" "%s\n" % (failed_matcher, assertion_msg)
best_matches_msg += "{} - assertion failure :\n" "{}\n".format(failed_matcher, assertion_msg)
else:
best_matches_msg = "No similar requests, that have not been played, found."
return (
"Can't overwrite existing cassette (%r) in "
"your current record mode (%r).\n"
"No match for the request (%r) was found.\n"
"%s" % (cassette._path, cassette.record_mode, failed_request, best_matches_msg)
"Can't overwrite existing cassette ({!r}) in "
"your current record mode ({!r}).\n"
"No match for the request ({!r}) was found.\n"
"{}".format(cassette._path, cassette.record_mode, failed_request, best_matches_msg)
)


Expand Down
2 changes: 1 addition & 1 deletion vcr/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from botocore.awsrequest import AWSHTTPConnection, AWSHTTPSConnection
except ImportError as e:
try:
import botocore.vendored.requests # noqa: F401
import botocore.vendored.requests
except ImportError: # pragma: no cover
pass
else:
Expand Down
6 changes: 3 additions & 3 deletions vcr/stubs/aiohttp_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, method, url, request_info=None):
session=None,
)

async def json(self, *, encoding="utf-8", loads=json.loads, **kwargs): # NOQA: E999
async def json(self, *, encoding="utf-8", loads=json.loads, **kwargs):
stripped = self._body.strip()
if not stripped:
return None
Expand Down Expand Up @@ -162,7 +162,7 @@ async def record_response(cassette, vcr_request, response):
vcr_response = {
"status": {"code": response.status, "message": response.reason},
"headers": _serialize_headers(response.headers),
"body": body, # NOQA: E999
"body": body,
"url": str(response.url),
}

Expand Down Expand Up @@ -273,7 +273,7 @@ async def new_request(self, method, url, **kwargs):

log.info("%s not in cassette, sending to real server", vcr_request)

response = await real_request(self, method, url, **kwargs) # NOQA: E999
response = await real_request(self, method, url, **kwargs)
await record_responses(cassette, vcr_request, response)
return response

Expand Down

0 comments on commit c83c35a

Please sign in to comment.