Skip to content

Commit

Permalink
Fix functional API tests to be endian-agnostic
Browse files Browse the repository at this point in the history
Fix the "backslashreplace" tests for the functional API to be
endian-agnostic.  The tests used to rely on `.encode("utf-16")`
producing the same data as found in the test file.  However, on big
endian platforms it would produce a big endian encoding, while the test
file is little endian.  To avoid the problem, explicitly specify
`utf-16-le` encoding.  Since this meant that the BOM is no longer
produced, explicitly include it in input.

Fixes python#312
  • Loading branch information
mgorny committed Jul 10, 2024
1 parent be5a270 commit 3167e4b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions importlib_resources/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_read_text(self):
'utf-16.file',
errors='backslashreplace',
),
'Hello, UTF-16 world!\n'.encode('utf-16').decode(
'\ufeffHello, UTF-16 world!\n'.encode('utf-16-le').decode(
errors='backslashreplace',
),
)
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_open_text(self):
) as f:
self.assertEqual(
f.read(),
'Hello, UTF-16 world!\n'.encode('utf-16').decode(
'\ufeffHello, UTF-16 world!\n'.encode('utf-16-le').decode(
errors='backslashreplace',
),
)
Expand Down

0 comments on commit 3167e4b

Please sign in to comment.