my.pdfs: reorganize tests a bit, fix mypy
This commit is contained in:
parent
5c38872efc
commit
e7604c188e
6 changed files with 23 additions and 17 deletions
|
@ -38,8 +38,8 @@ def test_old_db() -> None:
|
|||
|
||||
@pytest.fixture(autouse=True)
|
||||
def prepare():
|
||||
testdata = Path(__file__).absolute().parent.parent / 'testdata'
|
||||
bmdata = testdata / 'hpi-testdata' / 'bluemaestro'
|
||||
from .common import testdata
|
||||
bmdata = testdata() / 'hpi-testdata' / 'bluemaestro'
|
||||
assert bmdata.exists(), bmdata
|
||||
|
||||
class bluemaestro:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -18,3 +19,9 @@ def reset_modules() -> None:
|
|||
to_unload = [m for m in sys.modules if re.match(r'my[.]?', m)]
|
||||
for m in to_unload:
|
||||
del sys.modules[m]
|
||||
|
||||
|
||||
def testdata() -> Path:
|
||||
d = Path(__file__).absolute().parent.parent / 'testdata'
|
||||
assert d.exists(), d
|
||||
return d
|
||||
|
|
|
@ -32,10 +32,8 @@ def prepare(tmp_path: Path):
|
|||
|
||||
|
||||
def _prepare_google_config(tmp_path: Path):
|
||||
testdata = Path(__file__).absolute().parent.parent / 'testdata'
|
||||
assert testdata.exists(), testdata
|
||||
|
||||
track = one(testdata.rglob('italy-slovenia-2017-07-29.json'))
|
||||
from .common import testdata
|
||||
track = one(testdata().rglob('italy-slovenia-2017-07-29.json'))
|
||||
|
||||
# todo ugh. unnecessary zipping, but at the moment takeout provider doesn't support plain dirs
|
||||
import zipfile
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import inspect
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
|
||||
from my.pdfs import get_annots, annotated_pdfs
|
||||
|
||||
from .common import testdata
|
||||
|
||||
ROOT = Path(__file__).parent.absolute()
|
||||
EXPECTED_HIGHLIGHTS = set(['Since 1994, when we first began organizing web sites, we have enjoyed a rare opportunity to participate in the birth of a new discipline. ',
|
||||
EXPECTED_HIGHLIGHTS = {
|
||||
'Since 1994, when we first began organizing web sites, we have enjoyed a rare opportunity to participate in the birth of a new discipline. ',
|
||||
'And yet, unlearn we must, ',
|
||||
'',
|
||||
])
|
||||
}
|
||||
|
||||
def test_get_annots():
|
||||
|
||||
def test_get_annots() -> None:
|
||||
"""
|
||||
Test get_annots, with a real PDF file
|
||||
get_annots should return a list of three Annotation objects
|
||||
"""
|
||||
annotations = get_annots(Path(ROOT / 'Information Architecture for the World Wide Web.pdf'))
|
||||
annotations = get_annots(testdata() / 'pdfs' / 'Information Architecture for the World Wide Web.pdf')
|
||||
assert len(annotations) == 3
|
||||
assert set([a.highlight for a in annotations]) == EXPECTED_HIGHLIGHTS
|
||||
|
||||
|
||||
def test_annotated_pdfs_with_filelist():
|
||||
def test_annotated_pdfs_with_filelist() -> None:
|
||||
"""
|
||||
Test annotated_pdfs, with a real PDF file
|
||||
annotated_pdfs should return a list of one Pdf object, with three Annotations
|
||||
"""
|
||||
filelist = [Path(ROOT / 'Information Architecture for the World Wide Web.pdf')]
|
||||
filelist = [testdata() / 'pdfs' / 'Information Architecture for the World Wide Web.pdf']
|
||||
annotations_generator = annotated_pdfs(filelist=filelist, roots=None)
|
||||
|
||||
assert inspect.isgeneratorfunction(annotated_pdfs)
|
||||
|
@ -36,6 +36,7 @@ def test_annotated_pdfs_with_filelist():
|
|||
highlights_from_pdfs = []
|
||||
|
||||
for pdf_object in list(annotations_generator):
|
||||
assert not isinstance(pdf_object, Exception)
|
||||
highlights_from_pdfs.extend([a.highlight for a in pdf_object.annotations])
|
||||
|
||||
assert len(highlights_from_pdfs) == 3
|
Loading…
Add table
Reference in a new issue