From 8f88a4da45908f814ed384e3dd180a6074f6971f Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Sat, 14 Aug 2021 09:20:58 -0600 Subject: [PATCH] Get the anosql tests clean --- .../anosql/src/python/anosql/adapters/sqlite3.py | 9 ++++++++- projects/anosql/test/python/test_sqlite3.py | 13 ++++++------- tools/python/defs.bzl | 8 ++++++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/projects/anosql/src/python/anosql/adapters/sqlite3.py b/projects/anosql/src/python/anosql/adapters/sqlite3.py index cd926a0..d2e43dd 100644 --- a/projects/anosql/src/python/anosql/adapters/sqlite3.py +++ b/projects/anosql/src/python/anosql/adapters/sqlite3.py @@ -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 diff --git a/projects/anosql/test/python/test_sqlite3.py b/projects/anosql/test/python/test_sqlite3.py index d0cf64c..8f89f71 100644 --- a/projects/anosql/test/python/test_sqlite3.py +++ b/projects/anosql/test/python/test_sqlite3.py @@ -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,), ) diff --git a/tools/python/defs.bzl b/tools/python/defs.bzl index 7f14fc3..ba5e155 100644 --- a/tools/python/defs.bzl +++ b/tools/python/defs.bzl @@ -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,