test: Fix formatting and annotation tests

This commit is contained in:
Marty Oehme 2023-09-22 20:04:39 +02:00
parent ee4690f52b
commit 1e29642cba
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
3 changed files with 77 additions and 52 deletions

View file

@ -1,49 +1,59 @@
import chevron
from papis.document import Document
from papis_extract.annotation import AnnotatedDocument, Annotation
from papis_extract.templating import Markdown, Csv
from papis_extract.formatter import (
format_count,
format_csv,
format_markdown,
format_markdown_atx,
)
def test_template_markers():
...
an_doc: AnnotatedDocument = AnnotatedDocument(
Document(data={"author": "document-author", "title": "document-title"}),
[
Annotation("myfile.pdf", text="my lovely text"),
Annotation("myfile.pdf", text="my second text", content="with note"),
],
)
def test_markdown_default():
fmt = Markdown()
assert (
chevron.render(
fmt.string,
{
"file": "somefile/somewhere.pdf",
"quote": "I am quote",
"note": "and including note.",
"page": 46,
"tag": "important",
"type": "highlight",
},
)
== "#important\n> I am quote [p. 46]\n NOTE: and including note."
fmt = format_markdown
assert fmt([an_doc]) == (
"""============== ---------------
document-title - document-author
============== ---------------
> my lovely text
> my second text
NOTE: with note"""
)
def test_csv_string():
fmt = Csv()
assert (
chevron.render(
fmt.string,
{
"file": "somefile/somewhere.pdf",
"quote": "I am quote",
"note": "and including note.",
"page": 46,
"tag": "important",
"type": "highlight",
},
)
== "highlight, important, 46, "
"I am quote, and including note., somefile/somewhere.pdf"
def test_markdown_atx():
fmt = format_markdown_atx
assert fmt([an_doc]) == (
"""# document-title - document-author
> my lovely text
> my second text
NOTE: with note"""
)
def test_csv_header():
fmt = Csv()
assert chevron.render(fmt.header, {}) == "type, tag, page, quote, note, file"
def test_count_default():
fmt = format_count
assert fmt([an_doc]) == ("""document-author - document-title: 2""")
def test_csv_default():
fmt = format_csv
assert fmt([an_doc]) == (
"type,tag,page,quote,note,author,title,ref,file\n"
'Highlight,,0,"my lovely text","","document-author",'
'"document-title","","myfile.pdf"\n'
'Highlight,,0,"my second text","with note","document-author",'
'"document-title","","myfile.pdf"'
)