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_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(),
]))
def test_validate_good_choice_in_list(self):
config = _root({'foo': 2})
valid = config['foo'].get(confuse.OneOf([
confuse.String(),
confuse.Integer(),
]))
self.assertEqual(valid, 2)
def test_none_as_default(self):
config = _root({})
valid = config.get({'foo': confuse.Integer(None)})
self.assertIsNone(valid['foo'])
def test_undeclared_key_ignored_from_input(self):
config = _root({'foo': 5, 'bar': 6})
valid = config.get({'foo': confuse.Integer()})
with self.assertRaises(KeyError):
valid['bar']
def test_nested_dict_template(self):
config = _root({
'foo': {'bar': 9},
})
valid = config.get({
'foo': {'bar': confuse.Integer()},
})
self.assertEqual(valid['foo']['bar'], 9)
def get_config_template():
template = {
'enabled': confuse.TypeTemplate(bool),
'keywords': confuse.StrSeq(),
'max_following': confuse.Integer(),
'multiple': confuse.TypeTemplate(bool)
}
return template
def get_config_template():
template = {
'enabled': confuse.TypeTemplate(bool),
'number': confuse.Integer()
}
return template
logger = logging.getLogger(__name__)
class Config:
base_template = {
'twitter': {
'consumer_key': confuse.String(),
'consumer_secret': confuse.String(),
'access_token_key': confuse.String(),
'access_token_secret': confuse.String(),
'min_ratelimit_percent': confuse.Integer(),
'search': {
'queries': confuse.TypeTemplate(list),
'max_queue': confuse.Integer(),
'max_quote_depth': confuse.Integer(),
'min_quote_similarity': confuse.Number(),
'skip_retweeted': confuse.TypeTemplate(bool),
# Is updated on runtime
'filter': {},
# Is updated on runtime
'sort': {},
},
# Is updated on runtime
'actions': {},
'scheduler': {
'search_interval': confuse.Integer(),
'retweet_interval': confuse.Integer(),
'retweet_random_margin': confuse.Integer(),
'blocked_users_update_interval': confuse.Integer(),
'clear_queue_interval': confuse.Integer(),
'rate_limit_update_interval': confuse.Integer(),