gh-91922: Fix sqlite connection on nonstardard locales and paths (GH-92926)

(cherry picked from commit d853758092)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-05-20 02:42:48 -07:00 committed by GitHub
parent 6814ab7907
commit 6ec050f633
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 64 deletions

View file

@ -21,21 +21,19 @@
# 3. This notice may not be removed or altered from any source distribution.
import contextlib
import os
import sqlite3 as sqlite
import subprocess
import sys
import threading
import unittest
import urllib.parse
from test.support import (
SHORT_TIMEOUT,
bigmemtest,
check_disallow_instantiation,
threading_helper,
)
from test.support import SHORT_TIMEOUT, bigmemtest, check_disallow_instantiation
from test.support import threading_helper
from _testcapi import INT_MAX, ULLONG_MAX
from os import SEEK_SET, SEEK_CUR, SEEK_END
from test.support.os_helper import TESTFN, unlink, temp_dir
from test.support.os_helper import TESTFN, TESTFN_UNDECODABLE, unlink, temp_dir, FakePath
# Helper for tests using TESTFN
@ -663,11 +661,19 @@ class OpenTests(unittest.TestCase):
def test_open_with_path_like_object(self):
""" Checks that we can successfully connect to a database using an object that
is PathLike, i.e. has __fspath__(). """
class Path:
def __fspath__(self):
return TESTFN
path = Path()
path = FakePath(TESTFN)
with managed_connect(path) as cx:
self.assertTrue(os.path.exists(path))
cx.execute(self._sql)
@unittest.skipIf(sys.platform == "win32", "skipped on Windows")
@unittest.skipIf(sys.platform == "darwin", "skipped on macOS")
@unittest.skipUnless(TESTFN_UNDECODABLE, "only works if there are undecodable paths")
def test_open_with_undecodable_path(self):
self.addCleanup(unlink, TESTFN_UNDECODABLE)
path = TESTFN_UNDECODABLE
with managed_connect(path) as cx:
self.assertTrue(os.path.exists(path))
cx.execute(self._sql)
def test_open_uri(self):