Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
insolor committed Jul 13, 2024
1 parent 72d8b60 commit 464f5e6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions alternative_encodings/common.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import codecs
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Union

if TYPE_CHECKING:
from _codecs import _EncodingMap # noqa: TCH004
from _codecs import _EncodingMap


def get_codec(encoding_table: dict[int, int] | _EncodingMap, decoding_table: str) -> type[codecs.Codec]:
def get_codec(encoding_table: Union[dict[int, int], "_EncodingMap"], decoding_table: str) -> type[codecs.Codec]:
class Codec(codecs.Codec):
def encode(self, input_string: str, errors: str = "strict") -> tuple[bytes, int]:
return codecs.charmap_encode(input_string, errors, encoding_table)
Expand All @@ -16,7 +16,7 @@ def decode(self, input_bytes: bytes, errors: str = "strict") -> tuple[str, int]:
return Codec


def get_incremental_encoder(encoding_table: dict[int, int] | _EncodingMap) -> type[codecs.IncrementalEncoder]:
def get_incremental_encoder(encoding_table: Union[dict[int, int], "_EncodingMap"]) -> type[codecs.IncrementalEncoder]:
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input_string: str, _final: bool = False) -> bytes: # noqa: FBT001, FBT002
return codecs.charmap_encode(input_string, self.errors, encoding_table)[0]
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cp859.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from collections.abc import Generator

import pytest
from utils import register_codec

from alternative_encodings import cp859

from .utils import register_codec


@pytest.fixture(scope="module", autouse=True)
def _register_codec_fixture() -> Generator[None, None, None]:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cp866i.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from collections.abc import Generator

import pytest
from utils import register_codec

from alternative_encodings import cp866i

from .utils import register_codec


@pytest.fixture(scope="module", autouse=True)
def _register_codec_fixture() -> Generator[None, None, None]:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_general.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import codecs

import pytest
from utils import register_codec

from alternative_encodings import cp859, cp866i, viscii

from .utils import register_codec

codecs_pairs = [
("cp859", cp859),
("cp866i", cp866i),
Expand Down
3 changes: 2 additions & 1 deletion tests/test_romaji.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from collections.abc import Generator

import pytest
from utils import register_codec

from alternative_encodings import romaji

from .utils import register_codec


@pytest.fixture(scope="module", autouse=True)
def _register_codec_fixture() -> Generator[None, None, None]:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_viscii.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from collections.abc import Generator

import pytest
from utils import register_codec

from alternative_encodings import viscii

from .utils import register_codec


@pytest.fixture(scope="module", autouse=True)
def _register_codec_fixture() -> Generator[None, None, None]:
Expand Down

0 comments on commit 464f5e6

Please sign in to comment.