Skip to content

Commit 10e1cbc

Browse files
committed
test: cover template discovery metadata
1 parent f638865 commit 10e1cbc

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

docs/templates.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ Built-in templates are located in the ``onecite/templates/`` directory:
3535
- ``software.yaml``
3636
- ``dataset.yaml``
3737

38+
Inspecting Templates from the CLI
39+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40+
41+
Use ``onecite templates`` to list the bundled fallback BibTeX templates and
42+
their required / optional fields::
43+
44+
onecite templates
45+
46+
Use JSON output when another tool needs to inspect the same metadata::
47+
48+
onecite templates --json
49+
3850
What Templates Actually Do
3951
---------------------------
4052

onecite/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def load_template(self, template_name: str) -> Dict[str, Any]:
103103
return self._get_default_template()
104104

105105
def list_templates(self) -> List[Dict[str, Any]]:
106-
"""Return metadata for the built-in YAML templates.
106+
"""Return metadata for the configured YAML template directory.
107107
108108
Returns:
109109
A list of dictionaries sorted by template name. Each item

tests/test_templates.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,38 @@
66
here; users can add custom ones at runtime.
77
"""
88

9+
from onecite.core import TemplateLoader
10+
911

1012
class TestTemplates:
1113

14+
def test_list_templates_schema(self):
15+
templates = TemplateLoader().list_templates()
16+
names = [template["name"] for template in templates]
17+
18+
assert names == sorted(names)
19+
assert "journal_article_full" in names
20+
21+
journal_template = next(
22+
template
23+
for template in templates
24+
if template["name"] == "journal_article_full"
25+
)
26+
assert set(journal_template) == {
27+
"name",
28+
"entry_type",
29+
"required_fields",
30+
"optional_fields",
31+
}
32+
assert journal_template["entry_type"] == "@article"
33+
assert journal_template["required_fields"] == [
34+
"author",
35+
"title",
36+
"journal",
37+
"year",
38+
]
39+
assert "abstract" in journal_template["optional_fields"]
40+
1241
def test_default_template(self, sample_references, run_onecite_process):
1342
"""journal_article_full is the default when no --template is given."""
1443
code, out, err, _ = run_onecite_process(sample_references["doi_only"])

0 commit comments

Comments
 (0)