hellocomputer/test/test_data.py

55 lines
1.4 KiB
Python
Raw Permalink Normal View History

2024-05-21 21:50:17 +02:00
from pathlib import Path
2024-05-28 22:23:11 +02:00
import hellocomputer
2024-07-26 11:59:13 +02:00
from hellocomputer.config import Settings, StorageEngines
2024-06-16 09:31:33 +02:00
from hellocomputer.db.sessions import SessionDB
2024-05-28 22:23:11 +02:00
2024-07-25 00:10:09 +02:00
settings = Settings(
storage_engine=StorageEngines.local,
path=Path(hellocomputer.__file__).parents[2] / "test" / "output",
)
2024-05-28 22:23:11 +02:00
TEST_XLS_PATH = (
Path(hellocomputer.__file__).parents[2]
/ "test"
/ "data"
/ "TestExcelHelloComputer.xlsx"
)
2024-05-21 21:50:17 +02:00
2024-05-28 22:23:11 +02:00
def test_0_dump():
2024-07-25 00:10:09 +02:00
db = SessionDB(settings, sid="test")
2024-05-28 22:23:11 +02:00
db.load_xls(TEST_XLS_PATH).dump()
2024-05-21 21:50:17 +02:00
assert db.sheets == ("answers",)
2024-07-25 00:10:09 +02:00
assert (settings.path / "sessions" / "test" / "answers.csv").exists()
2024-05-21 22:11:47 +02:00
def test_load():
2024-07-25 00:10:09 +02:00
db = SessionDB(settings, sid="test").load_folder()
2024-05-23 23:31:00 +02:00
results = db.query("select * from answers").fetchall()
2024-05-25 16:09:20 +02:00
assert len(results) == 6
2024-05-25 09:16:45 +02:00
def test_load_description():
2024-07-25 00:10:09 +02:00
db = SessionDB(settings, sid="test").load_folder()
2024-05-28 22:23:11 +02:00
file_description = db.load_description()
2024-05-25 09:16:45 +02:00
assert file_description.startswith("answers")
def test_schema():
2024-07-25 00:10:09 +02:00
db = SessionDB(settings, sid="test").load_folder()
2024-05-25 09:16:45 +02:00
schema = []
for sheet in db.sheets:
schema.append(db.table_schema(sheet))
2024-05-28 22:23:11 +02:00
assert db.schema.startswith("The schema of the database")
def test_query_prompt():
2024-07-25 00:10:09 +02:00
db = SessionDB(settings, sid="test").load_folder()
2024-05-28 22:23:11 +02:00
assert db.query_prompt("Find the average score of all students").startswith(
"The following sentence"
)