From af6cf02804a55ba48592fc539a267b2f737675b4 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Tue, 17 Oct 2023 19:25:10 +0530 Subject: [PATCH] Fix failing test for latest Ruff version (#284) fixes: #282 --- tests/test_server.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/test_server.py b/tests/test_server.py index 3c0d0be..71134ef 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -3,9 +3,11 @@ import os import tempfile +from dataclasses import dataclass from threading import Event from packaging.version import Version +from typing_extensions import Self from tests.client import defaults, session, utils @@ -18,6 +20,21 @@ """ VERSION_REQUIREMENT_ASTRAL_DOCS = Version("0.0.291") +VERSION_REQUIREMENT_APPLICABILITY_RENAME = Version("0.1.0") + + +@dataclass(frozen=True) +class Applicability: + safe: str + unsafe: str + display: str + + @classmethod + def from_ruff_version(cls, ruff_version: Version) -> Self: + if ruff_version >= VERSION_REQUIREMENT_APPLICABILITY_RENAME: + return cls(safe="safe", unsafe="unsafe", display="display") + else: + return cls(safe="Automatic", unsafe="Suggested", display="Manual") class TestServer: @@ -29,6 +46,7 @@ def test_linting_example(self, ruff_version: Version) -> None: if ruff_version >= VERSION_REQUIREMENT_ASTRAL_DOCS else "https://beta.ruff.rs/docs/" ) + applicability = Applicability.from_ruff_version(ruff_version) with tempfile.NamedTemporaryFile(suffix=".py") as fp: fp.write(CONTENTS.encode()) @@ -73,7 +91,7 @@ def _handler(params): }, "data": { "fix": { - "applicability": "Automatic", + "applicability": applicability.safe, "edits": [ { "content": "", @@ -119,6 +137,7 @@ def test_no_initialization_options(self, ruff_version: Version) -> None: if ruff_version >= VERSION_REQUIREMENT_ASTRAL_DOCS else "https://beta.ruff.rs/docs/" ) + applicability = Applicability.from_ruff_version(ruff_version) with tempfile.NamedTemporaryFile(suffix=".py") as fp: fp.write(CONTENTS.encode()) @@ -168,7 +187,7 @@ def _handler(params): }, "data": { "fix": { - "applicability": "Automatic", + "applicability": applicability.safe, "edits": [ { "content": "",