Skip to content

Commit 574184c

Browse files
committed
fix tests
1 parent 47d50b8 commit 574184c

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

Lib/test/test_ctypes/test_dlerror.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import _ctypes
21
import os
32
import platform
43
import re
@@ -123,16 +122,27 @@ def test_null_dlsym(self):
123122
self.assertEqual(os.read(pipe_r, 2), b'OK')
124123

125124

126-
class TestCAPI(unittest.TestCase):
127-
128-
@unittest.skipUnless(hasattr(_ctypes, 'dlopen'), 'require ctypes.dlopen()')
129-
@test.support.run_with_locales('LC_ALL', 'fr_FR.utf8', 'fr_FR.iso88591')
125+
@unittest.skipUnless(sys.platform.startswith('linux'),
126+
'test requires _ctypes.dlopen()')
127+
class TestLinuxLocalization(unittest.TestCase):
128+
129+
@test.support.run_with_locale(
130+
'LC_ALL',
131+
'fr_FR.iso88591', 'ja_JP.sjis', 'zh_CN.gbk',
132+
'',
133+
)
130134
def test_localized_error(self):
131-
with self.assertRaisesRegex(
132-
OSError,
133-
re.escape("foo.so: Ne peut ouvrir le fichier d'objet partagé"),
134-
):
135-
_ctypes.dlopen('foo.so', 2)
135+
# An ImportError would be propagated and would be unexpected on Linux.
136+
from _ctypes import dlopen
137+
138+
missing_filename = b'missing\xff.so'
139+
# Depending whether the locale is ISO-88591 or not, we may either
140+
# encode '\xff' as '\udcff' or 'ÿ', but we are only interested in
141+
# avoiding a UnicodeDecodeError when reporting the dlerror() error
142+
# message which contains the localized filename.
143+
filename_pattern = r'missing[ÿ|\udcff].so:.+'
144+
with self.assertRaisesRegex(OSError, filename_pattern):
145+
dlopen(missing_filename, 2)
136146

137147

138148
if __name__ == "__main__":

Lib/test/test_dbm_gnu.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from test import support
22
from test.support import import_helper, cpython_only
33
gdbm = import_helper.import_module("dbm.gnu") #skip if not supported
4-
import re
54
import unittest
65
import os
7-
from test.support.os_helper import (TESTFN, TESTFN_NONASCII,
8-
create_empty_file, unlink, FakePath)
6+
from test.support.os_helper import (TESTFN, TESTFN_NONASCII, FakePath,
7+
create_empty_file, temp_dir, unlink)
98

109

1110
filename = TESTFN
@@ -207,11 +206,16 @@ def test_clear(self):
207206
self.assertNotIn(k, db)
208207
self.assertEqual(len(db), 0)
209208

210-
@support.run_with_locales('LC_ALL', 'fr_FR.UTF-8', 'fr_FR.iso88591')
209+
@support.run_with_locale(
210+
'LC_ALL',
211+
'fr_FR.iso88591', 'ja_JP.sjis', 'zh_CN.gbk',
212+
'',
213+
)
211214
def test_localized_error(self):
212-
expect = re.escape('Base de données vide')
213-
empty = create_empty_file(filename)
214-
self.assertRaisesRegex(gdbm.error, expect, gdbm.open, filename, 'r')
215+
with temp_dir() as d:
216+
filename = os.path.join(os.fsencode(d), b'\xff')
217+
create_empty_file(filename)
218+
self.assertRaises(gdbm.error, gdbm.open, filename, 'r')
215219

216220

217221
if __name__ == '__main__':

0 commit comments

Comments
 (0)