forked from Scrybbling-together/remarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
78 lines (58 loc) · 2.27 KB
/
Copy pathconftest.py
File metadata and controls
78 lines (58 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pathlib
from dataclasses import dataclass
import pytest
import fitz
import remarks
from tests.NotebookMetadata import NotebookMetadata
def cleanup_output_folder():
"""Remove all .md and .pdf files from the tests/out folder."""
output_root_dir = pathlib.Path("tests/out/")
for file_pattern in ['*.md', '*.pdf']:
for file in output_root_dir.glob(file_pattern):
file.unlink()
def pytest_sessionstart(session):
cleanup_output_folder()
def pytest_addoption(parser):
parser.addoption(
"--interactive",
action="store_true",
default=False,
help="run interactive tests that require developer verification"
)
def with_remarks(metadata: NotebookMetadata):
input_name = metadata.rmn_source
input_dir = pathlib.Path(input_name)
output_dir = pathlib.Path("tests/out")
if not getattr(with_remarks, f"run_{input_name}", False):
remarks.run_remarks(input_dir, output_dir)
setattr(with_remarks, f"run_{input_name}", True)
return fitz.open(output_dir/f"{metadata.notebook_name} _remarks.pdf")
@dataclass
class PageMetadata:
notebook: NotebookMetadata
page_number: int
visual_description: str
# @pytest.fixture
# def visual_inspection(notebook: NotebookMetadata, remarks_document: Document, Page: PageMetadata, question: str):
# for file in notebook.rm_files:
# if "photo" in file:
# position = file["output_document_position"]
# img_output = remarks_document[position].get_pixmap()
# img_output.save(f"tests/out/{notebook.notebook_name} - {position} - Remarks.jpg")
# shutil.copy(file["photo"], f"tests/out/{notebook.notebook_name} - {position} - ReMarkable.jpg")
@pytest.fixture
def notebook(request):
"""Return the notebook fixture specified in the test's parameters"""
return request.getfixturevalue(request.param)
@pytest.fixture
def obsidian_markdown(notebook):
output_markdown_file = pathlib.Path(f"tests/out/{notebook.notebook_name}.md")
if output_markdown_file.is_file():
with open(output_markdown_file) as f:
return f.read()
else:
return None
@pytest.fixture
def remarks_document(notebook):
"""Run remarks on the notebook and return PDF"""
return with_remarks(notebook)