Import upstream version 0.12.1+git20210220.1.1720439, md5 1ed390485c486d1c9b11850f0174f933
Debian Janitor
3 years ago
515 | 515 |
)
|
516 | 516 |
assert_equal(repr(coerce_), "Coerce(int, msg='moo')")
|
517 | 517 |
assert_equal(repr(all_), "All('10', Coerce(int, msg=None), msg='all msg')")
|
518 | |
assert_equal(repr(maybe_int), "Any(%s, None, msg=None)" % str(int))
|
|
518 |
assert_equal(repr(maybe_int), "Any(None, %s, msg=None)" % str(int))
|
519 | 519 |
|
520 | 520 |
|
521 | 521 |
def test_list_validation_messages():
|
|
746 | 746 |
assert s([])
|
747 | 747 |
|
748 | 748 |
|
749 | |
def test_maybe_returns_subvalidator_error():
|
|
749 |
def test_maybe_returns_default_error():
|
750 | 750 |
schema = Schema(Maybe(Range(1, 2)))
|
751 | 751 |
|
752 | 752 |
# The following should be valid
|
|
758 | 758 |
# Should trigger a MultipleInvalid exception
|
759 | 759 |
schema(3)
|
760 | 760 |
except MultipleInvalid as e:
|
761 | |
assert_equal(str(e), "value must be at most 2")
|
|
761 |
assert_equal(str(e), "not a valid value")
|
762 | 762 |
else:
|
763 | 763 |
assert False, "Did not raise correct Invalid"
|
764 | 764 |
|
351 | 351 |
>>> validate = Schema(Match(r'^0x[A-F0-9]+$'))
|
352 | 352 |
>>> validate('0x123EF4')
|
353 | 353 |
'0x123EF4'
|
354 | |
>>> with raises(MultipleInvalid, "does not match regular expression"):
|
|
354 |
>>> with raises(MultipleInvalid, 'does not match regular expression ^0x[A-F0-9]+$'):
|
355 | 355 |
... validate('123EF4')
|
356 | 356 |
|
357 | 357 |
>>> with raises(MultipleInvalid, 'expected string or buffer'):
|
|
376 | 376 |
except TypeError:
|
377 | 377 |
raise MatchInvalid("expected string or buffer")
|
378 | 378 |
if not match:
|
379 | |
raise MatchInvalid(self.msg or 'does not match regular expression')
|
|
379 |
raise MatchInvalid(self.msg or 'does not match regular expression {}'.format(self.pattern.pattern))
|
380 | 380 |
return v
|
381 | 381 |
|
382 | 382 |
def __repr__(self):
|
|
554 | 554 |
... s("string")
|
555 | 555 |
|
556 | 556 |
"""
|
557 | |
return Any(validator, None, msg=msg)
|
|
557 |
return Any(None, validator, msg=msg)
|
558 | 558 |
|
559 | 559 |
|
560 | 560 |
class Range(object):
|