diff --git a/TODO.todo b/TODO.todo index e6f1e79..1ec3271 100644 --- a/TODO.todo +++ b/TODO.todo @@ -46,6 +46,13 @@ Documentation: ☐ Can prospector ignore tests dir? document this in the gist if so ☐ Redo the documentation on a CLI, reorganise and inocropoate all the new tembo layouts + Testing: + ☐ Document importing in inidivudal tests using `importlib.reload` + Globally import the module + Use `importlib.reload(module)` in each test instead of explicitly importing the module. + This is because the import is cached. + + Functionality: ☐ Replace loggers with `click.echo` for command outputs. Keep logging messages for actual logging messages? Define a format: [TEMBO:$datetime] $message 🐘 - document this in general python for CLI diff --git a/tembo/cli/cli.py b/tembo/cli/cli.py index 2520823..2ce4c1d 100644 --- a/tembo/cli/cli.py +++ b/tembo/cli/cli.py @@ -141,9 +141,6 @@ def _new_get_config_scope(scope: str) -> dict: if key_error.args[0] in optional_keys: config_scope.update({key_error.args[0]: None}) continue - tembo.cli.logger.critical( - "Key %s not found in config. yml - exiting", key_error - ) raise exceptions.MandatoryKeyNotFound( f"Key {key_error} not found in config.yml" ) diff --git a/tests/test_cli/data/config/missing_keys/config.yml b/tests/test_cli/data/config/missing_keys/config.yml new file mode 100644 index 0000000..6f6a2f8 --- /dev/null +++ b/tests/test_cli/data/config/missing_keys/config.yml @@ -0,0 +1,5 @@ +tembo: + scopes: + - name: some_scope + path: "some_scope" + extension: md diff --git a/tests/test_cli/data/config/optional_keys/config.yml b/tests/test_cli/data/config/optional_keys/config.yml new file mode 100644 index 0000000..2af3099 --- /dev/null +++ b/tests/test_cli/data/config/optional_keys/config.yml @@ -0,0 +1,6 @@ +tembo: + scopes: + - name: some_scope + path: "some_scope" + filename: "{name}" + extension: md diff --git a/tests/test_cli/test_cli.py b/tests/test_cli/test_cli.py index ba4539f..2d56814 100644 --- a/tests/test_cli/test_cli.py +++ b/tests/test_cli/test_cli.py @@ -1,8 +1,11 @@ +import importlib import os import pytest import tembo.exceptions +import tembo.cli +from tembo.cli.cli import _new_verify_name_exists, _new_get_config_scope def test_cli_page_is_saved_success(): @@ -12,8 +15,7 @@ def test_cli_page_is_saved_success(): def test_new_verify_name_exists_success(shared_datadir): # arrange os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "success") - import tembo.cli - from tembo.cli.cli import _new_verify_name_exists + importlib.reload(tembo.cli) # act verified_name = _new_verify_name_exists("some_scope") @@ -28,7 +30,7 @@ def test_new_verify_name_exists_success(shared_datadir): def test_new_verify_name_exists_scope_not_found(shared_datadir): # arrange os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "success") - import tembo.cli + importlib.reload(tembo.cli) from tembo.cli.cli import _new_verify_name_exists # act @@ -48,7 +50,7 @@ def test_new_verify_name_exists_scope_not_found(shared_datadir): def test_new_verify_name_exists_empty_config(shared_datadir): # arrange os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "empty") - import tembo.cli + importlib.reload(tembo.cli) from tembo.cli.cli import _new_verify_name_exists # act @@ -68,7 +70,7 @@ def test_new_verify_name_exists_empty_config(shared_datadir): def test_new_verify_name_exists_missing_config(shared_datadir): # arrange os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "missing") - import tembo.cli + importlib.reload(tembo.cli) from tembo.cli.cli import _new_verify_name_exists # act @@ -85,11 +87,38 @@ def test_new_verify_name_exists_missing_config(shared_datadir): del os.environ["TEMBO_CONFIG"] -# def test_new_get_config_scope(shared_datadir): -# # arrange -# os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "success") -# import tembo.cli +def test_new_get_config_scope_success(shared_datadir): + # arrange + os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "optional_keys") + importlib.reload(tembo.cli) -# # act + # act + config_scope = _new_get_config_scope("some_scope") -# # assert + # assert + assert config_scope == { + "name": "some_scope", + "path": "some_scope", + "filename": "{name}", + "extension": "md", + "example": None, + "template_filename": None, + } + + +def test_new_get_config_scope_key_not_found(shared_datadir): + # arrange + # arrange + os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "missing_keys") + importlib.reload(tembo.cli) + + # act + with pytest.raises( + tembo.exceptions.MandatoryKeyNotFound + ) as mandatory_key_not_found: + config_scope = _new_get_config_scope("some_scope") + + # assert + assert ( + str(mandatory_key_not_found.value) == "Key 'filename' not found in config.yml" + )