From 18800b249d2c3ef525f757b0817ed091edfc8f08 2020-05-17 18:52:23 From: Brett Smith Date: 2020-05-17 18:52:23 Subject: [PATCH] config: Let user specify books dir with ~. --- diff --git a/conservancy_beancount/config.py b/conservancy_beancount/config.py index eb09b724331282b103f5c273eef24a8c26c675e2..91fc3e513c48afd88fae8e5b4ebdc90b6343d36a 100644 --- a/conservancy_beancount/config.py +++ b/conservancy_beancount/config.py @@ -120,7 +120,7 @@ class Config: def books_path(self) -> Optional[Path]: try: - retval = Path(self.file_config['Beancount'].get('books dir')) + retval = Path(self.file_config['Beancount']['books dir']).expanduser() except (KeyError, ValueError): ok = False else: diff --git a/tests/test_config.py b/tests/test_config.py index f709ae1e425a2b260447397a0db358111fbec27d..bb4625a2947d7cfbc41ab2655692359ebb0d5e43 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -354,6 +354,11 @@ def test_no_books_path(): config = config_mod.Config() assert config.books_path() is None +def test_books_path_expands_user(): + config = config_mod.Config() + config.load_string('[Beancount]\nbooks dir = ~/userbooks\n') + assert config.books_path() == (Path.home() / 'userbooks') + @pytest.mark.parametrize('value,month,day', [ ('2', 2, 1), ('3 ', 3, 1),