Skip to content

Commit ca5f0e1

Browse files
committed
Merge fix for UTF-16 bom handling in tests.
Closes #312. Closes #313. Ref python/cpython#117569
2 parents 0fcdaab + b44af23 commit ca5f0e1

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

importlib_resources/tests/test_functional.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ def _gen_resourcetxt_path_parts(self):
4848
with self.subTest(path_parts=path_parts):
4949
yield path_parts
5050

51+
def assertEndsWith(self, string, suffix):
52+
"""Assert that `string` ends with `suffix`.
53+
54+
Used to ignore an architecture-specific UTF-16 byte-order mark."""
55+
self.assertEqual(string[-len(suffix) :], suffix)
56+
5157
def test_read_text(self):
5258
self.assertEqual(
5359
resources.read_text(self.anchor01, 'utf-8.file'),
@@ -88,13 +94,13 @@ def test_read_text(self):
8894
),
8995
'\x00\x01\x02\x03',
9096
)
91-
self.assertEqual(
97+
self.assertEndsWith( # ignore the BOM
9298
resources.read_text(
9399
self.anchor01,
94100
'utf-16.file',
95101
errors='backslashreplace',
96102
),
97-
'Hello, UTF-16 world!\n'.encode('utf-16').decode(
103+
'Hello, UTF-16 world!\n'.encode('utf-16-le').decode(
98104
errors='backslashreplace',
99105
),
100106
)
@@ -140,9 +146,9 @@ def test_open_text(self):
140146
'utf-16.file',
141147
errors='backslashreplace',
142148
) as f:
143-
self.assertEqual(
149+
self.assertEndsWith( # ignore the BOM
144150
f.read(),
145-
'Hello, UTF-16 world!\n'.encode('utf-16').decode(
151+
'Hello, UTF-16 world!\n'.encode('utf-16-le').decode(
146152
errors='backslashreplace',
147153
),
148154
)

newsfragments/312.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Merged fix for UTF-16 BOM handling in functional tests.

0 commit comments

Comments
 (0)