diff options
author | Petr Viktorin <encukou@gmail.com> | 2024-04-05 15:00:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-05 15:00:29 (GMT) |
commit | 4d4a6f1b6aea6dae131ac116f1735a38c3e32cd1 (patch) | |
tree | 01315985ca13318fca0d1db53934879cc20ea2e0 | |
parent | 687616877ba540a44f82ff764b5f13d36c0f3910 (diff) | |
download | cpython-4d4a6f1b6aea6dae131ac116f1735a38c3e32cd1.zip cpython-4d4a6f1b6aea6dae131ac116f1735a38c3e32cd1.tar.gz cpython-4d4a6f1b6aea6dae131ac116f1735a38c3e32cd1.tar.bz2 |
gh-116608: Ignore UTF-16 BOM in importlib.resources._functional tests (GH-117569)
gh-116609: Ignore UTF-16 BOM in importlib.resources._functional tests
To test the `errors` argument, we read a UTF-16 file as UTF-8
with "backslashreplace" error handling. However, the utf-16
codec adds an endian-specific byte-order mark, so on big-endian
machines the expectation doesn't match the test file (which was
saved on a little-endian machine).
Use endswith to ignore the BOM.
-rw-r--r-- | Lib/test/test_importlib/resources/test_functional.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Lib/test/test_importlib/resources/test_functional.py b/Lib/test/test_importlib/resources/test_functional.py index fd02fc7..d60a2be 100644 --- a/Lib/test/test_importlib/resources/test_functional.py +++ b/Lib/test/test_importlib/resources/test_functional.py @@ -32,6 +32,12 @@ class FunctionalAPIBase: with self.subTest(path_parts=path_parts): yield path_parts + def assertEndsWith(self, string, suffix): + """Assert that `string` ends with `suffix`. + + Used to ignore an architecture-specific UTF-16 byte-order mark.""" + self.assertEqual(string[-len(suffix):], suffix) + def test_read_text(self): self.assertEqual( resources.read_text(self.anchor01, 'utf-8.file'), @@ -65,12 +71,12 @@ class FunctionalAPIBase: ), '\x00\x01\x02\x03', ) - self.assertEqual( + self.assertEndsWith( # ignore the BOM resources.read_text( self.anchor01, 'utf-16.file', errors='backslashreplace', ), - 'Hello, UTF-16 world!\n'.encode('utf-16').decode( + 'Hello, UTF-16 world!\n'.encode('utf-16-le').decode( errors='backslashreplace', ), ) @@ -112,9 +118,9 @@ class FunctionalAPIBase: self.anchor01, 'utf-16.file', errors='backslashreplace', ) as f: - self.assertEqual( + self.assertEndsWith( # ignore the BOM f.read(), - 'Hello, UTF-16 world!\n'.encode('utf-16').decode( + 'Hello, UTF-16 world!\n'.encode('utf-16-le').decode( errors='backslashreplace', ), ) |