Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_filename_relative_to_sibling_needs_siblings(self):
config = _root({'foo': 'bar'})
with self.assertRaises(confuse.ConfigTemplateError):
config['foo'].get(confuse.Filename(relative_to='bar'))
def test_filename_with_file_source(self):
source = confuse.ConfigSource({'foo': 'foo/bar'},
filename='/baz/config.yaml')
config = _root(source)
config.config_dir = lambda: '/config/path'
valid = config['foo'].get(confuse.Filename())
self.assertEqual(valid, os.path.realpath('/config/path/foo/bar'))
def test_default_none(self):
config = _root({})
valid = config['foo'].get(confuse.Filename(None))
self.assertEqual(valid, None)
def test_missing_required_value(self):
config = _root({})
with self.assertRaises(confuse.NotFoundError):
config['foo'].get(confuse.Filename())
def test_filename_relative_to_sibling(self):
config = _root({'foo': '/', 'bar': 'baz'})
valid = config.get({
'foo': confuse.Filename(),
'bar': confuse.Filename(relative_to='foo')
})
self.assertEqual(valid.foo, os.path.realpath('/'))
self.assertEqual(valid.bar, os.path.realpath('/baz'))
def test_filename_relative_to_sibling(self):
config = _root({'foo': '/', 'bar': 'baz'})
valid = config.get({
'foo': confuse.Filename(),
'bar': confuse.Filename(relative_to='foo')
})
self.assertEqual(valid.foo, os.path.realpath('/'))
self.assertEqual(valid.bar, os.path.realpath('/baz'))
def test_filename_relative_to_sibling_with_recursion(self):
config = _root({'foo': '/', 'bar': 'r', 'baz': 'z'})
with self.assertRaises(confuse.ConfigTemplateError):
config.get({
'foo': confuse.Filename(relative_to='bar'),
'bar': confuse.Filename(relative_to='baz'),
'baz': confuse.Filename(relative_to='foo')
})
def _tokenfile(self):
"""Get the path to the JSON file for storing the OAuth token.
"""
return self.config['tokenfile'].get(confuse.Filename(in_app_dir=True))
def _tokenfile(self):
"""Get the path to the JSON file for storing the OAuth token.
"""
return self.config['tokenfile'].get(confuse.Filename(in_app_dir=True))
"""An example application using Confuse for configuration."""
from __future__ import division, absolute_import, print_function
import confuse
import argparse
template = {
'library': confuse.Filename(),
'import_write': confuse.OneOf([bool, 'ask', 'skip']),
'ignore': confuse.StrSeq(),
'plugins': list,
'paths': {
'directory': confuse.Filename(),
'default': confuse.Filename(relative_to='directory'),
}
}
config = confuse.LazyConfig('ConfuseExample', __name__)
def main():
parser = argparse.ArgumentParser(description='example Confuse program')
parser.add_argument('--library', '-l', dest='library', metavar='LIBPATH',
help='library database file')
parser.add_argument('--directory', '-d', dest='paths.directory',
metavar='DIRECTORY',
help='destination music directory')
parser.add_argument('--verbose', '-v', dest='verbose', action='store_true',
help='print debugging messages')