From ba8dc9ed5fec3454e3b5b403cb222bf8b033deaf Mon Sep 17 00:00:00 2001 From: Saba Date: Sat, 11 Dec 2021 14:14:31 -0500 Subject: [PATCH] Update the search_config instantiated for tests in conftest --- tests/conftest.py | 12 ++++++------ tests/test_client.py | 28 ++++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index fcff1510..48c0cf51 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,7 +14,7 @@ def model_dir(tmp_path_factory): # Generate Image Embeddings from Test Images search_config = ContentTypeConfig() search_config.image = ImageSearchConfig( - input_directory = Path('tests/data'), + input_directory = 'tests/data', embeddings_file = model_dir.joinpath('.image_embeddings.pt'), batch_size = 10, use_xmp_metadata = False) @@ -23,12 +23,12 @@ def model_dir(tmp_path_factory): # Generate Notes Embeddings from Test Notes search_config.org = TextSearchConfig( - input_files = [Path('tests/data/main_readme.org'), Path('tests/data/interface_emacs_readme.org')], + input_files = ['tests/data/main_readme.org', 'tests/data/interface_emacs_readme.org'], input_filter = None, compressed_jsonl = model_dir.joinpath('.notes.jsonl.gz'), embeddings_file = model_dir.joinpath('.note_embeddings.pt')) - asymmetric.setup(search_config.notes, regenerate=False, verbose=True) + asymmetric.setup(search_config.org, regenerate=False, verbose=True) return model_dir @@ -37,14 +37,14 @@ def model_dir(tmp_path_factory): def search_config(model_dir): search_config = ContentTypeConfig() search_config.org = TextSearchConfig( - input_files = [Path('tests/data/main_readme.org'), Path('tests/data/interface_emacs_readme.org')], + input_files = ['tests/data/main_readme.org', 'tests/data/interface_emacs_readme.org'], input_filter = None, compressed_jsonl = model_dir.joinpath('.notes.jsonl.gz'), embeddings_file = model_dir.joinpath('.note_embeddings.pt')) search_config.image = ImageSearchConfig( - input_directory = Path('tests/data'), - embeddings_file = Path('tests/data/.image_embeddings.pt'), + input_directory = 'tests/data', + embeddings_file = 'tests/data/.image_embeddings.pt', batch_size = 10, use_xmp_metadata = False) diff --git a/tests/test_client.py b/tests/test_client.py index bf8815fa..f363a243 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -8,13 +8,12 @@ from fastapi.testclient import TestClient 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 FullConfig +from src.utils.rawconfig import ContentTypeConfig # Arrange # ---------------------------------------------------------------------------------------------------- client = TestClient(app) -config = FullConfig() # Test # ---------------------------------------------------------------------------------------------------- @@ -30,9 +29,10 @@ def test_search_with_invalid_search_type(): # ---------------------------------------------------------------------------------------------------- -def test_search_with_valid_search_type(search_config): +def test_search_with_valid_search_type(search_config: ContentTypeConfig): # Arrange - config.content_type.image = search_config.image + config.content_type = search_config + # 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}") @@ -50,9 +50,9 @@ def test_regenerate_with_invalid_search_type(): # ---------------------------------------------------------------------------------------------------- -def test_regenerate_with_valid_search_type(search_config): +def test_regenerate_with_valid_search_type(search_config: ContentTypeConfig): # Arrange - config.content_type.image = search_config.image + config.content_type = search_config for search_type in ["notes", "ledger", "music", "image"]: # Act response = client.get(f"/regenerate?t={search_type}") @@ -61,9 +61,9 @@ def test_regenerate_with_valid_search_type(search_config): # ---------------------------------------------------------------------------------------------------- -def test_image_search(search_config): +def test_image_search(search_config: ContentTypeConfig): # Arrange - config.content_type.image = search_config.image + config.content_type = search_config 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"), @@ -83,9 +83,9 @@ def test_image_search(search_config): # ---------------------------------------------------------------------------------------------------- -def test_notes_search(search_config): +def test_notes_search(search_config: ContentTypeConfig): # Arrange - model.notes_search = asymmetric.setup(search_config.notes, regenerate=False) + model.notes_search = asymmetric.setup(search_config.org, regenerate=False) user_query = "How to git install application?" # Act @@ -99,9 +99,9 @@ def test_notes_search(search_config): # ---------------------------------------------------------------------------------------------------- -def test_notes_search_with_include_filter(search_config): +def test_notes_search_with_include_filter(search_config: ContentTypeConfig): # Arrange - model.notes_search = asymmetric.setup(search_config.notes, regenerate=False) + model.notes_search = asymmetric.setup(search_config.org, regenerate=False) user_query = "How to git install application? +Emacs" # Act @@ -115,9 +115,9 @@ def test_notes_search_with_include_filter(search_config): # ---------------------------------------------------------------------------------------------------- -def test_notes_search_with_exclude_filter(search_config): +def test_notes_search_with_exclude_filter(search_config: ContentTypeConfig): # Arrange - model.notes_search = asymmetric.setup(search_config.notes, regenerate=False) + model.notes_search = asymmetric.setup(search_config.org, regenerate=False) user_query = "How to git install application? -clone" # Act