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_string_default_value(self):
config = _root({})
valid = config.get({'foo': confuse.String('baz')})
self.assertEqual(valid['foo'], 'baz')
def test_pattern_matching(self):
config = _root({'foo': 'bar', 'baz': 'zab'})
valid = config.get({'foo': confuse.String(pattern='^ba.$')})
self.assertEqual(valid['foo'], 'bar')
with self.assertRaises(confuse.ConfigValueError):
config.get({'baz': confuse.String(pattern='!')})
def test_check_string_type(self):
config = _root({'foo': 5})
with self.assertRaises(confuse.ConfigTypeError):
config.get({'foo': confuse.String()})
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_concrete_string_as_template(self):
typ = confuse.as_template('foo')
self.assertIsInstance(typ, confuse.String)
self.assertEqual(typ.default, 'foo')
def test_validate_string(self):
config = _root({'foo': 'bar'})
valid = config.get({'foo': confuse.String()})
self.assertEqual(valid['foo'], 'bar')
import logging
import os.path
import confuse
import pkg_resources
import yaml
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': {},
'google_key': None,
'google_engine': u'001442825323518660753:hrh5ch1gjzm',
'fanarttv_key': None,
'store_source': False,
'high_resolution': False,
})
self.config['google_key'].redact = True
self.config['fanarttv_key'].redact = True
self.minwidth = self.config['minwidth'].get(int)
self.maxwidth = self.config['maxwidth'].get(int)
# allow both pixel and percentage-based margin specifications
self.enforce_ratio = self.config['enforce_ratio'].get(
confuse.OneOf([bool,
confuse.String(pattern=self.PAT_PX),
confuse.String(pattern=self.PAT_PERCENT)]))
self.margin_px = None
self.margin_percent = None
if type(self.enforce_ratio) is six.text_type:
if self.enforce_ratio[-1] == u'%':
self.margin_percent = float(self.enforce_ratio[:-1]) / 100
elif self.enforce_ratio[-2:] == u'px':
self.margin_px = int(self.enforce_ratio[:-2])
else:
# shouldn't happen
raise confuse.ConfigValueError()
self.enforce_ratio = True
cover_names = self.config['cover_names'].as_str_seq()
self.cover_names = list(map(util.bytestring_path, cover_names))
self.cautious = self.config['cautious'].get(bool)
def get_config_template():
template = {
'enabled': confuse.TypeTemplate(bool),
'host': confuse.String(),
'port': confuse.Integer(),
'tls': confuse.TypeTemplate(bool),
'username': confuse.String(),
'password': confuse.String(),
'recipient': confuse.String()
}
return template