Get the anosql tests clean

This commit is contained in:
Reid 'arrdem' McKenzie 2021-08-14 09:20:58 -06:00
parent d27e7e6df6
commit daca9da84d
3 changed files with 20 additions and 10 deletions

View file

@ -61,7 +61,14 @@ class SQLite3DriverAdapter(object):
cur = conn.cursor() cur = conn.cursor()
log.debug({'sql': sql, 'parameters': parameters}) log.debug({'sql': sql, 'parameters': parameters})
cur.execute(sql, parameters) cur.execute(sql, parameters)
results = cur.fetchall()
if "returning" not in sql.lower():
# Original behavior - return the last row ID
results = cur.lastrowid
else:
# New behavior - honor a `RETURNING` clause
results = cur.fetchall()
log.debug({"results": results}) log.debug({"results": results})
cur.close() cur.close()
return results return results

View file

@ -2,7 +2,6 @@ import os
import anosql import anosql
import pytest import pytest
from importlib.resources import path
def dict_factory(cursor, row): def dict_factory(cursor, row):
d = {} d = {}
@ -13,7 +12,7 @@ def dict_factory(cursor, row):
@pytest.fixture() @pytest.fixture()
def queries(): def queries():
dir_path = path("blogdb", "sql") dir_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "blogdb", "sql")
return anosql.from_path(dir_path, "sqlite3") return anosql.from_path(dir_path, "sqlite3")
@ -64,12 +63,12 @@ def test_insert_returning(sqlite3_conn, queries):
content="Hello, World!", content="Hello, World!",
published="2018-12-04", published="2018-12-04",
) )
print(blogid, type(blogid))
cur = sqlite3_conn.cursor() cur = sqlite3_conn.cursor()
cur.execute( cur.execute("""\
"""\ select title
select title from blogs
from blogs where blogid = ?;
where blogid = ?;
""", """,
(blogid,), (blogid,),
) )

View file

@ -164,9 +164,13 @@ def py_project(name=None,
""" """
lib_srcs = lib_srcs or native.glob(["src/python/**/*.py"]) lib_srcs = lib_srcs or native.glob(["src/python/**/*.py"])
lib_data = lib_data or native.glob(["src/resources/**/*"]) lib_data = lib_data or native.glob(["src/resources/**/*",
"src/python/**/*"],
exclude=["**/*.py"])
test_srcs = test_srcs or native.glob(["test/python/**/*.py"]) test_srcs = test_srcs or native.glob(["test/python/**/*.py"])
test_data = test_data or native.glob(["test/resources/**/*"]) test_data = test_data or native.glob(["test/resources/**/*",
"test/python/**/*"],
exclude=["**/*.py"])
py_library( py_library(
name=name, name=name,