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 test_missing_required_value_raises_error_on_validate(self):
config = _root({})
with self.assertRaises(confuse.NotFoundError):
config.get({'foo': confuse.Integer()})
def test_validate_first_good_choice_in_list(self):
config = _root({'foo': 3.14})
valid = config['foo'].get(confuse.OneOf([
confuse.Integer(),
confuse.Number(),
]))
self.assertEqual(valid, 3)
def test_validate_no_choice_in_list(self):
config = _root({'foo': None})
with self.assertRaises(confuse.ConfigValueError):
config['foo'].get(confuse.OneOf([
confuse.String(),
confuse.Integer(),
]))