-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_index.py
51 lines (36 loc) · 1.27 KB
/
test_index.py
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
import pytest
from index import create_index, group_notes_by_tag, INDEX_NAME, NOTES_DIR
EXPECTED_OUTPUT = """# Notes index
## Productivity
- [Pybites productivity tips](notes/20220817104440.md)
## Python
- [Enumerate](notes/20220817104441.md)
- [Pathlib](notes/20220817104442.md)
- [Pybites productivity tips](notes/20220817104440.md)
"""
@pytest.fixture
def notes_dir(tmp_path):
notes_dir = tmp_path / NOTES_DIR
notes_dir.mkdir()
return notes_dir
@pytest.fixture
def create_notes(notes_dir):
note_base = "2022081710444"
notes = (
"# Pybites productivity tips\n\nblabla\n\n#productivity #Python",
"# enumerate\n\nfor i, line in enumerate(lines, start=1):\n\n#python",
"# pathlib\n\nyou can use home() and cwd() on a Path object\n\n#python",
)
for i, note in enumerate(notes):
file = notes_dir / f"{note_base}{i}.md"
with open(file, "w") as f:
f.write(note + "\n")
def test_create_index(create_notes, notes_dir):
tag_index_tree = group_notes_by_tag(notes_dir)
create_index(tag_index_tree)
with open(INDEX_NAME) as f:
content = f.read().strip()
# stripping off header
actual = content.splitlines()[5:]
expected = EXPECTED_OUTPUT.splitlines()[2:]
assert actual == expected