Skip to content

Commit a01e873

Browse files
committed
add tests
1 parent 0fc3ccf commit a01e873

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

render_engine_parser/base_parsers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ def parse(
6363
"""
6464
return content
6565

66-
def create_entry(self, content: str = "Hello World", **kwargs) -> str:
66+
@staticmethod
67+
def create_entry(
68+
*, filepath: pathlib.Path | None, content: str = "Hello World", **kwargs
69+
) -> str:
6770
"""
68-
Writes the content type that would be parsed to the content_path
71+
Writes the content type that would be parsed to the content_path.
72+
73+
attrs:
74+
filepath: Only used if reading from an existing path
6975
"""
7076

7177
post = frontmatter.Post(content)

requirements.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.13
3+
# by the following command:
4+
#
5+
# pip-compile --extra=dev
6+
#
7+
coverage[toml]==7.6.1
8+
# via pytest-cov
9+
iniconfig==2.0.0
10+
# via pytest
11+
packaging==24.1
12+
# via pytest
13+
pluggy==1.5.0
14+
# via pytest
15+
pytest==8.3.2
16+
# via
17+
# pytest-cov
18+
# render_engine_parser (pyproject.toml)
19+
pytest-cov==5.0.0
20+
# via render_engine_parser (pyproject.toml)
21+
python-frontmatter==1.1.0
22+
# via render_engine_parser (pyproject.toml)
23+
pyyaml==6.0.2
24+
# via python-frontmatter
25+
ruff==0.6.4
26+
# via render_engine_parser (pyproject.toml)

tests/test_base_parser.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import frontmatter
12
import pytest
23

34
from render_engine_parser.base_parsers import BasePageParser, parse_content
@@ -52,3 +53,17 @@ def test_base_parser_parse_content_path(base_content_path):
5253

5354
expected_result = ({"title": "This is a Test"}, "# This is a Test")
5455
assert expected_result == BasePageParser.parse_content_path(base_content_path)
56+
57+
58+
def test_base_parser_net_entry():
59+
data = BasePageParser.create_entry(
60+
filepath=None, # reminder this is ignored in the base case
61+
content="This is a Test",
62+
title="Untitled Entry",
63+
slug="untitled-entry",
64+
)
65+
66+
post = frontmatter.loads(data)
67+
assert post["title"] == "Untitled Entry"
68+
assert post["slug"] == "untitled-entry"
69+
assert post.content == "This is a Test"

0 commit comments

Comments
 (0)