Changeset - 51137815d304
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-04-21 13:07:14
brettcsmith@brettcsmith.org
config: fiscal_year_begin returns a FiscalYear.
2 files changed with 6 insertions and 3 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/config.py
Show inline comments
...
 
@@ -33,6 +33,7 @@ from typing import (
 
    Type,
 
)
 

	
 
from . import books
 
from . import rtutil
 

	
 
class RTCredentials(NamedTuple):
...
 
@@ -130,7 +131,7 @@ class Config:
 
        config_root = self._path_from_environ('XDG_CONFIG_HOME')
 
        return Path(config_root, name, 'config.ini')
 

	
 
    def fiscal_year_begin(self) -> Tuple[int, int]:
 
    def fiscal_year_begin(self) -> books.FiscalYear:
 
        s = self.file_config.get('Beancount', 'fiscal year begin', fallback='3 1')
 
        match = re.match(r'([01]?[0-9])(?:\s*[-./ ]\s*([0-3]?[0-9]))?$', s.strip())
 
        if match is None:
...
 
@@ -146,7 +147,7 @@ class Config:
 
        except ValueError as e:
 
            raise ValueError(f"fiscal year begin {s!r} is invalid date: {e.args[0]}")
 
        else:
 
            return (month, day)
 
            return books.FiscalYear(month, day)
 

	
 
    def payment_threshold(self) -> decimal.Decimal:
 
        return decimal.Decimal(0)
tests/test_config.py
Show inline comments
...
 
@@ -378,4 +378,6 @@ def test_bad_fiscal_year_begin(value):
 

	
 
def test_default_fiscal_year_begin():
 
    config = config_mod.Config()
 
    assert config.fiscal_year_begin() == (3, 1)
 
    actual = config.fiscal_year_begin()
 
    assert actual.month == 3
 
    assert actual.day == 1
0 comments (0 inline, 0 general)