From 05c870402d810f1776675fc87d526493edc23110 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Sun, 24 Nov 2024 17:08:19 +0100 Subject: [PATCH] Generalized testing --- test/test_obsidian_format.py | 25 ++++--------------------- test/test_obsidian_vault.py | 15 ++++++++++----- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/test/test_obsidian_format.py b/test/test_obsidian_format.py index 0e8e16c..b85c666 100644 --- a/test/test_obsidian_format.py +++ b/test/test_obsidian_format.py @@ -4,27 +4,10 @@ import pytest from obsidian_import import obsidian -EXAMPLES = [ - obsidian.Event( - datetime.time(12, 0, 0), - datetime.time(12, 0, 0), - 'Ate', - 'Lunch', - 'instantly', - ), - obsidian.Event( - datetime.time(20, 0, 0), - datetime.time(22, 0, 0), - '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]].'), -] - +from .test_obsidian_vault import EXAMPLES, EXAMPLE_DATE, EXAMPLE_TIMEZONE @pytest.mark.parametrize('event', EXAMPLES) def test_format_preserves_information(event: obsidian.Event): - formatted = obsidian.format_event_string(event) - assert obsidian.parse_event_string(formatted) == event + formatted = obsidian.format_event_string(event, EXAMPLE_TIMEZONE) + assert obsidian.parse_event_string(formatted, EXAMPLE_DATE, + EXAMPLE_TIMEZONE) == event diff --git a/test/test_obsidian_vault.py b/test/test_obsidian_vault.py index a91840f..b43bac0 100644 --- a/test/test_obsidian_vault.py +++ b/test/test_obsidian_vault.py @@ -1,19 +1,24 @@ 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.time(12, 0, 0), - datetime.time(12, 0, 0), + 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.time(20, 0, 0), - datetime.time(22, 0, 0), + 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*', @@ -33,7 +38,7 @@ def test_write_internally(): vault.path_format = 'YYYY-MM-DD' vault.template_file_path = Path('daily-template-file.md') - vault.add_events(datetime.date(2020, 1, 1), EXAMPLES) + vault.add_events(EXAMPLE_DATE, EXAMPLES) assert len(vault.internal_file_text_cache) == 2 assert vault.internal_file_text_cache[