Skip to content

Commit 57d6db5

Browse files
[3.14] pythongh-136289: Fix test_sqlite3 on platforms with strict UTF-8 filesystem (pythonGH-136326) (pythonGH-136350)
(cherry picked from commit 85b817d) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 41d1683 commit 57d6db5

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
import warnings
3232

3333
from test.support import (
34-
SHORT_TIMEOUT, check_disallow_instantiation, requires_subprocess,
35-
is_apple, is_emscripten, is_wasi
34+
SHORT_TIMEOUT, check_disallow_instantiation, requires_subprocess
3635
)
3736
from test.support import gc_collect
3837
from test.support import threading_helper, import_helper
@@ -649,14 +648,21 @@ def test_open_with_path_like_object(self):
649648
self.assertTrue(os.path.exists(path))
650649
cx.execute(self._sql)
651650

651+
def get_undecodable_path(self):
652+
path = TESTFN_UNDECODABLE
653+
if not path:
654+
self.skipTest("only works if there are undecodable paths")
655+
try:
656+
open(path, 'wb').close()
657+
except OSError:
658+
self.skipTest(f"can't create file with undecodable path {path!r}")
659+
unlink(path)
660+
return path
661+
652662
@unittest.skipIf(sys.platform == "win32", "skipped on Windows")
653-
@unittest.skipIf(is_apple, "skipped on Apple platforms")
654-
@unittest.skipIf(is_emscripten or is_wasi, "not supported on Emscripten/WASI")
655-
@unittest.skipUnless(TESTFN_UNDECODABLE, "only works if there are undecodable paths")
656663
def test_open_with_undecodable_path(self):
657-
path = TESTFN_UNDECODABLE
664+
path = self.get_undecodable_path()
658665
self.addCleanup(unlink, path)
659-
self.assertFalse(os.path.exists(path))
660666
with contextlib.closing(sqlite.connect(path)) as cx:
661667
self.assertTrue(os.path.exists(path))
662668
cx.execute(self._sql)
@@ -696,14 +702,10 @@ def test_open_uri_readonly(self):
696702
cx.execute(self._sql)
697703

698704
@unittest.skipIf(sys.platform == "win32", "skipped on Windows")
699-
@unittest.skipIf(is_apple, "skipped on Apple platforms")
700-
@unittest.skipIf(is_emscripten or is_wasi, "not supported on Emscripten/WASI")
701-
@unittest.skipUnless(TESTFN_UNDECODABLE, "only works if there are undecodable paths")
702705
def test_open_undecodable_uri(self):
703-
path = TESTFN_UNDECODABLE
706+
path = self.get_undecodable_path()
704707
self.addCleanup(unlink, path)
705708
uri = "file:" + urllib.parse.quote(path)
706-
self.assertFalse(os.path.exists(path))
707709
with contextlib.closing(sqlite.connect(uri, uri=True)) as cx:
708710
self.assertTrue(os.path.exists(path))
709711
cx.execute(self._sql)

0 commit comments

Comments
 (0)