diff --git a/src/utils/cli.py b/src/utils/cli.py index 00d0566e..1ffcce08 100644 --- a/src/utils/cli.py +++ b/src/utils/cli.py @@ -38,12 +38,14 @@ def cli(args=None): config_from_file = yaml.safe_load(config_file) args.config = merge_dicts(priority_dict=config_from_file, default_dict=args.config) args.config = FullConfigModel.parse_obj(args.config) + else: + args.config = FullConfigModel.parse_obj(args.config) if args.org_files: - args.config['content-type']['org']['input-files'] = args.org_files + args.config.content_type.org.input_files = args.org_files if args.org_filter: - args.config['content-type']['org']['input-filter'] = args.org_filter + args.config.content_type.org.input_filter = args.org_filter return args diff --git a/src/utils/rawconfig.py b/src/utils/rawconfig.py index da8a448b..8ce26132 100644 --- a/src/utils/rawconfig.py +++ b/src/utils/rawconfig.py @@ -27,7 +27,7 @@ class TextSearchConfigModel(ConfigBaseModel): class ImageSearchConfigModel(ConfigBaseModel): use_xmp_metadata: Optional[str] batch_size: Optional[int] - input_directory: Optional[List[str]] + input_directory: Optional[Path] input_filter: Optional[str] embeddings_file: Optional[Path] diff --git a/tests/conftest.py b/tests/conftest.py index 28f14ef7..51690bbb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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, diff --git a/tests/test_cli.py b/tests/test_cli.py index de2f9753..58808fb4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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'] diff --git a/tests/test_client.py b/tests/test_client.py index cbf0e0c3..5841fc9e 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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"),