mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
sqlite3: fix iterdump import and filter support (#8692)
* sqlite3: fix iterdump import and filter support Fix Connection.iterdump() to import sqlite3.dump with a from-list and forward its keyword-only filter argument, matching CPython 3.14. Remove stale expected-failure markers from all passing iterdump tests. Assisted-by: GitHub Copilot:GPT-5.6 Luna (high) * sqlite3: fix clippy core iterator lint Use core::iter instead of std::iter in the iterdump filter kwargs path, as required by RustPython clippy. Add the sqlite3 expected-failure workflow and CI clippy feedback reports. Assisted-by: GitHub Copilot:GPT-5.6 Luna (high)
This commit is contained in:
1 parent
a0dc7c2e13
commit
08e6e697a1
2 files changed
+15
-11
No files matched your search
Vendored
-7
@@ -9,7 +9,6 @@ from .util import requires_virtual_table
|
||||
|
||||
class DumpTests(MemoryDatabaseMixin, unittest.TestCase):
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_table_dump(self):
|
||||
expected_sqls = [
|
||||
"PRAGMA foreign_keys=OFF;",
|
||||
@@ -57,7 +56,6 @@ class DumpTests(MemoryDatabaseMixin, unittest.TestCase):
|
||||
[self.assertEqual(expected_sqls[i], actual_sqls[i])
|
||||
for i in range(len(expected_sqls))]
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; iterdump filter parameter not implemented
|
||||
def test_table_dump_filter(self):
|
||||
all_table_sqls = [
|
||||
"""CREATE TABLE "some_table_2" ("id_1" INTEGER);""",
|
||||
@@ -128,7 +126,6 @@ class DumpTests(MemoryDatabaseMixin, unittest.TestCase):
|
||||
["BEGIN TRANSACTION;", *all_table_sqls, *all_views_sqls, "COMMIT;"],
|
||||
)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; _iterdump not implemented
|
||||
def test_dump_autoincrement(self):
|
||||
expected = [
|
||||
'CREATE TABLE "t1" (id integer primary key autoincrement);',
|
||||
@@ -149,7 +146,6 @@ class DumpTests(MemoryDatabaseMixin, unittest.TestCase):
|
||||
actual = [stmt for stmt in self.cx.iterdump()]
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; _iterdump not implemented
|
||||
def test_dump_autoincrement_create_new_db(self):
|
||||
self.cu.execute("BEGIN TRANSACTION")
|
||||
self.cu.execute("CREATE TABLE t1 (id integer primary key autoincrement)")
|
||||
@@ -175,7 +171,6 @@ class DumpTests(MemoryDatabaseMixin, unittest.TestCase):
|
||||
rows = res.fetchall()
|
||||
self.assertEqual(rows[0][0], seq)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; _iterdump not implemented
|
||||
def test_unorderable_row(self):
|
||||
# iterdump() should be able to cope with unorderable row types (issue #15545)
|
||||
class UnorderableRow:
|
||||
@@ -197,7 +192,6 @@ class DumpTests(MemoryDatabaseMixin, unittest.TestCase):
|
||||
got = list(self.cx.iterdump())
|
||||
self.assertEqual(expected, got)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; _iterdump not implemented
|
||||
def test_dump_custom_row_factory(self):
|
||||
# gh-118221: iterdump should be able to cope with custom row factories.
|
||||
def dict_factory(cu, row):
|
||||
@@ -213,7 +207,6 @@ class DumpTests(MemoryDatabaseMixin, unittest.TestCase):
|
||||
self.assertEqual(expected, actual)
|
||||
self.assertEqual(self.cx.row_factory, dict_factory)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; _iterdump not implemented
|
||||
@requires_virtual_table("fts4")
|
||||
def test_dump_virtual_tables(self):
|
||||
# gh-64662
|
||||
|
||||
@@ -62,7 +62,7 @@ mod _sqlite3 {
|
||||
},
|
||||
convert::IntoObject,
|
||||
function::{
|
||||
ArgCallable, ArgIterable, FsPath, FuncArgs, OptionalArg, PyComparisonValue,
|
||||
ArgCallable, ArgIterable, FsPath, FuncArgs, KwArgs, OptionalArg, PyComparisonValue,
|
||||
PySetterValue, TimeoutSeconds,
|
||||
},
|
||||
object::{Traverse, TraverseFn},
|
||||
@@ -405,6 +405,12 @@ mod _sqlite3 {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct IterDumpArgs {
|
||||
#[pyarg(named, optional)]
|
||||
filter: Option<PyStrRef>,
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct CreateFunctionArgs {
|
||||
#[pyarg(any)]
|
||||
@@ -1507,10 +1513,15 @@ mod _sqlite3 {
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
fn iterdump(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult {
|
||||
let module = vm.import("sqlite3.dump", 0)?;
|
||||
fn iterdump(zelf: PyRef<Self>, args: IterDumpArgs, vm: &VirtualMachine) -> PyResult {
|
||||
let from_list = PyTuple::new_ref_typed(vec![vm.ctx.new_str("_iterdump")], &vm.ctx);
|
||||
let module = vm.import_from("sqlite3.dump", &from_list, 0)?;
|
||||
let func = module.get_attr("_iterdump", vm)?;
|
||||
func.call((zelf,), vm)
|
||||
let filter: PyObjectRef = args
|
||||
.filter
|
||||
.map_or_else(|| vm.ctx.none(), |filter| filter.into());
|
||||
let kwargs = core::iter::once(("filter", filter)).collect::<KwArgs>();
|
||||
func.call(FuncArgs::new(vec![zelf.into()], kwargs), vm)
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
|
||||
Reference in new issue
Block a user