Skip to content

Commit

Permalink
Fix failing test for latest Ruff version (#284)
Browse files Browse the repository at this point in the history
fixes: #282
  • Loading branch information
dhruvmanila authored Oct 17, 2023
1 parent b033e6a commit af6cf02
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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())
Expand Down Expand Up @@ -73,7 +91,7 @@ def _handler(params):
},
"data": {
"fix": {
"applicability": "Automatic",
"applicability": applicability.safe,
"edits": [
{
"content": "",
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -168,7 +187,7 @@ def _handler(params):
},
"data": {
"fix": {
"applicability": "Automatic",
"applicability": applicability.safe,
"edits": [
{
"content": "",
Expand Down

0 comments on commit af6cf02

Please sign in to comment.