From 8f382d0d5e236641c57d06236dccf996b3388d13 Mon Sep 17 00:00:00 2001 From: Kristaps Kaupe Date: Wed, 3 Jan 2024 15:36:55 +0200 Subject: [PATCH] Add test for dict_factory() --- test/jmbase/test_base_support.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/jmbase/test_base_support.py b/test/jmbase/test_base_support.py index 68734e5b7..024187915 100644 --- a/test/jmbase/test_base_support.py +++ b/test/jmbase/test_base_support.py @@ -1,7 +1,9 @@ #! /usr/bin/env python -import pytest import copy -from jmbase import random_insert +import pytest +import sqlite3 + +from jmbase import dict_factory, random_insert def test_color_coded_logging(): # TODO @@ -30,3 +32,14 @@ def test_random_insert(list1, list2): i_x = list1.index(x) i_y = list1.index(y) assert i_y > i_x + +def test_dict_factory(): + con = sqlite3.connect(":memory:") + con.row_factory = dict_factory + db = con.cursor() + db.execute("CREATE TABLE test (one TEXT, two TEXT)") + db.execute("INSERT INTO test VALUES (?, ?)", [ "one", "two" ]) + res = db.execute("SELECT * FROM test") + row = res.fetchone() + assert row["one"] == "one" + assert row["two"] == "two"