From fd1b0e1702029db0b958e5ea12d46f90e4872ae1 Mon Sep 17 00:00:00 2001 From: Hugo Herter Date: Thu, 13 Jun 2024 16:13:55 +0200 Subject: [PATCH] Fix: Ruff did not check code quality Solution: Add ruff to check the code quality and fix the reported errors. --- pyproject.toml | 9 +++++---- tests/unit/conftest.py | 6 ++---- tests/unit/test_domains.py | 4 ++-- tests/unit/test_download.py | 1 - tests/unit/test_wallet_ethereum.py | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f21f7ece..63fa6d35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -141,19 +141,19 @@ dependencies = [ "black==24.2.0", "mypy==1.9.0", "mypy-extensions==1.0.0", - # "ruff==0.1.15", + "ruff==0.4.8", "isort==5.13.2", ] [tool.hatch.envs.linting.scripts] typing = "mypy --config-file=pyproject.toml {args:} ./src/ ./tests/ ./examples/" style = [ - # "ruff {args:.}", + "ruff {args:.} ./src/ ./tests/ ./examples/", "black --check --diff {args:} ./src/ ./tests/ ./examples/", "isort --check-only --profile black {args:} ./src/ ./tests/ ./examples/", ] fmt = [ "black {args:} ./src/ ./tests/ ./examples/", - # "ruff --fix {args:.}", + "ruff --fix {args:.} ./src/ ./tests/ ./examples/", "isort --profile black {args:} ./src/ ./tests/ ./examples/", "style", ] @@ -169,6 +169,7 @@ exclude = [ "conftest.py" ] show_column_numbers = true +check_untyped_defs = true # Import discovery # Install types for third-party library stubs (e.g. from typeshed repository) @@ -231,4 +232,4 @@ exclude_lines = [ # Don't complain about ineffective code: "pass", -] \ No newline at end of file +] diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index a5d2d481..4b06c243 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -1,4 +1,6 @@ +import asyncio import json +from functools import wraps from io import BytesIO from pathlib import Path from tempfile import NamedTemporaryFile @@ -196,10 +198,6 @@ def mock_session_with_post_success( return client -import asyncio -from functools import wraps - - def async_wrap(cls): class AsyncWrapper: def __init__(self, *args, **kwargs): diff --git a/tests/unit/test_domains.py b/tests/unit/test_domains.py index 380e4bb5..eadfcec1 100644 --- a/tests/unit/test_domains.py +++ b/tests/unit/test_domains.py @@ -47,7 +47,7 @@ async def test_configured_domain(): url = "https://custom-domain-unit-test.aleph.sh" hostname = hostname_from_url(url) status = await alephdns.check_domain(hostname, TargetType.IPFS, "0xfakeaddress") - assert type(status) is dict + assert isinstance(status, dict) @pytest.mark.asyncio @@ -57,4 +57,4 @@ async def test_not_configured_domain(): hostname = hostname_from_url(url) with pytest.raises(DomainConfigurationError): status = await alephdns.check_domain(hostname, TargetType.IPFS, "0xfakeaddress") - assert type(status) is None + assert status is None diff --git a/tests/unit/test_download.py b/tests/unit/test_download.py index ffffae74..a889949d 100644 --- a/tests/unit/test_download.py +++ b/tests/unit/test_download.py @@ -1,6 +1,5 @@ import tempfile from pathlib import Path -from unittest.mock import AsyncMock, patch import pytest diff --git a/tests/unit/test_wallet_ethereum.py b/tests/unit/test_wallet_ethereum.py index 0f798c9d..f7ca2157 100644 --- a/tests/unit/test_wallet_ethereum.py +++ b/tests/unit/test_wallet_ethereum.py @@ -23,7 +23,7 @@ async def test_ledger_eth_account(): address = account.get_address() assert address - assert type(address) is str + assert isinstance(address, str) assert len(address) == 42 message = Message("ETH", account.get_address(), "SomeType", "ItemHash")