config: Let user specify books dir with ~.
This commit is contained in:
		
							parent
							
								
									55de5627f2
								
							
						
					
					
						commit
						18800b249d
					
				
					 2 changed files with 6 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -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:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue