conservancy_beancount/tests/test_ranges.py

55 lines
1.9 KiB
Python

"""test_ranges.py - Unit tests for range classes"""
# Copyright © 2020 Brett Smith
# License: AGPLv3-or-later WITH Beancount-Plugin-Additional-Permission-1.0
#
# Full copyright and licensing details can be found at toplevel file
# LICENSE.txt in the repository.
import datetime
import pytest
from conservancy_beancount import ranges
ONE_DAY = datetime.timedelta(days=1)
@pytest.mark.parametrize('start,stop', [
# One month
(datetime.date(2018, 3, 1), datetime.date(2018, 4, 1)),
# Three months
(datetime.date(2018, 6, 1), datetime.date(2018, 9, 1)),
# Six months, spanning year
(datetime.date(2018, 9, 1), datetime.date(2019, 3, 1)),
# Nine months
(datetime.date(2018, 2, 1), datetime.date(2018, 12, 1)),
# Twelve months on Jan 1
(datetime.date(2018, 1, 1), datetime.date(2019, 1, 1)),
# Twelve months spanning year
(datetime.date(2018, 3, 1), datetime.date(2019, 3, 1)),
# Eighteen months spanning year
(datetime.date(2018, 3, 1), datetime.date(2019, 9, 1)),
# Wild
(datetime.date(2018, 1, 1), datetime.date(2020, 4, 15)),
])
def test_date_range(start, stop):
date_range = ranges.DateRange(start, stop)
assert (start - ONE_DAY) not in date_range
assert start in date_range
assert (start + ONE_DAY) in date_range
assert (stop - ONE_DAY) in date_range
assert stop not in date_range
assert (stop + ONE_DAY) not in date_range
def test_date_range_one_day():
start = datetime.date(2018, 7, 1)
date_range = ranges.DateRange(start, start + ONE_DAY)
assert (start - ONE_DAY) not in date_range
assert start in date_range
assert (start + ONE_DAY) not in date_range
def test_date_range_empty():
date = datetime.date(2018, 8, 10)
date_range = ranges.DateRange(date, date)
assert (date - ONE_DAY) not in date_range
assert date not in date_range
assert (date + ONE_DAY) not in date_range