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
|
|
|
|
|
|
|
|
# External Modules
|
|
|
|
import pytest
|
2021-08-22 02:21:38 +00:00
|
|
|
|
|
|
|
# Internal Packages
|
2021-09-30 11:12:14 +00:00
|
|
|
from src.utils.cli import cli
|
2021-08-22 02:21:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Test
|
|
|
|
# ----------------------------------------------------------------------------------------------------
|
|
|
|
def test_cli_minimal_default():
|
|
|
|
# Act
|
2022-08-04 21:24:12 +00:00
|
|
|
actual_args = cli(['tests/data/config.yml'])
|
2021-08-22 02:21:38 +00:00
|
|
|
|
|
|
|
# Assert
|
|
|
|
assert actual_args.config_file == Path('tests/data/config.yml')
|
|
|
|
assert actual_args.regenerate == False
|
|
|
|
assert actual_args.verbose == 0
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------------------------------
|
2022-08-04 21:24:12 +00:00
|
|
|
def test_cli_invalid_config_file_path():
|
2021-08-22 02:21:38 +00:00
|
|
|
# Act
|
2022-08-04 21:24:12 +00:00
|
|
|
with pytest.raises(ValueError):
|
|
|
|
cli([f"non-existent-khoj-{random()}.yml"])
|
2021-08-22 02:21:38 +00:00
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------------------------------
|
|
|
|
def test_cli_config_from_file():
|
|
|
|
# Act
|
2022-08-04 21:24:12 +00:00
|
|
|
actual_args = cli(['tests/data/config.yml',
|
2021-08-22 02:21:38 +00:00
|
|
|
'--regenerate',
|
|
|
|
'-vvv'])
|
|
|
|
|
|
|
|
# Assert
|
|
|
|
assert actual_args.config_file == Path('tests/data/config.yml')
|
|
|
|
assert actual_args.regenerate == True
|
|
|
|
assert actual_args.config is not None
|
2022-08-04 20:26:31 +00:00
|
|
|
assert actual_args.config.content_type.org.input_files == [Path('~/first_from_config.org'), Path('~/second_from_config.org')]
|
2021-08-22 02:21:38 +00:00
|
|
|
assert actual_args.verbose == 3
|