hellocomputer/test/test_data.py

60 lines
1.6 KiB
Python
Raw 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-06-11 17:20:32 +02:00
from hellocomputer.db import StorageEngines
2024-06-12 11:04:28 +02:00
from hellocomputer.sessions import SessionDB
2024-05-28 22:23:11 +02:00
TEST_STORAGE = StorageEngines.local
TEST_XLS_PATH = (
Path(hellocomputer.__file__).parents[2]
/ "test"
/ "data"
/ "TestExcelHelloComputer.xlsx"
)
2024-05-21 21:50:17 +02:00
TEST_OUTPUT_FOLDER = Path(hellocomputer.__file__).parents[2] / "test" / "output"
2024-05-28 22:23:11 +02:00
def test_0_dump():
2024-06-11 18:54:10 +02:00
db = SessionDB(storage_engine=TEST_STORAGE, path=TEST_OUTPUT_FOLDER, 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-06-11 19:02:33 +02:00
assert (TEST_OUTPUT_FOLDER / "sessions" / "test" / "answers.csv").exists()
2024-05-21 22:11:47 +02:00
def test_load():
2024-06-11 18:54:10 +02:00
db = SessionDB(
2024-06-11 17:20:32 +02:00
storage_engine=TEST_STORAGE, path=TEST_OUTPUT_FOLDER, 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-06-11 18:54:10 +02:00
db = SessionDB(
2024-06-11 17:20:32 +02:00
storage_engine=TEST_STORAGE, path=TEST_OUTPUT_FOLDER, 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-06-11 18:54:10 +02:00
db = SessionDB(
2024-06-11 17:20:32 +02:00
storage_engine=TEST_STORAGE, path=TEST_OUTPUT_FOLDER, 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-06-11 18:54:10 +02:00
db = SessionDB(
2024-06-11 17:20:32 +02:00
storage_engine=TEST_STORAGE, path=TEST_OUTPUT_FOLDER, 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"
)