Unittests for su module.
[rox-lib.git] / tests / python / testbasedir.py
blobf0ac9b999c112de158d9990e1e127d1a2dc2e65b
1 #!/usr/bin/env python
2 import unittest
3 import os, sys
4 sys.path.append('../../python')
6 from rox import basedir
8 class TestBasedir(unittest.TestCase):
9 def setUp(self):
10 os.environ['XDG_DATA_HOME'] = '/tmp/share'
11 os.environ['XDG_DATA_DIRS'] = '/tmp/share.2:/tmp/share.3'
12 os.environ['XDG_CONFIG_HOME'] = '/tmp/config'
13 os.environ['XDG_CONFIG_DIRS'] = '/tmp/config.2:/tmp/config.3'
14 reload(basedir)
16 def testDefaults(self):
17 for x in ['XDG_DATA_HOME', 'XDG_DATA_DIRS',
18 'XDG_CONFIG_HOME', 'XDG_CONFIG_DIRS']:
19 if x in os.environ:
20 del os.environ[x]
21 reload(basedir)
22 self.assertEquals(os.path.expanduser('~/.config'),
23 basedir.xdg_config_home)
24 self.assertEquals([basedir.xdg_config_home, '/etc/xdg'],
25 basedir.xdg_config_dirs)
27 self.assertEquals(os.path.expanduser('~/.local/share'),
28 basedir.xdg_data_home)
29 self.assertEquals([basedir.xdg_data_home,
30 '/usr/local/share', '/usr/share'],
31 basedir.xdg_data_dirs)
33 def testOverride(self):
34 self.assertEquals('/tmp/config', basedir.xdg_config_home)
35 self.assertEquals([basedir.xdg_config_home,
36 '/tmp/config.2', '/tmp/config.3'],
37 basedir.xdg_config_dirs)
39 self.assertEquals('/tmp/share', basedir.xdg_data_home)
40 self.assertEquals([basedir.xdg_data_home,
41 '/tmp/share.2', '/tmp/share.3'],
42 basedir.xdg_data_dirs)
44 def testMkDir(self):
45 assert not os.path.isdir(basedir.xdg_config_home)
46 path = basedir.save_config_path('ROX-Lib-Test')
47 self.assertEquals('/tmp/config/ROX-Lib-Test', path)
48 assert os.path.isdir(basedir.xdg_config_home)
49 assert os.path.isdir(path)
51 os.rmdir(path)
52 os.rmdir(basedir.xdg_config_home)
55 sys.argv.append('-v')
56 unittest.main()