From 1e09339b32f6627fbce0de818547fe18d35fdc15 2020-05-16 13:51:02 From: Brett Smith Date: 2020-05-16 13:51:02 Subject: [PATCH] config: Make payment threshold configurable. --- diff --git a/conservancy_beancount/config.py b/conservancy_beancount/config.py index 643a1852136e711d4e90b6c42428d755a446fc55..eb09b724331282b103f5c273eef24a8c26c675e2 100644 --- a/conservancy_beancount/config.py +++ b/conservancy_beancount/config.py @@ -157,7 +157,10 @@ class Config: return books.FiscalYear(month, day) def payment_threshold(self) -> decimal.Decimal: - return decimal.Decimal(0) + try: + return decimal.Decimal(self.file_config['Beancount']['payment threshold']) + except (KeyError, ValueError): + return decimal.Decimal(10) def repository_path(self) -> Optional[Path]: try: diff --git a/tests/test_config.py b/tests/test_config.py index cf05f3612b604e99f187631a477265c7b20a590e..7b3ae7ee06809fed16c55292b919d41a2262decf 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -293,11 +293,22 @@ def test_relative_xdg_cache_home_ignored(tmp_path): cache_dir_path = config.cache_dir_path('TESTcache') assert cache_dir_path == tmp_path / '.cache/TESTcache' -def test_payment_threshold(): +def test_default_payment_threshold(): threshold = config_mod.Config().payment_threshold() - assert threshold == 0 assert isinstance(threshold, (int, decimal.Decimal)) +@pytest.mark.parametrize('config_threshold', [ + '15', + ' +15', + '15. ', + '15.0', + '15.00', +]) +def test_payment_threshold(config_threshold): + config = config_mod.Config() + config.load_string(f'[Beancount]\npayment threshold = {config_threshold}\n') + assert config.payment_threshold() == decimal.Decimal(15) + @pytest.mark.parametrize('config_path', [ None, '',