diff Lib/sqlite3/test/dbapi.py @ 82113:f13bb1e40fbc

Issue #13773: sqlite3.connect() gets a new `uri` parameter to pass the filename as a URI, allowing to pass custom options.
author Antoine Pitrou <solipsis@pitrou.net>
date Sun, 10 Feb 2013 00:02:44 +0100
parents d2ab2e4ce3ae
children 8d28d44f3a9a
line wrap: on
line diff
--- a/Lib/sqlite3/test/dbapi.py	Sat Feb 09 23:16:51 2013 +0100
+++ b/Lib/sqlite3/test/dbapi.py	Sun Feb 10 00:02:44 2013 +0100
@@ -28,6 +28,9 @@
 except ImportError:
     threading = None
 
+from test.support import TESTFN, unlink
+
+
 class ModuleTests(unittest.TestCase):
     def CheckAPILevel(self):
         self.assertEqual(sqlite.apilevel, "2.0",
@@ -163,6 +166,21 @@
         with self.assertRaises(AttributeError):
             self.cx.in_transaction = True
 
+    def CheckOpenUri(self):
+        if sqlite.sqlite_version_info < (3, 7, 7):
+            with self.assertRaises(sqlite.NotSupportedError):
+                sqlite.connect(':memory:', uri=True)
+            return
+        self.addCleanup(unlink, TESTFN)
+        with sqlite.connect(TESTFN) as cx:
+            cx.execute('create table test(id integer)')
+        with sqlite.connect('file:' + TESTFN, uri=True) as cx:
+            cx.execute('insert into test(id) values(0)')
+        with sqlite.connect('file:' + TESTFN + '?mode=ro', uri=True) as cx:
+            with self.assertRaises(sqlite.OperationalError):
+                cx.execute('insert into test(id) values(1)')
+
+
 class CursorTests(unittest.TestCase):
     def setUp(self):
         self.cx = sqlite.connect(":memory:")