Exemplo n.º 1
0
 def test_filename_relative_to_sibling_with_recursion(self):
     config = _root({'foo': '/', 'bar': 'r', 'baz': 'z'})
     with self.assertRaises(confit.ConfigTemplateError):
         config.get({
             'foo': confit.Filename(relative_to='bar'),
             'bar': confit.Filename(relative_to='baz'),
             'baz': confit.Filename(relative_to='foo')
         })
Exemplo n.º 2
0
 def test_filename_relative_to_sibling(self):
     config = _root({'foo': '/', 'bar': 'baz'})
     valid = config.get({
         'foo': confit.Filename(),
         'bar': confit.Filename(relative_to='foo')
     })
     self.assertEqual(valid.foo, os.path.realpath('/'))
     self.assertEqual(valid.bar, os.path.realpath('/baz'))
Exemplo n.º 3
0
 def test_filename_with_file_source(self):
     source = confit.ConfigSource({'foo': 'foo/bar'},
                                  filename='/baz/config.yaml')
     config = _root(source)
     config.config_dir = lambda: '/config/path'
     valid = config['foo'].get(confit.Filename())
     self.assertEqual(valid, os.path.realpath('/config/path/foo/bar'))
Exemplo n.º 4
0
 def test_filename_wrong_type(self):
     config = _root({'foo': 8})
     with self.assertRaises(confit.ConfigTypeError):
         config['foo'].get(confit.Filename())
Exemplo n.º 5
0
 def test_filename_with_non_file_source(self):
     config = _root({'foo': 'foo/bar'})
     valid = config['foo'].get(confit.Filename())
     self.assertEqual(valid, os.path.join(os.getcwd(), 'foo', 'bar'))
Exemplo n.º 6
0
 def test_filename_relative_to_sibling_needs_template(self):
     config = _root({'foo': '/', 'bar': 'baz'})
     with self.assertRaises(confit.ConfigTemplateError):
         config.get({'bar': confit.Filename(relative_to='foo')})
Exemplo n.º 7
0
 def test_filename_relative_to_sibling_needs_siblings(self):
     config = _root({'foo': 'bar'})
     with self.assertRaises(confit.ConfigTemplateError):
         config['foo'].get(confit.Filename(relative_to='bar'))
Exemplo n.º 8
0
 def test_filename_relative_to_self(self):
     config = _root({'foo': 'bar'})
     with self.assertRaises(confit.ConfigTemplateError):
         config.get({'foo': confit.Filename(relative_to='foo')})
Exemplo n.º 9
0
 def test_filename_working_dir_overrides_sibling(self):
     config = _root({'foo': 'bar'})
     valid = config.get(
         {'foo': confit.Filename(cwd='/dev/null', relative_to='baz')})
     self.assertEqual(valid.foo, os.path.realpath('/dev/null/bar'))
Exemplo n.º 10
0
 def test_filename_relative_to_working_dir(self):
     config = _root({'foo': 'bar'})
     valid = config['foo'].get(confit.Filename(cwd='/dev/null'))
     self.assertEqual(valid, os.path.realpath('/dev/null/bar'))
Exemplo n.º 11
0
"""An example application using Confit for configuration."""
from __future__ import print_function
from __future__ import unicode_literals
import os
import confit
import argparse

template = {
    'library': confit.Filename(),
    'import_write': confit.OneOf([bool, 'true', 'false']),
    'ignore': confit.StrSeq(),
    'plugins': list,
    'paths': {
        'directory': confit.Filename(),
        'default': confit.Filename(relative_to='directory'),
    }
}

config = confit.LazyConfig(
    'ConfitExample',
    file="~/PycharmProjects/confit/example/config_default.yaml")


def main():
    parser = argparse.ArgumentParser(description='example Confit program')
    parser.add_argument('--library',
                        '-l',
                        dest='library',
                        metavar='LIBPATH',
                        help='library database file')
    parser.add_argument('--directory',