Get the anosql tests clean

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

View file

@ -61,7 +61,14 @@ class SQLite3DriverAdapter(object):
cur = conn.cursor()
log.debug({'sql': sql, 'parameters': 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})
cur.close()
return results

View file

@ -2,7 +2,6 @@ import os
import anosql
import pytest
from importlib.resources import path
def dict_factory(cursor, row):
d = {}
@ -13,7 +12,7 @@ def dict_factory(cursor, row):
@pytest.fixture()
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")
@ -64,12 +63,12 @@ def test_insert_returning(sqlite3_conn, queries):
content="Hello, World!",
published="2018-12-04",
)
print(blogid, type(blogid))
cur = sqlite3_conn.cursor()
cur.execute(
"""\
select title
from blogs
where blogid = ?;
cur.execute("""\
select title
from blogs
where blogid = ?;
""",
(blogid,),
)

View file

@ -164,9 +164,13 @@ def py_project(name=None,
"""
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_data = test_data or native.glob(["test/resources/**/*"])
test_data = test_data or native.glob(["test/resources/**/*",
"test/python/**/*"],
exclude=["**/*.py"])
py_library(
name=name,