diff --git a/conservancy_beancount/books.py b/conservancy_beancount/books.py index c939e5b1242cf9b379713653c569a97fd8daa30d..072fbb65bf99c253e9cab1fcc3391f05481ac41d 100644 --- a/conservancy_beancount/books.py +++ b/conservancy_beancount/books.py @@ -18,13 +18,19 @@ import datetime from pathlib import Path +from beancount import loader as bc_loader + from typing import ( + Any, Iterable, Mapping, NamedTuple, Optional, Union, ) +from .beancount_types import ( + LoadResult, +) PathLike = Union[str, Path] PluginsSpec = Mapping[str, Optional[str]] @@ -147,3 +153,18 @@ class Loader: books_start, *(self._format_include(year) for year in years), ]) + + def load_fy_range(self, + from_fy: Year, + to_fy: Optional[Year]=None, + plugins: Optional[PluginsSpec]=None, + ) -> LoadResult: + """Load books for a range of fiscal years + + This is a convenience wrapper to call + self.fy_range_string(from_fy, to_fy, plugins) + and load the result with beancount.loader.load_string. + """ + return bc_loader.load_string( # type:ignore[no-untyped-call, no-any-return] + self.fy_range_string(from_fy, to_fy, plugins), + ) diff --git a/tests/test_books_loader.py b/tests/test_books_loader.py index fb92e4ac1f68528d0d1eb95ec75453a952a88612..058ad75be59e53cd52ca598759fe769c0b48ea31 100644 --- a/tests/test_books_loader.py +++ b/tests/test_books_loader.py @@ -14,6 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import hashlib + from datetime import date from pathlib import Path @@ -74,3 +76,8 @@ def test_fy_range_string_plugins_override(conservancy_loader, plugins): def test_fy_range_string_empty_range(conservancy_loader): assert conservancy_loader.fy_range_string(2020, 2019) == '' + +def test_load_fy_range_empty(conservancy_loader): + entries, errors, options_map = conservancy_loader.load_fy_range(2020, 2019) + assert not entries + assert options_map.get('input_hash') == hashlib.md5().hexdigest()