{ } Raw JSON

bundles / astropy latest / astropy / extern / configobj / validate / _test

function

astropy.extern.configobj.validate:_test

source: /astropy/extern/configobj/validate.py :1336

Signature

def   _test ( value * args ** keywargs )

Summary

A function that exists for test purposes.

Extended Summary

>>> checks = [
...     '3, 6, min=1, max=3, test=list(a, b, c)',
...     '3',
...     '3, 6',
...     '3,',
...     'min=1, test="a b c"',
...     'min=5, test="a, b, c"',
...     'min=1, max=3, test="a, b, c"',
...     'min=-100, test=-99',
...     'min=1, max=3',
...     '3, 6, test="36"',
...     '3, 6, test="a, b, c"',
...     '3, max=3, test=list("a", "b", "c")',
...     '''3, max=3, test=list("'a'", 'b', "x=(c)")''',
...     "test='x=fish(3)'",
...    ]
>>> v = Validator({'test': _test})
>>> for entry in checks:
...     pprint(v.check(('test(%s)' % entry), 3))
(3, ('3', '6'), {'max': '3', 'min': '1', 'test': ['a', 'b', 'c']})
(3, ('3',), {})
(3, ('3', '6'), {})
(3, ('3',), {})
(3, (), {'min': '1', 'test': 'a b c'})
(3, (), {'min': '5', 'test': 'a, b, c'})
(3, (), {'max': '3', 'min': '1', 'test': 'a, b, c'})
(3, (), {'min': '-100', 'test': '-99'})
(3, (), {'max': '3', 'min': '1'})
(3, ('3', '6'), {'test': '36'})
(3, ('3', '6'), {'test': 'a, b, c'})
(3, ('3',), {'max': '3', 'test': ['a', 'b', 'c']})
(3, ('3',), {'max': '3', 'test': ["'a'", 'b', 'x=(c)']})
(3, (), {'test': 'x=fish(3)'})
>>> v = Validator()
>>> v.check('integer(default=6)', '3')
3
>>> v.check('integer(default=6)', None, True)
6
>>> v.get_default_value('integer(default=6)')
6
>>> v.get_default_value('float(default=6)')
6.0
>>> v.get_default_value('pass(default=None)')
>>> v.get_default_value("string(default='None')")
'None'
>>> v.get_default_value('pass')
Traceback (most recent call last):
KeyError: 'Check "pass" has no default value.'
>>> v.get_default_value('pass(default=list(1, 2, 3, 4))')
['1', '2', '3', '4']
>>> v = Validator()
>>> v.check("pass(default=None)", None, True)
>>> v.check("pass(default='None')", None, True)
'None'
>>> v.check('pass(default="None")', None, True)
'None'
>>> v.check('pass(default=list(1, 2, 3, 4))', None, True)
['1', '2', '3', '4']

Bug test for unicode arguments >>> v = Validator() >>> v.check(unicode('string(min=4)'), unicode('test')) == unicode('test') True

>>> v = Validator()
>>> v.get_default_value(unicode('string(min=4, default="1234")')) == unicode('1234')
True
>>> v.check(unicode('string(min=4, default="1234")'), unicode('test')) == unicode('test')
True
>>> v = Validator()
>>> default = v.get_default_value('string(default=None)')
>>> default == None
1

Aliases

  • astropy.config.configuration.validate._test