@@ -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 )
0 commit comments