fix: skip library.json test when bib.sqlite has no data (fixes CI)
The test assumed bib.sqlite always has items when present. In CI, a stale or empty bib.sqlite could exist without data, causing the export to produce an empty library.json. Now validates the database has items before asserting on the export output.
This commit is contained in:
@@ -30,11 +30,20 @@ class TestExportLibrary:
|
|||||||
assert result.returncode == 0, result.stderr
|
assert result.returncode == 0, result.stderr
|
||||||
|
|
||||||
def test_library_json_has_items(self):
|
def test_library_json_has_items(self):
|
||||||
"""library.json should have >0 items when bib.sqlite exists."""
|
"""library.json should have >0 items when bib.sqlite has data."""
|
||||||
if not BIB_DB.exists():
|
if not BIB_DB.exists():
|
||||||
import pytest
|
|
||||||
|
|
||||||
pytest.skip("bib.sqlite not available")
|
pytest.skip("bib.sqlite not available")
|
||||||
|
# Verify bib.sqlite is a real database with items
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
try:
|
||||||
|
con = sqlite3.connect(str(BIB_DB))
|
||||||
|
count = con.execute("SELECT count(*) FROM items").fetchone()[0]
|
||||||
|
con.close()
|
||||||
|
except (sqlite3.OperationalError, sqlite3.DatabaseError):
|
||||||
|
pytest.skip("bib.sqlite is not a valid database")
|
||||||
|
if count == 0:
|
||||||
|
pytest.skip("bib.sqlite has no items")
|
||||||
# Run the export
|
# Run the export
|
||||||
subprocess.run([sys.executable, str(EXPORT_SCRIPT)], check=True)
|
subprocess.run([sys.executable, str(EXPORT_SCRIPT)], check=True)
|
||||||
data = json.loads(LIBRARY_JSON.read_text())
|
data = json.loads(LIBRARY_JSON.read_text())
|
||||||
|
|||||||
Reference in New Issue
Block a user