]> kaliko git repositories - mpd-sima.git/blob - tests/test_config.py
Fixed indentation
[mpd-sima.git] / tests / test_config.py
1 #!/usr/bin/env python3
2 # coding: utf-8
3
4 import unittest
5 import os
6
7 from unittest.mock import patch
8
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
12
13
14 class TestConfMan(unittest.TestCase):
15
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)
22         conf = ConfMan({})
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)
27         conf = ConfMan({})
28         self.assertEqual(conf.config['sima']['var_dir'], var_dir)
29
30     @patch('sima.utils.config.isdir')
31     def test_default_locations(self, mock_isdir):
32         home = '/foo'
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
37         conf = ConfMan({})
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)
46
47 # VIM MODLINE
48 # vim: ai ts=4 sw=4 sts=4 expandtab fileencoding=utf8