diff --git a/test_iconvcodec.py b/test_iconvcodec.py index aaa5bc9..97d206c 100644 --- a/test_iconvcodec.py +++ b/test_iconvcodec.py @@ -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") self.assertEqual(bytestring, b"Hallo") def test_encode_with_long_out(self): @@ -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") @@ -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( + f"Codec lookup succeeded but encode failed for '{encoding}'" + ) from None