Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ jobs:
run: |
.venv/bin/ruff check src_py test

- name: Smoke test JSON extension install
working-directory: ladybug/tools/python_api
env:
LBUG_PYTHON_BACKEND: capi
run: |
.venv/bin/python -c 'import shutil, tempfile; from pathlib import Path; import ladybug as lb; tmp = Path(tempfile.mkdtemp()); db = lb.Database(tmp / "db.lbdb"); conn = lb.Connection(db); conn.execute("INSTALL json; LOAD json;"); shutil.rmtree(tmp)'

- name: Run pytest (C API backend)
working-directory: ladybug/tools/python_api
env:
Expand All @@ -140,7 +147,7 @@ jobs:

- name: Update submodules
working-directory: ladybug
run: git submodule update --init --recursive dataset extension
run: git submodule update --init --recursive dataset

- name: Checkout ladybug-python into ladybug/tools/python_api
uses: actions/checkout@v4
Expand Down Expand Up @@ -191,7 +198,6 @@ jobs:
GEN: Ninja
CMAKE_C_COMPILER_LAUNCHER: ccache
CMAKE_CXX_COMPILER_LAUNCHER: ccache
EXTRA_CMAKE_FLAGS: -DBUILD_EXTENSIONS=json -DEXTENSION_STATIC_LINK_LIST=json
run: |
make python
cp tools/python_api/src_py/*.py tools/python_api/build/ladybug/
Expand Down
54 changes: 37 additions & 17 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,17 @@ def init_db(path: Path) -> Path:
Path.mkdir(path)

db_path = get_db_file_path(path)
conn, _ = create_conn_db(db_path, read_only=False)
init_tinysnb(conn)
init_demo(conn)
init_npy(conn)
init_tensor(conn)
init_long_str(conn)
init_movie_serial(conn)
conn, db = create_conn_db(db_path, read_only=False)
try:
init_tinysnb(conn)
init_demo(conn)
init_npy(conn)
init_tensor(conn)
init_long_str(conn)
init_movie_serial(conn)
finally:
conn.close()
db.close()
return db_path


Expand Down Expand Up @@ -241,18 +245,25 @@ def conn_db_readonly(tmp_path: Path) -> ConnDB:
@pytest.fixture
def conn_db_readwrite(tmp_path: Path) -> ConnDB:
"""Return a new writable connection and database."""
return create_conn_db(init_db(tmp_path), read_only=False)
conn, db = create_conn_db(init_db(tmp_path), read_only=False)
try:
yield conn, db
finally:
conn.close()
db.close()


@pytest.fixture
def async_connection_readonly(tmp_path: Path) -> lb.AsyncConnection:
"""Return a cached read-only async connection."""
global _READONLY_ASYNC_CONNECTION_
if _READONLY_ASYNC_CONNECTION_ is None:
conn, db = create_conn_db(init_db(tmp_path), read_only=True)
conn.close()
_READONLY_ASYNC_CONNECTION_ = lb.AsyncConnection(db, max_threads_per_query=4)
return _READONLY_ASYNC_CONNECTION_
"""Return a read-only async connection."""
conn, db = create_conn_db(init_db(tmp_path), read_only=True)
conn.close()
async_conn = lb.AsyncConnection(db, max_threads_per_query=4)
try:
yield async_conn
finally:
async_conn.close()
db.close()


@pytest.fixture
Expand All @@ -271,7 +282,12 @@ def async_connection_readwrite(tmp_path: Path) -> lb.AsyncConnection:
@pytest.fixture
def conn_db_empty(tmp_path: Path) -> ConnDB:
"""Return a new empty connection and database."""
return create_conn_db(get_db_file_path(tmp_path), read_only=False)
conn, db = create_conn_db(get_db_file_path(tmp_path), read_only=False)
try:
yield conn, db
finally:
conn.close()
db.close()


@pytest.fixture
Expand All @@ -281,7 +297,11 @@ def conn_db_in_mem() -> ConnDB:
database_path=":memory:", buffer_pool_size=_POOL_SIZE_, read_only=False
)
conn = lb.Connection(db, num_threads=4)
return conn, db
try:
yield conn, db
finally:
conn.close()
db.close()


def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None:
Expand Down
2 changes: 2 additions & 0 deletions test/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def test_to_json_string_param_roundtrip(conn_db_empty: ConnDB) -> None:
"""to_json() with a JSON string parameter should store the parsed object, not a string literal."""
conn, _ = conn_db_empty
conn.execute("""
INSTALL json;
LOAD json;
CREATE NODE TABLE User (id SERIAL PRIMARY KEY, meta JSON);
""")

Expand Down
Loading