Max Rasskazov | c018e38 | 2015-06-03 15:22:04 +0300 | [diff] [blame] | 1 | #-*- coding: utf-8 -*- |
| 2 | |
| 3 | import unittest |
| 4 | |
| 5 | import utils |
| 6 | |
| 7 | |
| 8 | logger = utils.logger.getChild('TestUtils') |
| 9 | |
| 10 | |
| 11 | class TestUtils(unittest.TestCase): |
| 12 | |
| 13 | def setUp(self): |
| 14 | self.gen10 = self.get_generator(10) |
| 15 | |
| 16 | def get_generator(self, max): |
| 17 | for i in xrange(max): |
| 18 | yield i |
| 19 | |
| 20 | def test_retry_3_from_5(self): |
| 21 | res = utils.Retry(timeout=1, |
| 22 | attempts=5).wait_result(self.gen10.next, 3) |
| 23 | self.assertEqual(res, 3) |
| 24 | |
| 25 | def test_retry_failed(self): |
| 26 | retryer = utils.Retry(timeout=1, attempts=3) |
| 27 | self.assertRaises(utils.ResultNotProduced, |
| 28 | retryer.wait_result, self.gen10.next, 5) |
| 29 | |
| 30 | if __name__ == '__main__': |
| 31 | unittest.main() |