mirror of
https://github.com/dtomlinson91/tembo.git
synced 2025-12-22 10:45:45 +00:00
adding latest
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import importlib
|
||||
import os
|
||||
import pathlib
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -9,6 +10,7 @@ from tembo.cli.cli import (
|
||||
_new_verify_name_exists,
|
||||
_new_get_config_scope,
|
||||
_new_show_example,
|
||||
_new_create_scoped_page,
|
||||
)
|
||||
|
||||
|
||||
@@ -147,3 +149,97 @@ def test_new_show_example(path, message, shared_datadir, capsys):
|
||||
# assert
|
||||
assert capsys.readouterr().out == message
|
||||
assert system_exit.value.code == 0
|
||||
|
||||
|
||||
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 == ""
|
||||
|
||||
|
||||
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'
|
||||
)
|
||||
|
||||
|
||||
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'
|
||||
)
|
||||
|
||||
|
||||
@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:
|
||||
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
|
||||
assert (
|
||||
capsys.readouterr().out
|
||||
== f'[TEMBO] Your tembo config.yml/template specifies 0 input tokens, you gave 1. Example: tembo new some_scope 🐘\n'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user