mirror of
https://github.com/dtomlinson91/tembo.git
synced 2025-12-22 06:05:44 +00:00
adding latest tests
This commit is contained in:
@@ -46,7 +46,8 @@ Functionality:
|
|||||||
VSCode:
|
VSCode:
|
||||||
PyInstaller:
|
PyInstaller:
|
||||||
☐ Document build error: <https://github.com/pyenv/pyenv/issues/1095>
|
☐ Document build error: <https://github.com/pyenv/pyenv/issues/1095>
|
||||||
PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.8.11
|
PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.8.11 mac
|
||||||
|
PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.8.11 linux
|
||||||
☐ Freeze a click app: <https://stackoverflow.com/questions/45090083/freeze-a-program-created-with-pythons-click-pacage>
|
☐ Freeze a click app: <https://stackoverflow.com/questions/45090083/freeze-a-program-created-with-pythons-click-pacage>
|
||||||
☐ If python 3.9 can be used with Pyinstaller, rewrite the code to use the latest Python features
|
☐ If python 3.9 can be used with Pyinstaller, rewrite the code to use the latest Python features
|
||||||
dict.update -> |=
|
dict.update -> |=
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ def new(scope, inputs, dry_run, example):
|
|||||||
|
|
||||||
Example: tembo new meeting my_presentation
|
Example: tembo new meeting my_presentation
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# get the name from the tembo config.yml
|
# get the name from the tembo config.yml
|
||||||
try:
|
try:
|
||||||
_name_found = scope in [
|
_name_found = scope in [
|
||||||
@@ -86,6 +87,7 @@ def new(scope, inputs, dry_run, example):
|
|||||||
"Key %s not found in config. yml - exiting", key_error
|
"Key %s not found in config. yml - exiting", key_error
|
||||||
)
|
)
|
||||||
raise SystemExit(1) from key_error
|
raise SystemExit(1) from key_error
|
||||||
|
|
||||||
# print the example to the user
|
# print the example to the user
|
||||||
if example:
|
if example:
|
||||||
tembo.logger.info(
|
tembo.logger.info(
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ class PageCreatorOptions:
|
|||||||
filename: str
|
filename: str
|
||||||
extension: str
|
extension: str
|
||||||
name: str
|
name: str
|
||||||
example: str | None
|
|
||||||
user_input: Collection[str]
|
user_input: Collection[str]
|
||||||
template_filename: str | None
|
example: str | None = None
|
||||||
template_path: str | None
|
template_filename: str | None = None
|
||||||
|
template_path: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class PageCreator:
|
class PageCreator:
|
||||||
@@ -60,7 +60,7 @@ class PageCreator:
|
|||||||
) -> str:
|
) -> str:
|
||||||
# check for overriden template_path
|
# check for overriden template_path
|
||||||
if template_path is not None:
|
if template_path is not None:
|
||||||
converted_template_path = self._convert_to_path("", template_path, "", "")
|
converted_template_path = pathlib.Path(template_path).expanduser()
|
||||||
else:
|
else:
|
||||||
# default template_path is base_path / .templates
|
# default template_path is base_path / .templates
|
||||||
converted_template_path = self._convert_to_path(
|
converted_template_path = self._convert_to_path(
|
||||||
@@ -132,6 +132,15 @@ class ScopedPageCreator(PageCreator):
|
|||||||
)
|
)
|
||||||
return ScopedPage(path, template_contents)
|
return ScopedPage(path, template_contents)
|
||||||
|
|
||||||
|
def _get_template_contents(
|
||||||
|
self, template_filename: str | None, template_path: str | None
|
||||||
|
) -> str:
|
||||||
|
return (
|
||||||
|
self._load_template(self.base_path, template_filename, template_path)
|
||||||
|
if template_filename is not None
|
||||||
|
else ""
|
||||||
|
)
|
||||||
|
|
||||||
def _get_input_tokens(
|
def _get_input_tokens(
|
||||||
self, template_filename: str | None, template_path: str | None
|
self, template_filename: str | None, template_path: str | None
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
@@ -168,15 +177,6 @@ class ScopedPageCreator(PageCreator):
|
|||||||
)
|
)
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
def _get_template_contents(
|
|
||||||
self, template_filename: str | None, template_path: str | None
|
|
||||||
) -> str:
|
|
||||||
return (
|
|
||||||
self._load_template(self.base_path, template_filename, template_path)
|
|
||||||
if template_filename is not None
|
|
||||||
else ""
|
|
||||||
)
|
|
||||||
|
|
||||||
def _substitute_tokens(
|
def _substitute_tokens(
|
||||||
self,
|
self,
|
||||||
tokenified_string: str,
|
tokenified_string: str,
|
||||||
|
|||||||
126
tests/test_journal/old_test_pages.py
Normal file
126
tests/test_journal/old_test_pages.py
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
import pathlib
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import jinja2
|
||||||
|
|
||||||
|
from tembo.journal.pages import PageCreator, ScopedPageCreator
|
||||||
|
|
||||||
|
|
||||||
|
def test_page_creator_convert_to_path_missing_base_path(caplog):
|
||||||
|
# arrange
|
||||||
|
base_path = "/some/nonexistent/path"
|
||||||
|
page_path = "some_page"
|
||||||
|
filename = "some_filename"
|
||||||
|
extension = "ex"
|
||||||
|
|
||||||
|
# act
|
||||||
|
with pytest.raises(SystemExit) as system_exit:
|
||||||
|
PageCreator._convert_to_path(
|
||||||
|
base_path=base_path,
|
||||||
|
page_path=page_path,
|
||||||
|
filename=filename,
|
||||||
|
extension=extension,
|
||||||
|
)
|
||||||
|
|
||||||
|
# assert
|
||||||
|
assert system_exit.value.code == 1
|
||||||
|
assert caplog.records[0].levelname == "CRITICAL"
|
||||||
|
assert (
|
||||||
|
caplog.records[0].message
|
||||||
|
== "Tembo base path of /some/nonexistent/path does not exist - exiting"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"page_path,filename,extension",
|
||||||
|
[
|
||||||
|
("some_pagepath", "some_filename", "ex"),
|
||||||
|
("some pagepath", "some filename", "ex"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_page_creator_convert_to_path_full_path_to_file(
|
||||||
|
page_path, filename, extension, tmpdir
|
||||||
|
):
|
||||||
|
# arrange
|
||||||
|
path_to_file = (
|
||||||
|
pathlib.Path(tmpdir)
|
||||||
|
/ pathlib.Path(page_path)
|
||||||
|
/ pathlib.Path(filename).with_suffix(f".{extension}")
|
||||||
|
)
|
||||||
|
base_path = tmpdir
|
||||||
|
|
||||||
|
# act
|
||||||
|
converted_path = PageCreator._convert_to_path(
|
||||||
|
base_path, page_path, filename, extension
|
||||||
|
)
|
||||||
|
|
||||||
|
# assert
|
||||||
|
assert str(path_to_file).replace(" ", "_") == str(converted_path)
|
||||||
|
|
||||||
|
|
||||||
|
def test_page_creator_convert_to_path_full_path_no_file(tmpdir):
|
||||||
|
# arrange
|
||||||
|
full_path = pathlib.Path("/some/path")
|
||||||
|
base_path = ""
|
||||||
|
page_path = "/some/path"
|
||||||
|
filename = ""
|
||||||
|
extension = ""
|
||||||
|
|
||||||
|
# act
|
||||||
|
converted_path = PageCreator._convert_to_path(
|
||||||
|
base_path, page_path, filename, extension
|
||||||
|
)
|
||||||
|
|
||||||
|
# assert
|
||||||
|
assert str(full_path).replace(" ", "_") == str(converted_path)
|
||||||
|
|
||||||
|
|
||||||
|
def test_page_creator_load_template_with_base_path_success(datadir):
|
||||||
|
# arrange
|
||||||
|
# default template_path would be datadir/.templates
|
||||||
|
base_path = str(datadir)
|
||||||
|
template_filename = "some_template.md.tpl"
|
||||||
|
|
||||||
|
# act
|
||||||
|
template_contents = ScopedPageCreator()._load_template(
|
||||||
|
base_path, template_filename, None
|
||||||
|
)
|
||||||
|
|
||||||
|
# assert
|
||||||
|
assert template_contents == "template contents"
|
||||||
|
|
||||||
|
|
||||||
|
def test_page_creator_load_template_overriden_template_path_success(datadir):
|
||||||
|
# arrange
|
||||||
|
base_path = str(datadir)
|
||||||
|
template_filename = "some_template.md.tpl"
|
||||||
|
template_path = str(datadir / ".templates")
|
||||||
|
|
||||||
|
# act
|
||||||
|
# we explicitly pass in the template_path to override the default
|
||||||
|
template_contents = ScopedPageCreator()._load_template(
|
||||||
|
base_path, template_filename, template_path
|
||||||
|
)
|
||||||
|
|
||||||
|
# assert
|
||||||
|
assert template_contents == "template contents"
|
||||||
|
|
||||||
|
|
||||||
|
def test_page_creator_load_template_missing_template_file(datadir, caplog):
|
||||||
|
# arrange
|
||||||
|
base_path = str(datadir)
|
||||||
|
template_filename = "some_nonexistent_template.md.tpl"
|
||||||
|
template_path = str(datadir / ".templates")
|
||||||
|
|
||||||
|
# act
|
||||||
|
with pytest.raises(SystemExit) as system_exit:
|
||||||
|
template_contents = ScopedPageCreator()._load_template(
|
||||||
|
base_path, template_filename, template_path
|
||||||
|
)
|
||||||
|
|
||||||
|
# assert
|
||||||
|
assert system_exit.value.code == 1
|
||||||
|
assert caplog.records[0].message == (
|
||||||
|
f"Template file {template_path}/some_nonexistent_template.md.tpl not found "
|
||||||
|
"- exiting"
|
||||||
|
)
|
||||||
@@ -1,126 +1,13 @@
|
|||||||
import pathlib
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import jinja2
|
|
||||||
|
|
||||||
from tembo.journal.pages import PageCreator, ScopedPageCreator
|
from tembo.journal.pages import PageCreatorOptions
|
||||||
|
|
||||||
|
|
||||||
def test_page_creator_convert_to_path_missing_base_path(caplog):
|
def test_scoped_page_creator_create_page_missing_base_path():
|
||||||
# arrange
|
# arrange
|
||||||
base_path = "/some/nonexistent/path"
|
options = PageCreatorOptions()
|
||||||
page_path = "some_page"
|
|
||||||
filename = "some_filename"
|
|
||||||
extension = "ex"
|
|
||||||
|
|
||||||
# act
|
# act
|
||||||
with pytest.raises(SystemExit) as system_exit:
|
|
||||||
PageCreator._convert_to_path(
|
|
||||||
base_path=base_path,
|
|
||||||
page_path=page_path,
|
|
||||||
filename=filename,
|
|
||||||
extension=extension,
|
|
||||||
)
|
|
||||||
|
|
||||||
# assert
|
# assert
|
||||||
assert system_exit.value.code == 1
|
pass
|
||||||
assert caplog.records[0].levelname == "CRITICAL"
|
|
||||||
assert (
|
|
||||||
caplog.records[0].message
|
|
||||||
== "Tembo base path of /some/nonexistent/path does not exist - exiting"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"page_path,filename,extension",
|
|
||||||
[
|
|
||||||
("some_pagepath", "some_filename", "ex"),
|
|
||||||
("some pagepath", "some filename", "ex"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_page_creator_convert_to_path_full_path_to_file(
|
|
||||||
page_path, filename, extension, tmpdir
|
|
||||||
):
|
|
||||||
# arrange
|
|
||||||
path_to_file = (
|
|
||||||
pathlib.Path(tmpdir)
|
|
||||||
/ pathlib.Path(page_path)
|
|
||||||
/ pathlib.Path(filename).with_suffix(f".{extension}")
|
|
||||||
)
|
|
||||||
base_path = tmpdir
|
|
||||||
|
|
||||||
# act
|
|
||||||
converted_path = PageCreator._convert_to_path(
|
|
||||||
base_path, page_path, filename, extension
|
|
||||||
)
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert str(path_to_file).replace(" ", "_") == str(converted_path)
|
|
||||||
|
|
||||||
|
|
||||||
def test_page_creator_convert_to_path_full_path_no_file(tmpdir):
|
|
||||||
# arrange
|
|
||||||
full_path = pathlib.Path("/some/path")
|
|
||||||
base_path = ""
|
|
||||||
page_path = "/some/path"
|
|
||||||
filename = ""
|
|
||||||
extension = ""
|
|
||||||
|
|
||||||
# act
|
|
||||||
converted_path = PageCreator._convert_to_path(
|
|
||||||
base_path, page_path, filename, extension
|
|
||||||
)
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert str(full_path).replace(" ", "_") == str(converted_path)
|
|
||||||
|
|
||||||
|
|
||||||
def test_page_creator_load_template_with_base_path_success(datadir):
|
|
||||||
# arrange
|
|
||||||
# default template_path would be datadir/.templates
|
|
||||||
base_path = str(datadir)
|
|
||||||
template_filename = "some_template.md.tpl"
|
|
||||||
|
|
||||||
# act
|
|
||||||
template_contents = ScopedPageCreator()._load_template(
|
|
||||||
base_path, template_filename, None
|
|
||||||
)
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert template_contents == "template contents"
|
|
||||||
|
|
||||||
|
|
||||||
def test_page_creator_load_template_overriden_template_path_success(datadir):
|
|
||||||
# arrange
|
|
||||||
base_path = str(datadir)
|
|
||||||
template_filename = "some_template.md.tpl"
|
|
||||||
template_path = str(datadir / ".templates")
|
|
||||||
|
|
||||||
# act
|
|
||||||
# we explicitly pass in the template_path to override the default
|
|
||||||
template_contents = ScopedPageCreator()._load_template(
|
|
||||||
base_path, template_filename, template_path
|
|
||||||
)
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert template_contents == "template contents"
|
|
||||||
|
|
||||||
|
|
||||||
def test_page_creator_load_template_missing_template_file(datadir, caplog):
|
|
||||||
# arrange
|
|
||||||
base_path = str(datadir)
|
|
||||||
template_filename = "some_nonexistent_template.md.tpl"
|
|
||||||
template_path = str(datadir / ".templates")
|
|
||||||
|
|
||||||
# act
|
|
||||||
with pytest.raises(SystemExit) as system_exit:
|
|
||||||
template_contents = ScopedPageCreator()._load_template(
|
|
||||||
base_path, template_filename, template_path
|
|
||||||
)
|
|
||||||
|
|
||||||
# assert
|
|
||||||
assert system_exit.value.code == 1
|
|
||||||
assert (
|
|
||||||
caplog.records[0].message
|
|
||||||
== f"Template file {template_path}/some_nonexistent_template.md.tpl not found - exiting"
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user