Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
capjamesg committed Aug 22, 2024
1 parent 51f9786 commit b5934d6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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")
43 changes: 43 additions & 0 deletions tests/save_and_load.py
Original file line number Diff line number Diff line change
@@ -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"))

0 comments on commit b5934d6

Please sign in to comment.