Skip to content

Commit

Permalink
New verify many support
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Dec 28, 2018
1 parent 859e6c7 commit 8d57e87
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/quorum/__init__.py
Expand Up @@ -116,8 +116,8 @@
leafs, load_form, load_locale, get_locale, get_langs, set_locale, reset_locale, anotate_async,\
anotate_secure, run_thread, camel_to_underscore, camel_to_readable, underscore_to_readable,\
generate_identifier, to_locale, nl_to_br, nl_to_br_jinja, sp_to_nbsp, sp_to_nbsp_jinja, unset, date_time,\
quote, unquote, is_content_type, parse_content_type, verify, verify_equal, verify_not_equal, execute,\
deprecated, JSONEncoder
quote, unquote, is_content_type, parse_content_type, verify, verify_equal, verify_not_equal, verify_many,\
execute, deprecated, JSONEncoder
from .validation import validate, validate_b, validate_e, safe, eq, gt, gte, lt, lte, not_null,\
not_empty, not_false, is_in, is_upper, is_lower, is_simple, is_email, is_url, is_regex, field_eq,\
field_gt, field_gte, field_lt, field_lte, string_gt, string_lt, string_eq, equals, not_past,\
Expand Down
19 changes: 19 additions & 0 deletions src/quorum/test/util.py
Expand Up @@ -519,3 +519,22 @@ def test_verify_not_equal(self):
quorum.OperationalError,
lambda: quorum.verify_not_equal(1, 1, exception = quorum.OperationalError)
)

def test_verify_many(self):
result = quorum.verify_many((1 == 1, 2 == 2, 3 == 3))
self.assertEqual(result, None)

result = quorum.verify_many(("hello" == "hello",))
self.assertEqual(result, None)

self.assertRaises(quorum.AssertionError, lambda: quorum.verify_many((1 == 2,)))

self.assertRaises(quorum.AssertionError, lambda: quorum.verify_many((1 == 1, 1 == 2)))

self.assertRaises(
quorum.OperationalError,
lambda: quorum.verify_many(
(1 == 1, 1 == 2),
exception = quorum.OperationalError
)
)
10 changes: 10 additions & 0 deletions src/quorum/util.py
Expand Up @@ -1256,6 +1256,16 @@ def verify_not_equal(first, second, message = None, code = None, exception = Non
**kwargs
)

def verify_many(sequence, message = None, code = None, exception = None, **kwargs):
for condition in sequence:
verify(
condition,
message = message,
code = code,
exception = exception,
**kwargs
)

def execute(args, command = None, path = None, shell = True, encoding = None):
if not encoding: encoding = sys.getfilesystemencoding()
if command: args = command.split(" ")
Expand Down

0 comments on commit 8d57e87

Please sign in to comment.