| OLD | NEW |
| 1 # Copyright (c) 2010 Google Inc. All rights reserved. | 1 # Copyright (c) 2010 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 def _raise_exception(self): | 42 def _raise_exception(self): |
| 43 raise self.exception | 43 raise self.exception |
| 44 | 44 |
| 45 def test_exception(self): | 45 def test_exception(self): |
| 46 transaction = NetworkTransaction() | 46 transaction = NetworkTransaction() |
| 47 did_process_exception = False | 47 did_process_exception = False |
| 48 did_throw_exception = True | 48 did_throw_exception = True |
| 49 try: | 49 try: |
| 50 transaction.run(lambda: self._raise_exception()) | 50 transaction.run(lambda: self._raise_exception()) |
| 51 did_throw_exception = False | 51 did_throw_exception = False |
| 52 except Exception, e: | 52 except Exception as e: |
| 53 did_process_exception = True | 53 did_process_exception = True |
| 54 self.assertEqual(e, self.exception) | 54 self.assertEqual(e, self.exception) |
| 55 self.assertTrue(did_throw_exception) | 55 self.assertTrue(did_throw_exception) |
| 56 self.assertTrue(did_process_exception) | 56 self.assertTrue(did_process_exception) |
| 57 | 57 |
| 58 def _raise_500_error(self): | 58 def _raise_500_error(self): |
| 59 self._run_count += 1 | 59 self._run_count += 1 |
| 60 if self._run_count < 3: | 60 if self._run_count < 3: |
| 61 raise HTTPError("http://example.com/", 500, "internal server error",
None, None) | 61 raise HTTPError("http://example.com/", 500, "internal server error",
None, None) |
| 62 return 42 | 62 return 42 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 79 self.assertIsNone(transaction.run(lambda: self._raise_404_error())) | 79 self.assertIsNone(transaction.run(lambda: self._raise_404_error())) |
| 80 | 80 |
| 81 def test_timeout(self): | 81 def test_timeout(self): |
| 82 self._run_count = 0 | 82 self._run_count = 0 |
| 83 transaction = NetworkTransaction(initial_backoff_seconds=60 * 60, timeou
t_seconds=60) | 83 transaction = NetworkTransaction(initial_backoff_seconds=60 * 60, timeou
t_seconds=60) |
| 84 did_process_exception = False | 84 did_process_exception = False |
| 85 did_throw_exception = True | 85 did_throw_exception = True |
| 86 try: | 86 try: |
| 87 transaction.run(lambda: self._raise_500_error()) | 87 transaction.run(lambda: self._raise_500_error()) |
| 88 did_throw_exception = False | 88 did_throw_exception = False |
| 89 except NetworkTimeout, e: | 89 except NetworkTimeout as e: |
| 90 did_process_exception = True | 90 did_process_exception = True |
| 91 self.assertTrue(did_throw_exception) | 91 self.assertTrue(did_throw_exception) |
| 92 self.assertTrue(did_process_exception) | 92 self.assertTrue(did_process_exception) |
| OLD | NEW |