Permalink
Browse files

Enhanced validation of TimeoutValidation and added test cases for it.

  • Loading branch information...
mikahanninen committed Aug 27, 2012
1 parent 0dcbc4e commit d2ff70e9e2d17c44854c98c88b624b2e27ce951b
Showing with 40 additions and 2 deletions.
  1. +7 −2 src/robotide/validators/__init__.py
  2. +33 −0 utest/validators/test_timeout_validation.py
@@ -59,13 +59,18 @@ def _validate(self, value):
timestr = time_tokens[0]
try:
secs = utils.timestr_to_secs(timestr)
+ if secs <= 0:
+ raise ValueError("Timestring must be over zero")
time_tokens[0] = utils.secs_to_timestr(secs)
- except DataError, err:
+ except ValueError, err:
if not '${' in timestr:
return str(err)
- self.Window.SetValue(utils.join_value(time_tokens))
+ self._set_window_value(utils.join_value(time_tokens))
return None
+ def _set_window_value(self, value):
+ self.Window.SetValue(value)
+
class ArgumentsValidator(_AbstractValidator):
@@ -0,0 +1,33 @@
+import unittest
+from robotide.validators import TimeoutValidator
+
+class TimeoutValidationTest(unittest.TestCase):
+
+ def setUp(self):
+ self.validator = TimeoutValidator()
+ self.validator._set_window_value = self._catch_value
+ self._value = ""
+
+ def _catch_value(self, value):
+ self._value = value
+
+ def test_timeout_validation_passes(self):
+ result = self.validator._validate("2h 30min 45sec")
+ self.assertEqual( result, None, "Empty string should have been returned from validate: %s" % result)
@mikahanninen

mikahanninen Aug 27, 2012

Owner

Not entirely true error message.... "None should have been returned from validate". Fix later.

+
+ def test_timeout_validation_negative_cases(self):
+ self._run_validation("-1000","-1","0")
+
+ def test_timeout_validation_illegal_format(self):
+ self._run_validation("1 minuuttia", "2 tuntia ja muuta","dshfkjhsdkjfhjk")
+
+ def _run_validation(self, *test_values):
+ errors = []
+ for val in test_values:
+ result = self.validator._validate(val)
+ if result == None:
+ errors.append("\n%s should have failed, but didn't, got '%s'" % (val, result))
+ self.assertEqual(len(errors), 0, ''.join(errors))
+
+if __name__ == '__main__':
+ unittest.main()

0 comments on commit d2ff70e

Please sign in to comment.