mirror of
https://github.com/dtomlinson91/tembo.git
synced 2025-12-22 05:55:44 +00:00
adding latest tests
This commit is contained in:
8
tests/test_cli/data/config/missing_template/config.yml
Normal file
8
tests/test_cli/data/config/missing_template/config.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
tembo:
|
||||||
|
scopes:
|
||||||
|
- name: some_scope
|
||||||
|
example: tembo new some_scope
|
||||||
|
path: some_scope
|
||||||
|
filename: "{name}"
|
||||||
|
extension: md
|
||||||
|
template_filename: some_nonexistent_template.md.tpl
|
||||||
@@ -5,6 +5,10 @@
|
|||||||
path: "some_scope"
|
path: "some_scope"
|
||||||
filename: "{name}"
|
filename: "{name}"
|
||||||
extension: md
|
extension: md
|
||||||
|
- name: some_scope_no_example
|
||||||
|
path: "some_scope"
|
||||||
|
filename: "{name}"
|
||||||
|
extension: md
|
||||||
- name: another_some_scope
|
- name: another_some_scope
|
||||||
example: tembo new another_some_scope
|
example: tembo new another_some_scope
|
||||||
path: "another_some_scope"
|
path: "another_some_scope"
|
||||||
|
|||||||
@@ -4,270 +4,8 @@ import pathlib
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import tembo.exceptions
|
|
||||||
import tembo.cli
|
import tembo.cli
|
||||||
from tembo.cli.cli import (
|
from tembo.cli.cli import new, list_all
|
||||||
_new_verify_name_exists,
|
|
||||||
_new_get_config_scope,
|
|
||||||
_new_show_example,
|
|
||||||
new_create_scoped_page,
|
|
||||||
new,
|
|
||||||
list_all,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_new_verify_name_exists_success(shared_datadir):
|
|
||||||
# arrange
|
|
||||||
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "success")
|
|
||||||
importlib.reload(tembo.cli)
|
|
||||||
|
|
||||||
# act
|
|
||||||
verified_name = _new_verify_name_exists("some_scope")
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert verified_name is None
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
del os.environ["TEMBO_CONFIG"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_new_verify_name_exists_scope_not_found(shared_datadir):
|
|
||||||
# arrange
|
|
||||||
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "success")
|
|
||||||
importlib.reload(tembo.cli)
|
|
||||||
|
|
||||||
# act
|
|
||||||
with pytest.raises(tembo.exceptions.ScopeNotFound) as scope_not_found:
|
|
||||||
_new_verify_name_exists("some_missing_scope")
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert (
|
|
||||||
str(scope_not_found.value) == "Scope some_missing_scope not found in config.yml"
|
|
||||||
)
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
del os.environ["TEMBO_CONFIG"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_new_verify_name_exists_empty_config(shared_datadir):
|
|
||||||
# arrange
|
|
||||||
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "empty")
|
|
||||||
importlib.reload(tembo.cli)
|
|
||||||
|
|
||||||
# act
|
|
||||||
with pytest.raises(tembo.exceptions.EmptyConfigYML) as empty_config_yml:
|
|
||||||
_new_verify_name_exists("some_missing_scope")
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert (
|
|
||||||
str(empty_config_yml.value)
|
|
||||||
== f'Config.yml found in {os.environ["TEMBO_CONFIG"]} is empty'
|
|
||||||
)
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
del os.environ["TEMBO_CONFIG"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_new_verify_name_exists_missing_config(shared_datadir):
|
|
||||||
# arrange
|
|
||||||
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "missing")
|
|
||||||
importlib.reload(tembo.cli)
|
|
||||||
|
|
||||||
# act
|
|
||||||
with pytest.raises(tembo.exceptions.MissingConfigYML) as missing_config_yml:
|
|
||||||
_new_verify_name_exists("some_missing_scope")
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert (
|
|
||||||
str(missing_config_yml.value)
|
|
||||||
== f'No config.yml found in {os.environ["TEMBO_CONFIG"]}'
|
|
||||||
)
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
del os.environ["TEMBO_CONFIG"]
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
config_scope = _new_get_config_scope("some_scope")
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert config_scope == {
|
|
||||||
"name": "some_scope",
|
|
||||||
"path": "some_scope",
|
|
||||||
"filename": "{name}",
|
|
||||||
"extension": "md",
|
|
||||||
"example": None,
|
|
||||||
"template_filename": None,
|
|
||||||
}
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
del os.environ["TEMBO_CONFIG"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_new_get_config_scope_key_not_found(shared_datadir):
|
|
||||||
# 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"
|
|
||||||
)
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
del os.environ["TEMBO_CONFIG"]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"path,message",
|
|
||||||
[
|
|
||||||
("success", "[TEMBO] Example for some_scope: tembo new some_scope 🐘\n"),
|
|
||||||
("optional_keys", "[TEMBO] No example in config.yml 🐘\n"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_new_show_example(path, message, shared_datadir, capsys):
|
|
||||||
# arrange
|
|
||||||
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / path)
|
|
||||||
importlib.reload(tembo.cli)
|
|
||||||
config_scope = _new_get_config_scope("some_scope")
|
|
||||||
|
|
||||||
# act
|
|
||||||
with pytest.raises(SystemExit) as system_exit:
|
|
||||||
_new_show_example(True, config_scope)
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert capsys.readouterr().out == message
|
|
||||||
assert system_exit.value.code == 0
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
del os.environ["TEMBO_CONFIG"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_new_create_scoped_page_success(shared_datadir, tmpdir):
|
|
||||||
# arrange
|
|
||||||
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "success")
|
|
||||||
os.environ["TEMBO_BASE_PATH"] = str(tmpdir)
|
|
||||||
importlib.reload(tembo.cli)
|
|
||||||
|
|
||||||
config_scope = _new_get_config_scope("some_scope")
|
|
||||||
inputs = ()
|
|
||||||
scoped_page_file = pathlib.Path(tmpdir / "some_scope" / "some_scope").with_suffix(
|
|
||||||
".md"
|
|
||||||
)
|
|
||||||
|
|
||||||
# act
|
|
||||||
scoped_page = new_create_scoped_page(config_scope, inputs)
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert scoped_page.path == scoped_page_file
|
|
||||||
assert scoped_page.page_content == ""
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
del os.environ["TEMBO_CONFIG"]
|
|
||||||
del os.environ["TEMBO_BASE_PATH"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_new_create_scoped_page_base_path_does_not_exist(
|
|
||||||
shared_datadir, tmpdir, capsys
|
|
||||||
):
|
|
||||||
# arrange
|
|
||||||
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "success")
|
|
||||||
os.environ["TEMBO_BASE_PATH"] = str(tmpdir / "nonexistent" / "path")
|
|
||||||
importlib.reload(tembo.cli)
|
|
||||||
|
|
||||||
config_scope = _new_get_config_scope("some_scope")
|
|
||||||
inputs = ()
|
|
||||||
|
|
||||||
# act
|
|
||||||
with pytest.raises(SystemExit) as system_exit:
|
|
||||||
new_create_scoped_page(config_scope, inputs)
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert system_exit.value.code == 1
|
|
||||||
assert (
|
|
||||||
capsys.readouterr().out
|
|
||||||
== f'[TEMBO] Tembo base path of {os.environ["TEMBO_BASE_PATH"]} does not exist. 🐘\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
del os.environ["TEMBO_CONFIG"]
|
|
||||||
del os.environ["TEMBO_BASE_PATH"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_new_create_scoped_page_template_file_does_not_exist(
|
|
||||||
shared_datadir, tmpdir, capsys
|
|
||||||
):
|
|
||||||
# arrange
|
|
||||||
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "success")
|
|
||||||
os.environ["TEMBO_BASE_PATH"] = str(tmpdir)
|
|
||||||
os.environ["TEMBO_TEMPLATE_PATH"] = str(tmpdir)
|
|
||||||
importlib.reload(tembo.cli)
|
|
||||||
|
|
||||||
config_scope = _new_get_config_scope("some_scope")
|
|
||||||
config_scope["template_filename"] = "some_nonexistent_template.md.tpl"
|
|
||||||
inputs = ()
|
|
||||||
|
|
||||||
# act
|
|
||||||
with pytest.raises(SystemExit) as system_exit:
|
|
||||||
new_create_scoped_page(config_scope, inputs)
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert system_exit.value.code == 1
|
|
||||||
assert (
|
|
||||||
capsys.readouterr().out
|
|
||||||
== f'[TEMBO] Template file {os.environ["TEMBO_TEMPLATE_PATH"]}/{config_scope["template_filename"]} does not exist. 🐘\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
del os.environ["TEMBO_CONFIG"]
|
|
||||||
del os.environ["TEMBO_BASE_PATH"]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("example", [(True,), (False,)])
|
|
||||||
def test_new_create_scoped_page_mismatched_token(
|
|
||||||
example, shared_datadir, tmpdir, capsys
|
|
||||||
):
|
|
||||||
# arrange
|
|
||||||
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "success")
|
|
||||||
os.environ["TEMBO_BASE_PATH"] = str(tmpdir)
|
|
||||||
importlib.reload(tembo.cli)
|
|
||||||
|
|
||||||
config_scope = _new_get_config_scope("some_scope")
|
|
||||||
inputs = ("some_input",)
|
|
||||||
if not example[0]:
|
|
||||||
config_scope["example"] = None
|
|
||||||
|
|
||||||
# act
|
|
||||||
with pytest.raises(SystemExit) as system_exit:
|
|
||||||
new_create_scoped_page(config_scope, inputs)
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert system_exit.value.code == 1
|
|
||||||
if not example[0]:
|
|
||||||
assert (
|
|
||||||
capsys.readouterr().out
|
|
||||||
== f"[TEMBO] Your tembo config.yml/template specifies 0 input tokens, you gave 1 🐘\n"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
assert (
|
|
||||||
capsys.readouterr().out
|
|
||||||
== f"[TEMBO] Your tembo config.yml/template specifies 0 input tokens, you gave 1. Example: tembo new some_scope 🐘\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
del os.environ["TEMBO_CONFIG"]
|
|
||||||
del os.environ["TEMBO_BASE_PATH"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_new_dry_run(shared_datadir, tmpdir, capsys):
|
def test_new_dry_run(shared_datadir, tmpdir, capsys):
|
||||||
@@ -360,7 +98,7 @@ def test_new_scope_not_found(shared_datadir, tmpdir, capsys):
|
|||||||
assert system_exit.value.code == 1
|
assert system_exit.value.code == 1
|
||||||
assert (
|
assert (
|
||||||
capsys.readouterr().out
|
capsys.readouterr().out
|
||||||
== f"[TEMBO] Scope some_nonexistent_scope not found in config.yml 🐘\n"
|
== "[TEMBO] Scope some_nonexistent_scope not found in config.yml 🐘\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
# cleanup
|
# cleanup
|
||||||
@@ -425,7 +163,7 @@ def test_new_missing_mandatory_key(shared_datadir, tmpdir, capsys):
|
|||||||
# assert
|
# assert
|
||||||
assert system_exit.value.code == 1
|
assert system_exit.value.code == 1
|
||||||
assert (
|
assert (
|
||||||
capsys.readouterr().out == f"[TEMBO] Key 'filename' not found in config.yml 🐘\n"
|
capsys.readouterr().out == "[TEMBO] Key 'filename' not found in config.yml 🐘\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
# cleanup
|
# cleanup
|
||||||
@@ -433,6 +171,113 @@ def test_new_missing_mandatory_key(shared_datadir, tmpdir, capsys):
|
|||||||
del os.environ["TEMBO_BASE_PATH"]
|
del os.environ["TEMBO_BASE_PATH"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"path,message",
|
||||||
|
[
|
||||||
|
("success", "[TEMBO] Example for some_scope: tembo new some_scope 🐘\n"),
|
||||||
|
("optional_keys", "[TEMBO] No example in config.yml 🐘\n"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_new_show_example(path, message, shared_datadir, capsys):
|
||||||
|
# arrange
|
||||||
|
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / path)
|
||||||
|
importlib.reload(tembo.cli)
|
||||||
|
|
||||||
|
# act
|
||||||
|
with pytest.raises(SystemExit) as system_exit:
|
||||||
|
new(["some_scope", "--example"])
|
||||||
|
|
||||||
|
# assert
|
||||||
|
assert system_exit.value.code == 0
|
||||||
|
assert capsys.readouterr().out == message
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
del os.environ["TEMBO_CONFIG"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_new_base_path_does_not_exist(shared_datadir, tmpdir, capsys):
|
||||||
|
# arrange
|
||||||
|
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "success")
|
||||||
|
os.environ["TEMBO_BASE_PATH"] = str(tmpdir / "nonexistent" / "path")
|
||||||
|
importlib.reload(tembo.cli)
|
||||||
|
|
||||||
|
# act
|
||||||
|
with pytest.raises(SystemExit) as system_exit:
|
||||||
|
new(["some_scope"])
|
||||||
|
|
||||||
|
# assert
|
||||||
|
assert system_exit.value.code == 1
|
||||||
|
assert (
|
||||||
|
capsys.readouterr().out
|
||||||
|
== f"[TEMBO] Tembo base path of {tmpdir}/nonexistent/path does not exist. 🐘\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
del os.environ["TEMBO_CONFIG"]
|
||||||
|
del os.environ["TEMBO_BASE_PATH"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_new_template_file_does_not_exist(shared_datadir, tmpdir, capsys):
|
||||||
|
# arrange
|
||||||
|
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "missing_template")
|
||||||
|
os.environ["TEMBO_BASE_PATH"] = str(tmpdir)
|
||||||
|
os.environ["TEMBO_TEMPLATE_PATH"] = str(tmpdir)
|
||||||
|
importlib.reload(tembo.cli)
|
||||||
|
|
||||||
|
# act
|
||||||
|
with pytest.raises(SystemExit) as system_exit:
|
||||||
|
new(["some_scope"])
|
||||||
|
|
||||||
|
# assert
|
||||||
|
assert (
|
||||||
|
capsys.readouterr().out
|
||||||
|
== f"[TEMBO] Template file {tmpdir}/some_nonexistent_template.md.tpl does not exist. 🐘\n"
|
||||||
|
)
|
||||||
|
assert system_exit.value.code == 1
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
del os.environ["TEMBO_CONFIG"]
|
||||||
|
del os.environ["TEMBO_TEMPLATE_PATH"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_new_mismatched_tokens_with_example(shared_datadir, tmpdir, capsys):
|
||||||
|
# arrange
|
||||||
|
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "success")
|
||||||
|
os.environ["TEMBO_BASE_PATH"] = str(tmpdir)
|
||||||
|
importlib.reload(tembo.cli)
|
||||||
|
|
||||||
|
# act
|
||||||
|
with pytest.raises(SystemExit) as system_exit:
|
||||||
|
new(["some_scope", "input0", "input1"])
|
||||||
|
|
||||||
|
# assert
|
||||||
|
assert system_exit.value.code == 1
|
||||||
|
capsys.readouterr().out == "[TEMBO] Your tembo config.yml/template specifies 0 input tokens, you gave 2. Example: tembo new some_scope 🐘\n"
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
del os.environ["TEMBO_CONFIG"]
|
||||||
|
del os.environ["TEMBO_BASE_PATH"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_new_mismatched_tokens_without_example(shared_datadir, tmpdir, capsys):
|
||||||
|
# arrange
|
||||||
|
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "success")
|
||||||
|
os.environ["TEMBO_BASE_PATH"] = str(tmpdir)
|
||||||
|
importlib.reload(tembo.cli)
|
||||||
|
|
||||||
|
# act
|
||||||
|
with pytest.raises(SystemExit) as system_exit:
|
||||||
|
new(["some_scope_no_example", "input0", "input1"])
|
||||||
|
|
||||||
|
# assert
|
||||||
|
assert system_exit.value.code == 1
|
||||||
|
capsys.readouterr().out == "[TEMBO] Your tembo config.yml/template specifies 0 input tokens, you gave 2 🐘\n"
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
del os.environ["TEMBO_CONFIG"]
|
||||||
|
del os.environ["TEMBO_BASE_PATH"]
|
||||||
|
|
||||||
|
|
||||||
def test_list_all_success(shared_datadir, tmpdir, capsys):
|
def test_list_all_success(shared_datadir, tmpdir, capsys):
|
||||||
# arrange
|
# arrange
|
||||||
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "success")
|
os.environ["TEMBO_CONFIG"] = str(shared_datadir / "config" / "success")
|
||||||
@@ -450,7 +295,7 @@ def test_list_all_success(shared_datadir, tmpdir, capsys):
|
|||||||
assert system_exit.value.code == 0
|
assert system_exit.value.code == 0
|
||||||
assert (
|
assert (
|
||||||
capsys.readouterr().out
|
capsys.readouterr().out
|
||||||
== f"[TEMBO] 2 names found in config.yml: 'some_scope', 'another_some_scope' 🐘\n"
|
== "[TEMBO] 3 names found in config.yml: 'some_scope', 'some_scope_no_example', 'another_some_scope' 🐘\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
# cleanup
|
# cleanup
|
||||||
|
|||||||
Reference in New Issue
Block a user