diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..37e4683 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,5 @@ +import pytest + +def pytest_addoption(parser): + parser.addoption("--benchmark", action="store_true", default=False, help="Enable benchmarking") + parser.addoption("--long-benchmark", action="store_true", default=False, help="Enable long benchmark") \ No newline at end of file diff --git a/tests/save_and_load.py b/tests/save_and_load.py new file mode 100644 index 0000000..fd7280d --- /dev/null +++ b/tests/save_and_load.py @@ -0,0 +1,43 @@ +import json +from contextlib import ExitStack as DoesNotRaise + +import pytest + +from jamesql import JameSQL +from jamesql.index import INDEX_STORE, GSI_INDEX_STRATEGIES +import os + + + +def test_save_to_local_index(): + with open("tests/fixtures/documents.json") as f: + documents = json.load(f) + + index = JameSQL() + + for document in documents: + index.add(document) + + index.create_gsi("title", strategy=GSI_INDEX_STRATEGIES.CONTAINS) + + index.save("documents") + + expected_index_path = os.path.join(INDEX_STORE, "documents") + + assert os.path.exists(expected_index_path) + +def test_load_from_local_index(): + with open("tests/fixtures/documents.json") as f: + documents = json.load(f) + + index = JameSQL() + + index.load("documents") + + assert len(index.global_index) == len(documents) + assert index.global_index + assert len(index.gsis) == 1 + assert index.gsis["title"] + assert len(index.uuids_to_position_in_global_index) == len(documents) + + os.remove(os.path.join(INDEX_STORE, "documents"))