Skip to content

Commit 47d50b8

Browse files
committed
add tests for dlerror and gdbm_* functions
1 parent b02a715 commit 47d50b8

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Lib/test/test_ctypes/test_dlerror.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import _ctypes
12
import os
3+
import platform
4+
import re
25
import sys
6+
import test.support
37
import unittest
4-
import platform
8+
59

610
FOO_C = r"""
711
#include <unistd.h>
@@ -119,5 +123,17 @@ def test_null_dlsym(self):
119123
self.assertEqual(os.read(pipe_r, 2), b'OK')
120124

121125

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')
130+
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)
136+
137+
122138
if __name__ == "__main__":
123139
unittest.main()

Lib/test/test_dbm_gnu.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
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
45
import unittest
56
import os
6-
from test.support.os_helper import TESTFN, TESTFN_NONASCII, unlink, FakePath
7+
from test.support.os_helper import (TESTFN, TESTFN_NONASCII,
8+
create_empty_file, unlink, FakePath)
79

810

911
filename = TESTFN
@@ -205,6 +207,11 @@ def test_clear(self):
205207
self.assertNotIn(k, db)
206208
self.assertEqual(len(db), 0)
207209

210+
@support.run_with_locales('LC_ALL', 'fr_FR.UTF-8', 'fr_FR.iso88591')
211+
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')
208215

209216

210217
if __name__ == '__main__':

0 commit comments

Comments
 (0)