本文整理汇总了Python中util.assert_invalid函数的典型用法代码示例。如果您正苦于以下问题:Python assert_invalid函数的具体用法?Python assert_invalid怎么用?Python assert_invalid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_invalid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_equal
def test_equal():
v = V.equal('egg', msg="not equal")
assert v.__name__ == "equal"
assert v('egg') == 'egg'
assert_invalid(
lambda: v('bob'),
{None: 'not equal'})
示例2: test_parse_time
def test_parse_time():
fmt='%m %d %Y'
msg="potted shrimp"
v=V.parse_time(fmt, msg)
ts=v('10 03 2007')[:3]
assert ts==(2007, 10, 3)
assert_invalid(lambda: v('tough nuggie'), msg)
示例3: test_confirm_type
def test_confirm_type():
v = V.confirm_type((int, float), 'not a number')
assert v.__name__ == "confirm_type"
assert v(45) == 45
assert_invalid(
lambda: v('45'),
{None: 'not a number'})
示例4: test_ip
def test_ip():
v = V.ip('donkey')
i = '192.168.1.243'
assert v(i) == i
assert_invalid(
lambda: v("this is not an ip"),
{None: 'donkey'})
示例5: test_translate
def test_translate():
v = V.translate(dict(y=True, f=False), 'dong')
assert v.__name__ == "translate"
assert v('y') == True
assert_invalid(
lambda: v('pod'),
{None: 'dong'})
示例6: test_regex
def test_regex():
v = V.regex('shrubbery\d{3}$', 'regex')
assert v.__name__ == "regex"
assert v('shrubbery222') == 'shrubbery222'
assert_invalid(
lambda: v('buy a shrubbery333, ok?'),
{None: 'regex'})
示例7: test_not_equal
def test_not_equal():
v = V.not_equal('egg', msg='equal')
assert v.__name__ == "not_equal"
assert v('plop') == 'plop'
assert_invalid(
lambda: v('egg'),
{None: 'equal'})
示例8: test_is_list
def test_is_list():
msg = "list"
v = V.is_list(msg=msg)
assert v.__name__ == "is_list"
assert v([40]) == [40]
assert_invalid(
lambda: v(40),
{None: msg})
示例9: test_is_scalar
def test_is_scalar():
msg = 'sc'
v = V.is_scalar(msg=msg)
assert v.__name__ == "is_scalar"
assert v(40) == 40
assert_invalid(
lambda: v([40]),
{None: msg})
示例10: test_email
def test_email():
v=V.email()
e="[email protected]"
assert v(e)==e
e='[email protected]'
v=V.email(True, 'snog')
assert v(e)==e
assert_invalid(lambda: v('[email protected]'), 'snog')
示例11: test_credit_card_1
def test_credit_card_1():
cc='4000000000998'
v=V.credit_card(msg="aha")
assert v(cc)==cc
assert_invalid(lambda: v('pain chocolat'), dict(cc_number=['aha']))
assert_invalid(lambda: v(str(int(cc)-1)), dict(cc_number=['aha']))
v=V.credit_card(require_type=True, msg='aha')
assert v((cc, 'Visa'))==(cc, 'Visa')
示例12: test_clamp_length
def test_clamp_length():
msg='You are a pear'
v=V.clamp_length(min=3, msg=msg)
assert v('500')=='500'
assert_invalid(lambda: v('eh'), msg)
v=V.clamp_length(max=10, msg=dict(minlen='haha', maxlen='kong'))
assert v('40')=='40'
assert_invalid(lambda: v('I told you that Ronald would eat it when you were in the bathroom'), 'kong')
示例13: test_msg
def test_msg():
messages=dict(
integer="hey, I said use a number")
with msg(messages):
assert messages == getMessages()
assert_invalid(lambda: V.integer()('lump'), messages['integer'])
assert getMessages() != messages
assert_invalid(lambda: V.integer()('lump'), "not an integer")
示例14: test_not_belongs
def test_not_belongs():
msg = "belittle my humbug"
v = V.not_belongs(range(5), msg=msg)
assert v.__name__ == "not_belongs"
assert v('pinko') == 'pinko'
assert_invalid(
lambda: v(4),
{None: msg})
示例15: test_to_integer
def test_to_integer():
msg = "please enter an integer"
v = V.to_integer(msg=msg)
assert v.__name__ == "to_integer"
assert v('40') == 40
assert_invalid(
lambda: v('whack him until he screams'),
{None: msg})