Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 54 additions & 4 deletions test_iconvcodec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@


class TestIconvcodecModule(unittest.TestCase):
@unittest.skipUnless(sys.platform.startswith("linux"), "Linux only test")
def test_encode(self):
bytestring = "Hallo".encode("T.61")
bytestring = "Hallo".encode("VISCII")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we switch, VISCII is not provided by CPython, and seems to be more cross-platform than T.61.

self.assertEqual(bytestring, b"Hallo")

def test_encode_with_long_out(self):
Expand All @@ -18,9 +17,8 @@ def test_encode_with_long_out(self):
else:
self.assertEqual(bytestring, b"TM")

@unittest.skipUnless(sys.platform.startswith("linux"), "Linux only test")
def test_decode(self):
string = b"Hallo".decode("T.61")
string = b"Hallo".decode("VISCII")
self.assertEqual(string, "Hallo")

@unittest.skipUnless(sys.platform.startswith("linux"), "Linux only test")
Expand All @@ -45,3 +43,55 @@ def test_incremental_decode(self):

self.assertEqual(first, "")
self.assertEqual(second, "\u0141")

def test_available_encodings(self):
# Some from the list on https://www.gnu.org/software/libiconv/
encodings = (
*[f"ISO-8859-{i}" for i in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16)],
*[
f"CP{i}"
for i in (
437,
737,
775,
852,
855,
857,
858,
860,
861,
862,
863,
865,
869,
1125,
1133,
1250,
1251,
1252,
1253,
1254,
1257,
)
],
# "Georgian-PS",
# "ARMSCII-8",
"KOI8-T",
"PT154",
"RK1048",
"VISCII",
"TCVN",
"Macintosh",
)
for encoding in encodings:
with self.subTest(encoding=encoding):
codec_info = iconvcodec.lookup(encoding)
if codec_info is None:
self.fail(f"Unsupported codec: '{encoding}'")
# Actually test that encoding works
try:
"a".encode(encoding)
except Exception as e:
raise AssertionError(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use self.fail here as well?

f"Codec lookup succeeded but encode failed for '{encoding}'"
) from None