mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 00:28:31 +02:00
* Add text file that should be ignored to basic test folder journal. Makes tons of tests fail * Add additional files that should be ignored by FolderJournal * Ignore all files in folder journal except year/month/day.txt * Completely remake get_files in FolderJournal: - move get_files into FolderJournal class and add underscore prefix - create iterables to get for year/month folders and day files - make year/month/day file reading strict: only exact expected months and days out of all possible months and days * Restore accidentally-deleted self.sort() line * Use match instead of string comparison to be os-agnostic * Explicitly declare static methods * Filter with glob first for max performance * Explicitly check for valid dates in FolderJournal and add unit test * Remove unneeded jrnl import * Clean up method comment and add type hints * Add is_valid_date unit test * Elucidate comment Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
44 lines
1 KiB
Python
44 lines
1 KiB
Python
# Copyright © 2012-2023 jrnl contributors
|
|
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
import datetime
|
|
|
|
import pytest
|
|
|
|
from jrnl import time
|
|
|
|
|
|
def test_default_hour_is_added():
|
|
assert time.parse(
|
|
"2020-06-20", inclusive=False, default_hour=9, default_minute=0, bracketed=False
|
|
) == datetime.datetime(2020, 6, 20, 9)
|
|
|
|
|
|
def test_default_minute_is_added():
|
|
assert time.parse(
|
|
"2020-06-20",
|
|
inclusive=False,
|
|
default_hour=0,
|
|
default_minute=30,
|
|
bracketed=False,
|
|
) == datetime.datetime(2020, 6, 20, 0, 30)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"inputs",
|
|
[
|
|
[2000, 2, 29, True],
|
|
[2023, 1, 0, False],
|
|
[2023, 1, 1, True],
|
|
[2023, 4, 31, False],
|
|
[2023, 12, 31, True],
|
|
[2023, 12, 32, False],
|
|
[2023, 13, 1, False],
|
|
[2100, 2, 27, True],
|
|
[2100, 2, 28, True],
|
|
[2100, 2, 29, False],
|
|
],
|
|
)
|
|
def test_is_valid_date(inputs):
|
|
year, month, day, expected_result = inputs
|
|
assert time.is_valid_date(year, month, day) == expected_result
|