mirror of
https://github.com/dtomlinson91/tembo.git
synced 2025-12-22 09:35:44 +00:00
adding latest tests
This commit is contained in:
7
.coveragerc
Normal file
7
.coveragerc
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[report]
|
||||||
|
exclude_lines =
|
||||||
|
# Have to re-enable the standard pragma
|
||||||
|
pragma: no cover
|
||||||
|
|
||||||
|
# Don't complain if tests don't hit defensive assertion code:
|
||||||
|
raise NotImplementedError
|
||||||
@@ -24,6 +24,8 @@ Documentation:
|
|||||||
☐ Document how to use pytest to read a logging message
|
☐ Document how to use pytest to read a logging message
|
||||||
<https://stackoverflow.com/questions/53125305/testing-logging-output-with-pytest>
|
<https://stackoverflow.com/questions/53125305/testing-logging-output-with-pytest>
|
||||||
|
|
||||||
|
☐ Document using datadir with a module rather than a shared one. Link to tembo as an example.
|
||||||
|
|
||||||
Functionality:
|
Functionality:
|
||||||
✔ Move any `tembo.CONFIG` calls out of `pages.py` and ensure these are passed in from the cli. @done(21-10-28 19:44)
|
✔ Move any `tembo.CONFIG` calls out of `pages.py` and ensure these are passed in from the cli. @done(21-10-28 19:44)
|
||||||
✔ Make `config scope` a dict in `cli.py`. @done(21-10-28 19:44)
|
✔ Make `config scope` a dict in `cli.py`. @done(21-10-28 19:44)
|
||||||
@@ -31,6 +33,8 @@ Functionality:
|
|||||||
✔ Add the `--example` output to the miscounted token message so the user knows the correct command to use. @done(21-10-29 00:15)
|
✔ Add the `--example` output to the miscounted token message so the user knows the correct command to use. @done(21-10-29 00:15)
|
||||||
✔ Page options dataclass @done(21-10-28 20:09)
|
✔ Page options dataclass @done(21-10-28 20:09)
|
||||||
☐ Replace loggers with `click.echo` for command outputs. Keep logging messages for actual logging messages?
|
☐ Replace loggers with `click.echo` for command outputs. Keep logging messages for actual logging messages?
|
||||||
|
☐ Look at `_convert_to_path()` and see if it can be rewritten to make it clearer when there isn't a base path.
|
||||||
|
Currently checks to see if base_path is not None but this is never the case as a string must be passed in and if there isn't a base_path we pass in an empty string.
|
||||||
☐ Replace scoped page creator inputs so that the whole class uses the options dict rather than the variables passed around.
|
☐ Replace scoped page creator inputs so that the whole class uses the options dict rather than the variables passed around.
|
||||||
☐ Use the python runner Duty
|
☐ Use the python runner Duty
|
||||||
<https://github.com/pawamoy/duty>
|
<https://github.com/pawamoy/duty>
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import jinja2
|
||||||
|
|
||||||
from tembo.journal.pages import PageCreator
|
from tembo.journal.pages import PageCreator, ScopedPageCreator
|
||||||
|
|
||||||
|
|
||||||
def test_page_creator_convert_to_path_missing_base_path(caplog):
|
def test_page_creator_convert_to_path_missing_base_path(caplog):
|
||||||
@@ -46,10 +47,11 @@ def test_page_creator_convert_to_path_full_path_to_file(
|
|||||||
/ pathlib.Path(page_path)
|
/ pathlib.Path(page_path)
|
||||||
/ pathlib.Path(filename).with_suffix(f".{extension}")
|
/ pathlib.Path(filename).with_suffix(f".{extension}")
|
||||||
)
|
)
|
||||||
|
base_path = tmpdir
|
||||||
|
|
||||||
# act
|
# act
|
||||||
converted_path = PageCreator._convert_to_path(
|
converted_path = PageCreator._convert_to_path(
|
||||||
tmpdir, page_path, filename, extension
|
base_path, page_path, filename, extension
|
||||||
)
|
)
|
||||||
|
|
||||||
# assert
|
# assert
|
||||||
@@ -59,9 +61,66 @@ def test_page_creator_convert_to_path_full_path_to_file(
|
|||||||
def test_page_creator_convert_to_path_full_path_no_file(tmpdir):
|
def test_page_creator_convert_to_path_full_path_no_file(tmpdir):
|
||||||
# arrange
|
# arrange
|
||||||
full_path = pathlib.Path("/some/path")
|
full_path = pathlib.Path("/some/path")
|
||||||
|
base_path = ""
|
||||||
|
page_path = "/some/path"
|
||||||
|
filename = ""
|
||||||
|
extension = ""
|
||||||
|
|
||||||
# act
|
# act
|
||||||
converted_path = PageCreator._convert_to_path("", "/some/path", "", "")
|
converted_path = PageCreator._convert_to_path(
|
||||||
|
base_path, page_path, filename, extension
|
||||||
|
)
|
||||||
|
|
||||||
# assert
|
# assert
|
||||||
assert str(full_path).replace(" ", "_") == str(converted_path)
|
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"
|
||||||
|
)
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
template contents
|
||||||
Reference in New Issue
Block a user