Exemple #1
0
    def test_handle_not_all(self):
        memory_error = MemoryError()
        agg_ex = AggregateException([ZeroDivisionError(), None, memory_error])

        def my_handler(ex, a, b=None):
            return type(ex) == ZeroDivisionError

        with self.assertRaises(AggregateException) as new_agg_ex:
            agg_ex.handle(my_handler, 1, b=True)
        self.assertIsInstance(new_agg_ex.exception, AggregateException)
        self.assertEqual([memory_error], new_agg_ex.exception.exceptions)
    def test_handle_not_all(self):
        memory_error = MemoryError()
        agg_ex = AggregateException([ZeroDivisionError(), None, memory_error])

        def my_handler(ex, a, b=None):
            return type(ex) == ZeroDivisionError

        with self.assertRaises(AggregateException) as new_agg_ex:
            agg_ex.handle(my_handler, 1, b=True)
        self.assertIsInstance(new_agg_ex.exception, AggregateException)
        self.assertEqual([memory_error], new_agg_ex.exception.exceptions)
Exemple #3
0
 def sync_result(self):
     self._result = []
     exceptions = []
     for future in self.futures:
         if future.finished:
             self._result.append(future.result)
             if self.bubbles_exception_on_failure is not False:
                 exception = future.exception
                 exceptions.append(exception)
         else:
             self._result.append(None)
             exceptions.append(None)
     if any(ex for ex in exceptions):
         self._exception = AggregateException(exceptions)
 def test_flatten(self):
     agg_ex = AggregateException(
         [
             ZeroDivisionError(), None, MemoryError(),
             AggregateException(
                 [
                     AttributeError(),
                     AggregateException(
                         [
                             ImportError(),
                         ]
                     ),
                     None,
                 ]
             ),
             AggregateException([]),
         ]
     )
     flatten_ex = agg_ex.flatten()
     self.assertEqual(
         [ZeroDivisionError, MemoryError, AttributeError, ImportError],
         [type(ex) for ex in flatten_ex.exceptions]
     )
Exemple #5
0
 def test_flatten(self):
     agg_ex = AggregateException([
         ZeroDivisionError(),
         None,
         MemoryError(),
         AggregateException([
             AttributeError(),
             AggregateException([
                 ImportError(),
             ]),
             None,
         ]),
         AggregateException([]),
     ])
     flatten_ex = agg_ex.flatten()
     self.assertEqual(
         [ZeroDivisionError, MemoryError, AttributeError, ImportError],
         [type(ex) for ex in flatten_ex.exceptions])
Exemple #6
0
 def test_handle_all(self):
     agg_ex = AggregateException([ZeroDivisionError(), None, MemoryError()])
     agg_ex.handle(lambda ex: bool(ex))
 def test_handle_all(self):
     agg_ex = AggregateException([ZeroDivisionError(), None, MemoryError()])
     agg_ex.handle(lambda ex: bool(ex))