From c83c35a8efaf671ee70040153d4e217f69e3c08a Mon Sep 17 00:00:00 2001 From: Jair Henrique Date: Mon, 26 Jun 2023 14:43:45 -0300 Subject: [PATCH] Use ruff as linter --- pyproject.toml | 8 ++++++++ tests/integration/test_aiohttp.py | 4 ++-- tests/integration/test_boto.py | 12 ++++++------ tests/integration/test_boto3.py | 8 ++++---- tests/integration/test_httpx.py | 4 ++-- tests/integration/test_requests.py | 2 +- tests/integration/test_wild.py | 2 +- tests/unit/test_errors.py | 6 +++--- tests/unit/test_vcr_import.py | 2 +- tox.ini | 11 +++-------- vcr/__init__.py | 2 +- vcr/_handle_coroutine.py | 4 ++-- vcr/errors.py | 16 ++++++++-------- vcr/patch.py | 2 +- vcr/stubs/aiohttp_stubs.py | 6 +++--- 15 files changed, 46 insertions(+), 43 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c4283894..96b86a77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" ] \ No newline at end of file diff --git a/tests/integration/test_aiohttp.py b/tests/integration/test_aiohttp.py index 84bfec46..0cd2be11 100644 --- a/tests/integration/test_aiohttp.py +++ b/tests/integration/test_aiohttp.py @@ -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): diff --git a/tests/integration/test_boto.py b/tests/integration/test_boto.py index 08d86505..4040b353 100644 --- a/tests/integration/test_boto.py +++ b/tests/integration/test_boto.py @@ -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): diff --git a/tests/integration/test_boto3.py b/tests/integration/test_boto3.py index 5c2904ae..02a0a03f 100644 --- a/tests/integration/test_boto3.py +++ b/tests/integration/test_boto3.py @@ -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: diff --git a/tests/integration/test_httpx.py b/tests/integration/test_httpx.py index 90c0589d..4b5da550 100644 --- a/tests/integration/test_httpx.py +++ b/tests/integration/test_httpx.py @@ -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: diff --git a/tests/integration/test_requests.py b/tests/integration/test_requests.py index 0ca4e5ab..fb3e6631 100644 --- a/tests/integration/test_requests.py +++ b/tests/integration/test_requests.py @@ -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): diff --git a/tests/integration/test_wild.py b/tests/integration/test_wild.py index 7111c8da..0ae4db05 100644 --- a/tests/integration/test_wild.py +++ b/tests/integration/test_wild.py @@ -7,7 +7,7 @@ requests = pytest.importorskip("requests") -import vcr # NOQA +import vcr def test_domain_redirect(): diff --git a/tests/unit/test_errors.py b/tests/unit/test_errors.py index 62c622a8..c053fee4 100644 --- a/tests/unit/test_errors.py +++ b/tests/unit/test_errors.py @@ -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 diff --git a/tests/unit/test_vcr_import.py b/tests/unit/test_vcr_import.py index e3a8c60d..ba8b53f8 100644 --- a/tests/unit/test_vcr_import.py +++ b/tests/unit/test_vcr_import.py @@ -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 diff --git a/tox.ini b/tox.ini index be389abd..328d3d98 100644 --- a/tox.ini +++ b/tox.ini @@ -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 diff --git a/vcr/__init__.py b/vcr/__init__.py index a48bd464..12e930e3 100644 --- a/vcr/__init__.py +++ b/vcr/__init__.py @@ -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" diff --git a/vcr/_handle_coroutine.py b/vcr/_handle_coroutine.py index 7dc3befc..401b55cf 100644 --- a/vcr/_handle_coroutine.py +++ b/vcr/_handle_coroutine.py @@ -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) diff --git a/vcr/errors.py b/vcr/errors.py index 4a2877e7..74e3e720 100644 --- a/vcr/errors.py +++ b/vcr/errors.py @@ -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) ) diff --git a/vcr/patch.py b/vcr/patch.py index a5ba6fab..e2b335c1 100644 --- a/vcr/patch.py +++ b/vcr/patch.py @@ -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: diff --git a/vcr/stubs/aiohttp_stubs.py b/vcr/stubs/aiohttp_stubs.py index 4541b735..7b8ddc96 100644 --- a/vcr/stubs/aiohttp_stubs.py +++ b/vcr/stubs/aiohttp_stubs.py @@ -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 @@ -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), } @@ -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