summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sqlite3
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@protonmail.com>2022-07-20 19:37:59 (GMT)
committerGitHub <noreply@github.com>2022-07-20 19:37:59 (GMT)
commit6dadf6ca019f2e19ca8f0344903be0c539263c30 (patch)
tree2d030286a92ceac2150a2d5ccbd5c77a3d1cbc6f /Lib/test/test_sqlite3
parent000a4eebe735b6aa527516cf70f5290c2b5163bf (diff)
downloadcpython-6dadf6ca019f2e19ca8f0344903be0c539263c30.zip
cpython-6dadf6ca019f2e19ca8f0344903be0c539263c30.tar.gz
cpython-6dadf6ca019f2e19ca8f0344903be0c539263c30.tar.bz2
gh-90016: Deprecate default sqlite3 adapters and converters (#94276)
Co-authored-by: CAM Gerlach <CAM.Gerlach@Gerlach.CAM>
Diffstat (limited to 'Lib/test/test_sqlite3')
-rw-r--r--Lib/test/test_sqlite3/test_regression.py6
-rw-r--r--Lib/test/test_sqlite3/test_types.py31
2 files changed, 26 insertions, 11 deletions
diff --git a/Lib/test/test_sqlite3/test_regression.py b/Lib/test/test_sqlite3/test_regression.py
index 0b727ce..ad83a97 100644
--- a/Lib/test/test_sqlite3/test_regression.py
+++ b/Lib/test/test_sqlite3/test_regression.py
@@ -129,7 +129,8 @@ class RegressionTests(unittest.TestCase):
con = sqlite.connect(":memory:",detect_types=sqlite.PARSE_DECLTYPES)
cur = con.cursor()
cur.execute("create table foo(bar timestamp)")
- cur.execute("insert into foo(bar) values (?)", (datetime.datetime.now(),))
+ with self.assertWarnsRegex(DeprecationWarning, "adapter"):
+ cur.execute("insert into foo(bar) values (?)", (datetime.datetime.now(),))
cur.execute(SELECT)
cur.execute("drop table foo")
cur.execute("create table foo(bar integer)")
@@ -305,7 +306,8 @@ class RegressionTests(unittest.TestCase):
cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.123456789')")
cur.execute("SELECT * FROM t")
- values = [x[0] for x in cur.fetchall()]
+ with self.assertWarnsRegex(DeprecationWarning, "converter"):
+ values = [x[0] for x in cur.fetchall()]
self.assertEqual(values, [
datetime.datetime(2012, 4, 4, 15, 6, 0, 456000),
diff --git a/Lib/test/test_sqlite3/test_types.py b/Lib/test/test_sqlite3/test_types.py
index 177cd10..6231882 100644
--- a/Lib/test/test_sqlite3/test_types.py
+++ b/Lib/test/test_sqlite3/test_types.py
@@ -496,38 +496,51 @@ class DateTimeTests(unittest.TestCase):
def test_sqlite_date(self):
d = sqlite.Date(2004, 2, 14)
- self.cur.execute("insert into test(d) values (?)", (d,))
+ with self.assertWarnsRegex(DeprecationWarning, "adapter") as cm:
+ self.cur.execute("insert into test(d) values (?)", (d,))
+ self.assertEqual(cm.filename, __file__)
self.cur.execute("select d from test")
- d2 = self.cur.fetchone()[0]
+ with self.assertWarnsRegex(DeprecationWarning, "converter") as cm:
+ d2 = self.cur.fetchone()[0]
+ self.assertEqual(cm.filename, __file__)
self.assertEqual(d, d2)
def test_sqlite_timestamp(self):
ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0)
- self.cur.execute("insert into test(ts) values (?)", (ts,))
+ with self.assertWarnsRegex(DeprecationWarning, "adapter") as cm:
+ self.cur.execute("insert into test(ts) values (?)", (ts,))
+ self.assertEqual(cm.filename, __file__)
self.cur.execute("select ts from test")
- ts2 = self.cur.fetchone()[0]
+ with self.assertWarnsRegex(DeprecationWarning, "converter") as cm:
+ ts2 = self.cur.fetchone()[0]
+ self.assertEqual(cm.filename, __file__)
self.assertEqual(ts, ts2)
def test_sql_timestamp(self):
now = datetime.datetime.utcnow()
self.cur.execute("insert into test(ts) values (current_timestamp)")
self.cur.execute("select ts from test")
- ts = self.cur.fetchone()[0]
+ with self.assertWarnsRegex(DeprecationWarning, "converter"):
+ ts = self.cur.fetchone()[0]
self.assertEqual(type(ts), datetime.datetime)
self.assertEqual(ts.year, now.year)
def test_date_time_sub_seconds(self):
ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 500000)
- self.cur.execute("insert into test(ts) values (?)", (ts,))
+ with self.assertWarnsRegex(DeprecationWarning, "adapter"):
+ self.cur.execute("insert into test(ts) values (?)", (ts,))
self.cur.execute("select ts from test")
- ts2 = self.cur.fetchone()[0]
+ with self.assertWarnsRegex(DeprecationWarning, "converter"):
+ ts2 = self.cur.fetchone()[0]
self.assertEqual(ts, ts2)
def test_date_time_sub_seconds_floating_point(self):
ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 510241)
- self.cur.execute("insert into test(ts) values (?)", (ts,))
+ with self.assertWarnsRegex(DeprecationWarning, "adapter"):
+ self.cur.execute("insert into test(ts) values (?)", (ts,))
self.cur.execute("select ts from test")
- ts2 = self.cur.fetchone()[0]
+ with self.assertWarnsRegex(DeprecationWarning, "converter"):
+ ts2 = self.cur.fetchone()[0]
self.assertEqual(ts, ts2)