File tree Expand file tree Collapse file tree 2 files changed +11
-11
lines changed
Expand file tree Collapse file tree 2 files changed +11
-11
lines changed Original file line number Diff line number Diff line change 44from yaml import safe_load , safe_dump
55
66from ocrd_models import OcrdConfig
7- from ocrd_utils import XDG_CONFIG_HOME , VERSION
7+ from ocrd_utils import VERSION
8+ import ocrd_utils
89from ocrd_validators import OcrdConfigValidator
910from ocrd_models .ocrd_config import DEFAULT_CONFIG
1011
11- def load_config_file ():
12+ def load_config_file (basedir = None ):
1213 """
1314 Load the configuration file
1415 """
15- fpath = Path (XDG_CONFIG_HOME , 'ocrd' , 'config.yml' )
16+ if not basedir :
17+ basedir = ocrd_utils .XDG_CONFIG_HOME
18+ fpath = Path (basedir , 'ocrd' , 'config.yml' )
1619 if not fpath .parent .exists ():
17- fpath .parent .mkdir ()
20+ fpath .parent .mkdir (parents = True )
1821 obj = DEFAULT_CONFIG
1922 if not fpath .exists ():
2023 with open (str (fpath ), 'w' , encoding = 'utf-8' ) as f_out :
Original file line number Diff line number Diff line change 22from unittest import mock
33from pathlib import Path
44
5- import ocrd_utils
5+ from ocrd_utils import pushd_popd
6+ from ocrd .config import load_config_file
67
78def test_config_loading ():
8- XDG_CONFIG_HOME_before = ocrd_utils .XDG_CONFIG_HOME
9- with ocrd_utils .pushd_popd (tempdir = True ) as tempdir :
10- ocrd_utils .XDG_CONFIG_HOME = tempdir
9+ with pushd_popd (tempdir = True ) as tempdir :
1110 Path ('ocrd' ).mkdir ()
1211 with open ('ocrd/config.yml' , 'w' , encoding = 'utf-8' ) as f :
1312 f .write ('resource_location: cache\n ' )
14- from ocrd .config import load_config_file
15- obj = load_config_file ()
13+ obj = load_config_file (tempdir )
1614 assert obj .dump () == {'resource_location' : 'cache' }
17- ocrd_utils .XDG_CONFIG_HOME = XDG_CONFIG_HOME_before
1815
1916if __name__ == '__main__' :
2017 main (__file__ )
You can’t perform that action at this time.
0 commit comments