summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2012-08-11 12:21:51 +0100
committerMark McLoughlin <markmc@redhat.com>2012-08-11 12:24:03 +0100
commit0a36c92e84be0f432b8ce792834dc297196e09af (patch)
treef683810c4694ac483f473a367f3ed09163a05111 /tests
parent887e9e169cd81dec7d7c01ce508e15d4e4fdd99e (diff)
downloadoslo-0a36c92e84be0f432b8ce792834dc297196e09af.tar.gz
oslo-0a36c92e84be0f432b8ce792834dc297196e09af.tar.xz
oslo-0a36c92e84be0f432b8ce792834dc297196e09af.zip
Tilde expansion for --config-file and --config-dir
Fixes bug #1012671 Allow a filename starting with ~ or ~user to be passed for --config-file or --config-dir. Change-Id: I67705401ed1c35c0cc2161095e36616552740aba
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_cfg.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/unit/test_cfg.py b/tests/unit/test_cfg.py
index 14a85c9..0d11863 100644
--- a/tests/unit/test_cfg.py
+++ b/tests/unit/test_cfg.py
@@ -1480,3 +1480,43 @@ class ConfigParserTestCase(unittest.TestCase):
parser = ConfigParser(tmpfile.name, {})
self.assertRaises(ParseError, parser.parse)
+
+
+class TildeExpansionTestCase(BaseTestCase):
+
+ def test_config_file_tilde(self):
+ homedir = os.path.expanduser('~')
+ tmpfile = tempfile.mktemp(dir=homedir, prefix='cfg-', suffix='.conf')
+ tmpbase = os.path.basename(tmpfile)
+
+ try:
+ self.conf(['--config-file', os.path.join('~', tmpbase)])
+ except ConfigFilesNotFoundError, cfnfe:
+ print cfnfe
+ self.assertTrue(homedir in str(cfnfe))
+
+ self.stubs.Set(os.path, 'exists', lambda p: p == tmpfile)
+
+ self.assertEquals(self.conf.find_file(tmpbase), tmpfile)
+
+ def test_config_dir_tilde(self):
+ homedir = os.path.expanduser('~')
+ tmpdir = tempfile.mktemp(dir=homedir,
+ prefix='cfg-',
+ suffix='.d')
+ tmpfile = os.path.join(tmpdir, 'foo.conf')
+ tmpbase = os.path.basename(tmpfile)
+
+ self.stubs.Set(glob, 'glob', lambda p: [tmpfile])
+
+ try:
+ print ['--config-dir', os.path.join('~', os.path.basename(tmpdir))]
+ self.conf(['--config-dir',
+ os.path.join('~', os.path.basename(tmpdir))])
+ except ConfigFilesNotFoundError, cfnfe:
+ print cfnfe
+ self.assertTrue(os.path.expanduser('~') in str(cfnfe))
+
+ self.stubs.Set(os.path, 'exists', lambda p: p == tmpfile)
+
+ self.assertEquals(self.conf.find_file(tmpbase), tmpfile)