mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Update unit tests to use the new BaseModel types
This commit is contained in:
@@ -4,7 +4,7 @@ from pathlib import Path
|
||||
|
||||
# Internal Packages
|
||||
from src.search_type import asymmetric, image_search
|
||||
from src.utils.rawconfig import SearchConfigModel, ImageSearchConfigModel, TextSearchConfigModel
|
||||
from src.utils.rawconfig import ContentTypeModel, ImageSearchConfigModel, TextSearchConfigModel
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
@@ -12,14 +12,14 @@ def model_dir(tmp_path_factory):
|
||||
model_dir = tmp_path_factory.mktemp('data')
|
||||
|
||||
# Generate Image Embeddings from Test Images
|
||||
search_config = SearchConfigModel()
|
||||
search_config = ContentTypeModel()
|
||||
search_config.image = ImageSearchConfigModel(
|
||||
input_directory = Path('tests/data'),
|
||||
embeddings_file = model_dir.joinpath('.image_embeddings.pt'),
|
||||
batch_size = 10,
|
||||
use_xmp_metadata = False)
|
||||
|
||||
image_search.setup(search_config.image, regenerate=False)
|
||||
image_search.setup(search_config.image, regenerate=False, verbose=True)
|
||||
|
||||
# Generate Notes Embeddings from Test Notes
|
||||
search_config.org = TextSearchConfigModel(
|
||||
@@ -28,14 +28,14 @@ def model_dir(tmp_path_factory):
|
||||
compressed_jsonl = model_dir.joinpath('.notes.jsonl.gz'),
|
||||
embeddings_file = model_dir.joinpath('.note_embeddings.pt'))
|
||||
|
||||
asymmetric.setup(search_config.notes, regenerate=False)
|
||||
asymmetric.setup(search_config.notes, regenerate=False, verbose=True)
|
||||
|
||||
return model_dir
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def search_config(model_dir):
|
||||
search_config = SearchConfigModel()
|
||||
search_config = ContentTypeModel()
|
||||
search_config.org = TextSearchConfigModel(
|
||||
input_files = [Path('tests/data/main_readme.org'), Path('tests/data/interface_emacs_readme.org')],
|
||||
input_filter = None,
|
||||
|
||||
@@ -40,7 +40,7 @@ def test_cli_config_from_file():
|
||||
assert actual_args.config_file == Path('tests/data/config.yml')
|
||||
assert actual_args.regenerate == True
|
||||
assert actual_args.config is not None
|
||||
assert actual_args.config['content-type']['org']['input-files'] == ['~/first_from_config.org', '~/second_from_config.org']
|
||||
assert actual_args.config.content_type.org.input_files == ['~/first_from_config.org', '~/second_from_config.org']
|
||||
assert actual_args.verbose == 3
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ def test_cli_config_from_cmd_args():
|
||||
assert actual_args.org_files == ['first.org']
|
||||
assert actual_args.config_file is None
|
||||
assert actual_args.config is not None
|
||||
assert actual_args.config['content-type']['org']['input-files'] == ['first.org']
|
||||
assert actual_args.config.content_type.org.input_files == ['first.org']
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
@@ -67,4 +67,4 @@ def test_cli_config_from_cmd_args_override_config_file():
|
||||
assert actual_args.org_files == ['first.org']
|
||||
assert actual_args.config_file == Path('tests/data/config.yml')
|
||||
assert actual_args.config is not None
|
||||
assert actual_args.config['content-type']['org']['input-files'] == ['first.org']
|
||||
assert actual_args.config.content_type.org.input_files == ['first.org']
|
||||
|
||||
@@ -5,15 +5,16 @@ from pathlib import Path
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
# Internal Packages
|
||||
from src.main import app, model, search_config as main_search_config
|
||||
from src.main import app, model, config
|
||||
from src.search_type import asymmetric, image_search
|
||||
from src.utils.helpers import resolve_absolute_path
|
||||
from src.utils.rawconfig import FullConfigModel
|
||||
|
||||
|
||||
# Arrange
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
client = TestClient(app)
|
||||
|
||||
config = FullConfigModel()
|
||||
|
||||
# Test
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
@@ -31,7 +32,7 @@ def test_search_with_invalid_search_type():
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
def test_search_with_valid_search_type(search_config):
|
||||
# Arrange
|
||||
main_search_config.image = search_config.image
|
||||
config.content_type.image = search_config.image
|
||||
for search_type in ["notes", "ledger", "music", "image"]:
|
||||
# Act
|
||||
response = client.get(f"/search?q=random&t={search_type}")
|
||||
@@ -51,7 +52,7 @@ def test_regenerate_with_invalid_search_type():
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
def test_regenerate_with_valid_search_type(search_config):
|
||||
# Arrange
|
||||
main_search_config.image = search_config.image
|
||||
config.content_type.image = search_config.image
|
||||
for search_type in ["notes", "ledger", "music", "image"]:
|
||||
# Act
|
||||
response = client.get(f"/regenerate?t={search_type}")
|
||||
@@ -62,7 +63,7 @@ def test_regenerate_with_valid_search_type(search_config):
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
def test_image_search(search_config):
|
||||
# Arrange
|
||||
main_search_config.image = search_config.image
|
||||
config.content_type.image = search_config.image
|
||||
model.image_search = image_search.setup(search_config.image, regenerate=False)
|
||||
query_expected_image_pairs = [("brown kitten next to fallen plant", "kitten_park.jpg"),
|
||||
("a horse and dog on a leash", "horse_dog.jpg"),
|
||||
|
||||
Reference in New Issue
Block a user