summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sqlite3
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-05-21 14:38:22 (GMT)
committerGitHub <noreply@github.com>2022-05-21 14:38:22 (GMT)
commit4e2b66489289cfd4db2a02edf173ac03cbb2fffe (patch)
tree83e141dff477985b8695b8dcc56e7bedaa04b42d /Lib/test/test_sqlite3
parent5b71b519f966e1017c868ea2b27c61a5eac38c1f (diff)
downloadcpython-4e2b66489289cfd4db2a02edf173ac03cbb2fffe.zip
cpython-4e2b66489289cfd4db2a02edf173ac03cbb2fffe.tar.gz
cpython-4e2b66489289cfd4db2a02edf173ac03cbb2fffe.tar.bz2
Improve tests for opening Sqlite by URI (GH-93047)
* Test with with escaped non-ascii characters * Test read-only open of existing DB.
Diffstat (limited to 'Lib/test/test_sqlite3')
-rw-r--r--Lib/test/test_sqlite3/test_dbapi.py47
1 files changed, 42 insertions, 5 deletions
diff --git a/Lib/test/test_sqlite3/test_dbapi.py b/Lib/test/test_sqlite3/test_dbapi.py
index f0c009a..744c4ad 100644
--- a/Lib/test/test_sqlite3/test_dbapi.py
+++ b/Lib/test/test_sqlite3/test_dbapi.py
@@ -661,21 +661,58 @@ class OpenTests(unittest.TestCase):
@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.addCleanup(unlink, path)
+ with managed_connect(path, in_mem=True) as cx:
self.assertTrue(os.path.exists(path))
cx.execute(self._sql)
def test_open_uri(self):
- with managed_connect(TESTFN) as cx:
+ path = TESTFN
+ uri = "file:" + urllib.parse.quote(os.fsencode(path))
+ self.assertFalse(os.path.exists(path))
+ with managed_connect(uri, uri=True) as cx:
+ self.assertTrue(os.path.exists(path))
cx.execute(self._sql)
- with managed_connect(f"file:{TESTFN}", uri=True) as cx:
+
+ def test_open_unquoted_uri(self):
+ path = TESTFN
+ uri = "file:" + path
+ self.assertFalse(os.path.exists(path))
+ with managed_connect(uri, uri=True) as cx:
+ self.assertTrue(os.path.exists(path))
cx.execute(self._sql)
+
+ def test_open_uri_readonly(self):
+ path = TESTFN
+ self.addCleanup(unlink, path)
+ uri = "file:" + urllib.parse.quote(os.fsencode(path)) + "?mode=ro"
+ self.assertFalse(os.path.exists(path))
+ # Cannot create new DB
with self.assertRaises(sqlite.OperationalError):
- with managed_connect(f"file:{TESTFN}?mode=ro", uri=True) as cx:
+ sqlite.connect(uri, uri=True)
+ self.assertFalse(os.path.exists(path))
+ sqlite.connect(path).close()
+ self.assertTrue(os.path.exists(path))
+ # Cannot modify new DB
+ with managed_connect(uri, uri=True) as cx:
+ with self.assertRaises(sqlite.OperationalError):
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_undecodable_uri(self):
+ path = TESTFN_UNDECODABLE
+ uri = "file:" + urllib.parse.quote(path)
+ self.assertFalse(os.path.exists(path))
+ try:
+ with managed_connect(uri, uri=True, in_mem=True) as cx:
+ self.assertTrue(os.path.exists(path))
+ cx.execute(self._sql)
+ finally:
+ unlink(path)
+
def test_factory_database_arg(self):
def factory(database, *args, **kwargs):
nonlocal database_arg