Skip to content

Commit 4f24dc0

Browse files
[3.13] pythongh-136289: Fix test_sqlite3 on platforms with strict UTF-8 filesystem (pythonGH-136326) (pythonGH-136351)
(cherry picked from commit 85b817d) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 0467b1f commit 4f24dc0

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
@@ -671,14 +670,21 @@ def test_open_with_path_like_object(self):
671670
self.assertTrue(os.path.exists(path))
672671
cx.execute(self._sql)
673672

673+
def get_undecodable_path(self):
674+
path = TESTFN_UNDECODABLE
675+
if not path:
676+
self.skipTest("only works if there are undecodable paths")
677+
try:
678+
open(path, 'wb').close()
679+
except OSError:
680+
self.skipTest(f"can't create file with undecodable path {path!r}")
681+
unlink(path)
682+
return path
683+
674684
@unittest.skipIf(sys.platform == "win32", "skipped on Windows")
675-
@unittest.skipIf(is_apple, "skipped on Apple platforms")
676-
@unittest.skipIf(is_emscripten or is_wasi, "not supported on Emscripten/WASI")
677-
@unittest.skipUnless(TESTFN_UNDECODABLE, "only works if there are undecodable paths")
678685
def test_open_with_undecodable_path(self):
679-
path = TESTFN_UNDECODABLE
686+
path = self.get_undecodable_path()
680687
self.addCleanup(unlink, path)
681-
self.assertFalse(os.path.exists(path))
682688
with contextlib.closing(sqlite.connect(path)) as cx:
683689
self.assertTrue(os.path.exists(path))
684690
cx.execute(self._sql)
@@ -718,14 +724,10 @@ def test_open_uri_readonly(self):
718724
cx.execute(self._sql)
719725

720726
@unittest.skipIf(sys.platform == "win32", "skipped on Windows")
721-
@unittest.skipIf(is_apple, "skipped on Apple platforms")
722-
@unittest.skipIf(is_emscripten or is_wasi, "not supported on Emscripten/WASI")
723-
@unittest.skipUnless(TESTFN_UNDECODABLE, "only works if there are undecodable paths")
724727
def test_open_undecodable_uri(self):
725-
path = TESTFN_UNDECODABLE
728+
path = self.get_undecodable_path()
726729
self.addCleanup(unlink, path)
727730
uri = "file:" + urllib.parse.quote(path)
728-
self.assertFalse(os.path.exists(path))
729731
with contextlib.closing(sqlite.connect(uri, uri=True)) as cx:
730732
self.assertTrue(os.path.exists(path))
731733
cx.execute(self._sql)

0 commit comments

Comments
 (0)