7 from unittest.mock import patch
9 from sima.utils.config import ConfMan, DIRNAME, CONF_FILE
10 # import set_logger to set TRACE_LEVEL_NUM
11 from sima.lib.logger import set_logger
14 class TestConfMan(unittest.TestCase):
16 @patch('sima.utils.config.makedirs')
17 @patch('sima.utils.config.chmod')
18 def test_XDG_var(self, mock_makedirs, mock_chmod):
19 config_home = '/foo/bar'
20 os.environ['XDG_CONFIG_HOME'] = config_home
21 conf_file = os.path.join(config_home, DIRNAME, CONF_FILE)
23 self.assertEqual(conf.conf_file, conf_file)
24 data_home = '/bar/foo'
25 os.environ['XDG_DATA_HOME'] = data_home
26 var_dir = os.path.join(data_home, DIRNAME)
28 self.assertEqual(conf.config['sima']['var_dir'], var_dir)
30 @patch('sima.utils.config.isdir')
31 def test_default_locations(self, mock_isdir):
33 mock_isdir.return_value = True
34 os.environ.pop('XDG_CONFIG_HOME', None)
35 os.environ.pop('XDG_DATA_HOME', None)
36 os.environ['HOME'] = home
38 # Test var dir construction
39 constructed_var_dir = conf.config['sima']['var_dir']
40 expected_var_dir = os.path.join(home, '.local', 'share', DIRNAME)
41 self.assertEqual(constructed_var_dir, expected_var_dir)
42 # Test config construction
43 constructed_config_location = conf.conf_file
44 expected_config = os.path.join(home, '.config', DIRNAME, CONF_FILE)
45 self.assertEqual(constructed_config_location, expected_config)
48 # vim: ai ts=4 sw=4 sts=4 expandtab fileencoding=utf8