2021-08-22 02:21:38 +00:00
|
|
|
# Standard Modules
|
|
|
|
from pathlib import Path
|
2022-08-04 21:24:12 +00:00
|
|
|
from random import random
|
|
|
|
|
2021-08-22 02:21:38 +00:00
|
|
|
# Internal Packages
|
2023-02-14 20:50:51 +00:00
|
|
|
from khoj.utils.cli import cli
|
|
|
|
from khoj.utils.helpers import resolve_absolute_path
|
2021-08-22 02:21:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Test
|
|
|
|
# ----------------------------------------------------------------------------------------------------
|
|
|
|
def test_cli_minimal_default():
|
|
|
|
# Act
|
2022-08-11 19:26:02 +00:00
|
|
|
actual_args = cli([])
|
2021-08-22 02:21:38 +00:00
|
|
|
|
|
|
|
# Assert
|
2023-02-17 16:04:26 +00:00
|
|
|
assert actual_args.config_file == resolve_absolute_path(Path("~/.khoj/khoj.yml"))
|
2021-08-22 02:21:38 +00:00
|
|
|
assert actual_args.regenerate == False
|
|
|
|
assert actual_args.verbose == 0
|
|
|
|
|
2023-02-17 16:04:26 +00:00
|
|
|
|
2021-08-22 02:21:38 +00:00
|
|
|
# ----------------------------------------------------------------------------------------------------
|
2022-08-04 21:24:12 +00:00
|
|
|
def test_cli_invalid_config_file_path():
|
2022-08-11 19:26:02 +00:00
|
|
|
# Arrange
|
|
|
|
non_existent_config_file = f"non-existent-khoj-{random()}.yml"
|
|
|
|
|
2021-08-22 02:21:38 +00:00
|
|
|
# Act
|
2023-10-26 20:15:31 +00:00
|
|
|
actual_args = cli([f"--config-file={non_existent_config_file}"])
|
2022-08-11 19:26:02 +00:00
|
|
|
|
|
|
|
# Assert
|
2022-08-11 22:47:52 +00:00
|
|
|
assert actual_args.config_file == resolve_absolute_path(non_existent_config_file)
|
2022-08-11 19:26:02 +00:00
|
|
|
assert actual_args.config == None
|
2021-08-22 02:21:38 +00:00
|
|
|
|
2023-02-17 16:04:26 +00:00
|
|
|
|
2021-08-22 02:21:38 +00:00
|
|
|
# ----------------------------------------------------------------------------------------------------
|
|
|
|
def test_cli_config_from_file():
|
|
|
|
# Act
|
2023-10-26 20:15:31 +00:00
|
|
|
actual_args = cli(["--config-file=tests/data/config.yml", "--regenerate", "-vvv"])
|
2021-08-22 02:21:38 +00:00
|
|
|
|
|
|
|
# Assert
|
2023-02-17 16:04:26 +00:00
|
|
|
assert actual_args.config_file == resolve_absolute_path(Path("tests/data/config.yml"))
|
2021-08-22 02:21:38 +00:00
|
|
|
assert actual_args.regenerate == True
|
|
|
|
assert actual_args.config is not None
|
2023-02-22 20:47:22 +00:00
|
|
|
assert actual_args.verbose == 3
|
|
|
|
|
|
|
|
# Ensure content config is loaded from file
|
2023-02-17 16:04:26 +00:00
|
|
|
assert actual_args.config.content_type.org.input_files == [
|
|
|
|
Path("~/first_from_config.org"),
|
|
|
|
Path("~/second_from_config.org"),
|
|
|
|
]
|