Skip to content

Commit

Permalink
Merge fix for UTF-16 bom handling in tests.
Browse files Browse the repository at this point in the history
Closes #312. Closes #313. Ref python/cpython#117569
  • Loading branch information
jaraco committed Aug 14, 2024
2 parents 0fcdaab + b44af23 commit ca5f0e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions importlib_resources/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ def _gen_resourcetxt_path_parts(self):
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'),
Expand Down Expand Up @@ -88,13 +94,13 @@ def test_read_text(self):
),
'\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',
),
)
Expand Down Expand Up @@ -140,9 +146,9 @@ def test_open_text(self):
'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',
),
)
Expand Down
1 change: 1 addition & 0 deletions newsfragments/312.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Merged fix for UTF-16 BOM handling in functional tests.

0 comments on commit ca5f0e1

Please sign in to comment.