Skip to content

Commit

Permalink
Add general test
Browse files Browse the repository at this point in the history
  • Loading branch information
insolor committed Apr 2, 2024
1 parent 9817cfc commit deb5031
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
8 changes: 1 addition & 7 deletions alternative_encodings/viscii.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import codecs

from .common import (
get_codec,
get_incremental_decoder,
get_incremental_encoder,
get_stream_reader,
get_stream_writer,
)
from .common import get_codec, get_incremental_decoder, get_incremental_encoder, get_stream_reader, get_stream_writer

# Decoding Table

Expand Down
10 changes: 8 additions & 2 deletions tests/test_cp859.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from utils import register_codec

import alternative_encodings.cp859 as cp859
from alternative_encodings import cp859


@pytest.fixture(scope="module", autouse=True)
Expand All @@ -24,6 +24,12 @@ def register_codec_fixture():
)


def test_encode():
@pytest.mark.parametrize("source_data, encoded",
[
(source_data, encoded),
('\r\n', b'\r\n'),
]
)
def test_encode(source_data, encoded):
assert codecs.encode(source_data, "cp859") == encoded
assert codecs.decode(encoded, "cp859") == source_data
2 changes: 1 addition & 1 deletion tests/test_cp866i.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from utils import register_codec

import alternative_encodings.cp866i as cp866i
from alternative_encodings import cp866i


@pytest.fixture(scope="module", autouse=True)
Expand Down
25 changes: 25 additions & 0 deletions tests/test_general.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import codecs

import pytest
from utils import register_codec

from alternative_encodings import cp859, cp866i, viscii

codecs_pairs = [
("cp859", cp859),
("cp866i", cp866i),
("viscii", viscii),
]


@pytest.mark.parametrize("string",
[
"\r\n",
]
)
def test_general(string):
for codec_name, codec in codecs_pairs:
with register_codec(codec):
encoded = codecs.encode(string, encoding=codec_name)
decoded = codecs.decode(encoded, encoding=codec_name)
assert decoded == string
2 changes: 1 addition & 1 deletion tests/test_viscii.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from utils import register_codec

import alternative_encodings.viscii as viscii
from alternative_encodings import viscii


@pytest.fixture(scope="module", autouse=True)
Expand Down

0 comments on commit deb5031

Please sign in to comment.