52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
from pathlib import Path
|
|
|
|
import hellocomputer
|
|
from hellocomputer.db import StorageEngines
|
|
from hellocomputer.analytics import AnalyticsDB
|
|
|
|
TEST_STORAGE = StorageEngines.local
|
|
TEST_XLS_PATH = (
|
|
Path(hellocomputer.__file__).parents[2]
|
|
/ "test"
|
|
/ "data"
|
|
/ "TestExcelHelloComputer.xlsx"
|
|
)
|
|
TEST_OUTPUT_FOLDER = Path(hellocomputer.__file__).parents[2] / "test" / "output"
|
|
|
|
|
|
def test_0_dump():
|
|
db = AnalyticsDB(storage_engine=TEST_STORAGE, path=TEST_OUTPUT_FOLDER)
|
|
db.load_xls(TEST_XLS_PATH).dump()
|
|
|
|
assert db.sheets == ("answers",)
|
|
assert (TEST_OUTPUT_FOLDER / "answers.csv").exists()
|
|
|
|
|
|
def test_load():
|
|
db = AnalyticsDB(storage_engine=TEST_STORAGE, path=TEST_OUTPUT_FOLDER).load_folder()
|
|
results = db.query("select * from answers").fetchall()
|
|
assert len(results) == 6
|
|
|
|
|
|
def test_load_description():
|
|
db = AnalyticsDB(storage_engine=TEST_STORAGE, path=TEST_OUTPUT_FOLDER).load_folder()
|
|
file_description = db.load_description()
|
|
assert file_description.startswith("answers")
|
|
|
|
|
|
def test_schema():
|
|
db = AnalyticsDB(storage_engine=TEST_STORAGE, path=TEST_OUTPUT_FOLDER).load_folder()
|
|
schema = []
|
|
for sheet in db.sheets:
|
|
schema.append(db.table_schema(sheet))
|
|
|
|
assert db.schema.startswith("The schema of the database")
|
|
|
|
|
|
def test_query_prompt():
|
|
db = AnalyticsDB(storage_engine=TEST_STORAGE, path=TEST_OUTPUT_FOLDER).load_folder()
|
|
|
|
assert db.query_prompt("Find the average score of all students").startswith(
|
|
"The following sentence"
|
|
)
|