diff --git a/tests/pdfs/Information Architecture for the World Wide Web.pdf b/testdata/pdfs/Information Architecture for the World Wide Web.pdf similarity index 100% rename from tests/pdfs/Information Architecture for the World Wide Web.pdf rename to testdata/pdfs/Information Architecture for the World Wide Web.pdf diff --git a/tests/bluemaestro.py b/tests/bluemaestro.py index 501da7f..1416900 100644 --- a/tests/bluemaestro.py +++ b/tests/bluemaestro.py @@ -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: diff --git a/tests/common.py b/tests/common.py index f8fc5de..47c2991 100644 --- a/tests/common.py +++ b/tests/common.py @@ -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 diff --git a/tests/location.py b/tests/location.py index 8840901..298b7ba 100644 --- a/tests/location.py +++ b/tests/location.py @@ -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 diff --git a/tests/pdfs/test_pdfs.py b/tests/pdfs.py similarity index 59% rename from tests/pdfs/test_pdfs.py rename to tests/pdfs.py index afc35d9..b8261c5 100644 --- a/tests/pdfs/test_pdfs.py +++ b/tests/pdfs.py @@ -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. ', - 'And yet, unlearn we must, ', - '', - ]) +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 diff --git a/tests/pdfs/__init__.py b/tests/pdfs/__init__.py deleted file mode 100644 index e69de29..0000000