1
0
personal-data/test/test_obsidian_vault.py

54 lines
1.5 KiB
Python
Raw Normal View History

2024-11-17 16:09:11 +00:00
import datetime
from pathlib import Path
2024-11-24 16:08:19 +00:00
from zoneinfo import ZoneInfo
2024-11-17 16:09:11 +00:00
from obsidian_import import obsidian
2024-11-24 16:08:19 +00:00
EXAMPLE_TIMEZONE = ZoneInfo('Europe/Copenhagen')
EXAMPLE_DATE = datetime.date(2020, 1, 1)
2024-11-17 16:09:11 +00:00
EXAMPLES = [
obsidian.Event(
2024-11-24 16:08:19 +00:00
datetime.datetime(2020, 1, 1, 12, 0, 0, tzinfo=EXAMPLE_TIMEZONE),
datetime.datetime(2020, 1, 1, 12, 0, 0, tzinfo=EXAMPLE_TIMEZONE),
2024-11-17 16:09:11 +00:00
'Ate',
'Lunch',
'instantly',
),
obsidian.Event(
2024-11-24 16:08:19 +00:00
datetime.datetime(2020, 1, 1, 20, 0, 0, tzinfo=EXAMPLE_TIMEZONE),
datetime.datetime(2020, 1, 1, 22, 0, 0, tzinfo=EXAMPLE_TIMEZONE),
2024-11-17 16:09:11 +00:00
'Watched',
'Tom and Jerry',
'on the *Television*',
),
obsidian.Event(None, None, None, None, 'Took a walk'),
obsidian.Event(None, None, None, None, 'Watched [[Cyberpunk: Edgerunners]].'),
]
def test_write_internally():
2024-11-17 16:09:41 +00:00
vault = obsidian.ObsidianVault(
Path('test'),
read_only=True,
allow_invalid_vault=True,
)
2024-11-17 16:09:11 +00:00
vault.daily_folder = Path('daily')
vault.path_format = 'YYYY-MM-DD'
vault.template_file_path = Path('daily-template-file.md')
2024-11-24 16:08:19 +00:00
vault.add_events(EXAMPLE_DATE, EXAMPLES)
2024-11-17 16:09:11 +00:00
assert len(vault.internal_file_text_cache) == 2
2024-11-17 16:09:41 +00:00
assert vault.internal_file_text_cache[
Path('test/daily-template-file.md')
].data.startswith(b'---\n')
2024-11-17 16:09:11 +00:00
expected_path = Path('test/daily/2020-01-01.md')
assert expected_path in vault.internal_file_text_cache
2024-11-26 22:02:38 +00:00
assert vault.internal_file_text_cache[expected_path].data.startswith(
b'---\naliases:\n',
)