2023-09-22 18:04:39 +00:00
|
|
|
from papis.document import Document
|
2024-01-20 15:34:10 +00:00
|
|
|
from papis_extract.annotation import Annotation
|
2023-08-31 19:32:24 +00:00
|
|
|
|
2023-09-22 18:04:39 +00:00
|
|
|
from papis_extract.formatter import (
|
|
|
|
format_count,
|
|
|
|
format_csv,
|
|
|
|
format_markdown,
|
|
|
|
format_markdown_atx,
|
2023-10-12 17:27:16 +00:00
|
|
|
format_markdown_setext,
|
2023-09-22 18:04:39 +00:00
|
|
|
)
|
2023-09-19 15:35:39 +00:00
|
|
|
|
2024-01-20 15:34:10 +00:00
|
|
|
document = Document(data={"author": "document-author", "title": "document-title"})
|
|
|
|
annotations = [
|
|
|
|
Annotation("myfile.pdf", text="my lovely text"),
|
|
|
|
Annotation("myfile.pdf", text="my second text", content="with note"),
|
|
|
|
]
|
2023-10-12 17:27:16 +00:00
|
|
|
md_default_output = """============== ---------------
|
2023-09-22 18:04:39 +00:00
|
|
|
document-title - document-author
|
|
|
|
============== ---------------
|
|
|
|
|
|
|
|
> my lovely text
|
|
|
|
|
|
|
|
> my second text
|
|
|
|
NOTE: with note"""
|
2023-10-12 17:27:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_markdown_default():
|
|
|
|
fmt = format_markdown
|
2024-01-20 15:34:10 +00:00
|
|
|
assert fmt(document, annotations) == md_default_output
|
2023-09-19 15:35:39 +00:00
|
|
|
|
|
|
|
|
2023-09-22 18:04:39 +00:00
|
|
|
def test_markdown_atx():
|
|
|
|
fmt = format_markdown_atx
|
2024-01-20 15:34:10 +00:00
|
|
|
assert fmt(document, annotations) == (
|
2023-09-22 18:04:39 +00:00
|
|
|
"""# document-title - document-author
|
|
|
|
|
|
|
|
> my lovely text
|
|
|
|
|
|
|
|
> my second text
|
|
|
|
NOTE: with note"""
|
2023-09-19 15:35:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-10-12 17:27:16 +00:00
|
|
|
def test_markdown_setext():
|
|
|
|
fmt = format_markdown_setext
|
2024-01-20 15:34:10 +00:00
|
|
|
assert fmt(document, annotations) == md_default_output
|
2023-10-12 17:27:16 +00:00
|
|
|
|
|
|
|
|
2023-09-22 18:04:39 +00:00
|
|
|
def test_count_default():
|
|
|
|
fmt = format_count
|
2024-01-20 15:34:10 +00:00
|
|
|
assert fmt(document, annotations) == ("""document-author - document-title: 2""")
|
2023-09-22 18:04:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_csv_default():
|
|
|
|
fmt = format_csv
|
2024-01-20 15:34:10 +00:00
|
|
|
assert fmt(document, annotations) == (
|
2023-09-22 18:04:39 +00:00
|
|
|
"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"'
|
|
|
|
)
|
2023-10-12 17:27:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
# sadpath - no annotations contained for each format
|
|
|
|
def test_markdown_no_annotations():
|
2024-01-20 15:34:10 +00:00
|
|
|
assert format_markdown(document, []) == ""
|
2023-10-12 17:27:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_count_no_annotations():
|
2024-01-20 15:34:10 +00:00
|
|
|
assert format_count(document, []) == ""
|
2023-10-12 17:27:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_csv_no_annotations():
|
2024-01-20 15:34:10 +00:00
|
|
|
assert format_csv(document, []) == ""
|