| 1 |
"""Test our handling of metadata in files with bibliographic metadata.""" |
| 2 |
|
| 3 |
# adapted from an example of bibliographic metadata at |
| 4 |
# https://docutils.sourceforge.io/docs/user/rst/demo.txt |
| 5 |
from __future__ import annotations |
| 6 |
|
| 7 |
from typing import TYPE_CHECKING |
| 8 |
|
| 9 |
import pytest |
| 10 |
|
| 11 |
if TYPE_CHECKING: |
| 12 |
from sphinx.testing.util import SphinxTestApp |
| 13 |
|
| 14 |
|
| 15 |
@pytest.mark.sphinx('dummy', testroot='metadata') |
| 16 |
def test_docinfo(app: SphinxTestApp) -> None: |
| 17 |
"""Inspect the 'docinfo' metadata stored in the first node of the document. |
| 18 |
Note this doesn't give us access to data stored in subsequence blocks |
| 19 |
that might be considered document metadata, such as 'abstract' or |
| 20 |
'dedication' blocks, or the 'meta' role. Doing otherwise is probably more |
| 21 |
messing with the internals of sphinx than this rare use case merits. |
| 22 |
""" |
| 23 |
app.build() |
| 24 |
expecteddocinfo = { |
| 25 |
'author': 'David Goodger', |
| 26 |
'authors': ['Me', 'Myself', 'I'], |
| 27 |
'address': '123 Example Street\nExample, EX Canada\nA1B 2C3', |
| 28 |
'field name': 'This is a generic bibliographic field.', |
| 29 |
'field name 2': ( |
| 30 |
'Generic bibliographic fields may contain multiple ' |
| 31 |
'body elements.\n\nLike this.' |
| 32 |
), |
| 33 |
'status': 'This is a “work in progress”', |
| 34 |
'version': '1', |
| 35 |
'copyright': ( |
| 36 |
'This document has been placed in the public domain. ' |
| 37 |
'You\nmay do with it as you wish. You may copy, modify,' |
| 38 |
'\nredistribute, reattribute, sell, buy, rent, lease,\n' |
| 39 |
'destroy, or improve it, quote it at length, excerpt,\n' |
| 40 |
'incorporate, collate, fold, staple, or mutilate it, or ' |
| 41 |
'do\nanything else to it that your or anyone else’s ' |
| 42 |
'heart\ndesires.' |
| 43 |
), |
| 44 |
'contact': '[email protected]', |
| 45 |
'date': '2006-05-21', |
| 46 |
'organization': 'humankind', |
| 47 |
'revision': '4564', |
| 48 |
'tocdepth': 1, |
| 49 |
'orphan': '', |
| 50 |
'nocomments': '', |
| 51 |
} |
| 52 |
assert app.env.metadata['index'] == expecteddocinfo |