1
0
personal-data/test/test_obsidian_vault.py
Jon Michael Aanes a301a37f2b
Some checks are pending
Run Python tests (through Pytest) / Test (push) Waiting to run
Verify Python project can be installed, loaded and have version checked / Test (push) Waiting to run
Ruff
2024-11-26 23:02:38 +01:00

54 lines
1.5 KiB
Python

import datetime
from pathlib import Path
from zoneinfo import ZoneInfo
from obsidian_import import obsidian
EXAMPLE_TIMEZONE = ZoneInfo('Europe/Copenhagen')
EXAMPLE_DATE = datetime.date(2020, 1, 1)
EXAMPLES = [
obsidian.Event(
datetime.datetime(2020, 1, 1, 12, 0, 0, tzinfo=EXAMPLE_TIMEZONE),
datetime.datetime(2020, 1, 1, 12, 0, 0, tzinfo=EXAMPLE_TIMEZONE),
'Ate',
'Lunch',
'instantly',
),
obsidian.Event(
datetime.datetime(2020, 1, 1, 20, 0, 0, tzinfo=EXAMPLE_TIMEZONE),
datetime.datetime(2020, 1, 1, 22, 0, 0, tzinfo=EXAMPLE_TIMEZONE),
'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():
vault = obsidian.ObsidianVault(
Path('test'),
read_only=True,
allow_invalid_vault=True,
)
vault.daily_folder = Path('daily')
vault.path_format = 'YYYY-MM-DD'
vault.template_file_path = Path('daily-template-file.md')
vault.add_events(EXAMPLE_DATE, EXAMPLES)
assert len(vault.internal_file_text_cache) == 2
assert vault.internal_file_text_cache[
Path('test/daily-template-file.md')
].data.startswith(b'---\n')
expected_path = Path('test/daily/2020-01-01.md')
assert expected_path in vault.internal_file_text_cache
assert vault.internal_file_text_cache[expected_path].data.startswith(
b'---\naliases:\n',
)