From 5c292640ba07b789fbeedfd99565ab4a97111c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Mon, 28 Mar 2016 14:47:58 +0100 Subject: [PATCH] Complete coverage for IS_IN_SET Removed unreachable code in IS_IN_SET if failures and self.theset: if self.multiple and (value is None or value == '') It's impossible to have *failures* and have value be None or '' at the same time --- gluon/tests/test_validators.py | 4 ++++ gluon/validators.py | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gluon/tests/test_validators.py b/gluon/tests/test_validators.py index cc925065..76c8c6c0 100644 --- a/gluon/tests/test_validators.py +++ b/gluon/tests/test_validators.py @@ -184,6 +184,10 @@ class TestValidators(unittest.TestCase): self.assertEqual(rtn, ('id1', None)) rtn = IS_IN_SET(['id1', 'id2'], error_message='oops', multiple=True)(None) self.assertEqual(rtn, ([], None)) + rtn = IS_IN_SET(['id1', 'id2'], error_message='oops', multiple=True)('') + self.assertEqual(rtn, ([], None)) + rtn = IS_IN_SET(['id1', 'id2'], error_message='oops', multiple=True)('id1') + self.assertEqual(rtn, (['id1'], None)) rtn = IS_IN_SET(['id1', 'id2'], error_message='oops', multiple=(1,2))(None) self.assertEqual(rtn, ([], 'oops')) import itertools diff --git a/gluon/validators.py b/gluon/validators.py index 84367d08..050c3a9c 100644 --- a/gluon/validators.py +++ b/gluon/validators.py @@ -471,8 +471,6 @@ class IS_IN_SET(Validator): thestrset = [str(x) for x in self.theset] failures = [x for x in values if not str(x) in thestrset] if failures and self.theset: - if self.multiple and (value is None or value == ''): - return ([], None) return (value, translate(self.error_message)) if self.multiple: if isinstance(self.multiple, (tuple, list)) and \