@@ -48,6 +48,12 @@ def _gen_resourcetxt_path_parts(self):
48
48
with self .subTest (path_parts = path_parts ):
49
49
yield path_parts
50
50
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
+
51
57
def test_read_text (self ):
52
58
self .assertEqual (
53
59
resources .read_text (self .anchor01 , 'utf-8.file' ),
@@ -88,13 +94,13 @@ def test_read_text(self):
88
94
),
89
95
'\x00 \x01 \x02 \x03 ' ,
90
96
)
91
- self .assertEqual (
97
+ self .assertEndsWith ( # ignore the BOM
92
98
resources .read_text (
93
99
self .anchor01 ,
94
100
'utf-16.file' ,
95
101
errors = 'backslashreplace' ,
96
102
),
97
- 'Hello, UTF-16 world!\n ' .encode ('utf-16' ).decode (
103
+ 'Hello, UTF-16 world!\n ' .encode ('utf-16-le ' ).decode (
98
104
errors = 'backslashreplace' ,
99
105
),
100
106
)
@@ -140,9 +146,9 @@ def test_open_text(self):
140
146
'utf-16.file' ,
141
147
errors = 'backslashreplace' ,
142
148
) as f :
143
- self .assertEqual (
149
+ self .assertEndsWith ( # ignore the BOM
144
150
f .read (),
145
- 'Hello, UTF-16 world!\n ' .encode ('utf-16' ).decode (
151
+ 'Hello, UTF-16 world!\n ' .encode ('utf-16-le ' ).decode (
146
152
errors = 'backslashreplace' ,
147
153
),
148
154
)
0 commit comments