Lines Matching defs:eg
31 ExceptionGroup('eg', [ValueError('too')], [TypeError('many')])
45 ExceptionGroup("eg", None)
49 ExceptionGroup("eg", [])
64 type(ExceptionGroup("eg", excs)),
76 eg = ExceptionGroup("eg", [ValueError(1), KeyboardInterrupt(2)])
87 type(MyEG("eg", [ValueError(12), TypeError(42)])),
96 MyEG("eg", [ValueError(12), KeyboardInterrupt(42)])
104 MyEG("eg", [ValueError(12), KeyboardInterrupt(42)])
111 MyEG("eg", [ValueError(12), Exception()])
118 MyEG("eg", [ValueError(12), Exception()])
126 type(MyBEG("eg", [ValueError(12), TypeError(42)])),
129 type(MyBEG("eg", [ValueError(12), KeyboardInterrupt(42)])),
135 eg = BaseExceptionGroup(
138 self.assertEqual(str(eg), "flat (2 sub-exceptions)")
139 self.assertEqual(repr(eg),
142 eg = BaseExceptionGroup(
143 'nested', [eg, ValueError(1), eg, TypeError(2)])
145 self.assertEqual(str(eg), "nested (4 sub-exceptions)")
146 self.assertEqual(repr(eg),
155 eg = BaseExceptionGroup(
158 self.assertEqual(str(eg), "flat (2 sub-exceptions)")
159 self.assertEqual(repr(eg),
164 eg = BaseExceptionGroup(
165 'nested', [eg, ValueError(1), eg])
167 self.assertEqual(str(eg), "nested (3 sub-exceptions)")
168 self.assertEqual(repr(eg),
180 eg = MyEG(
183 self.assertEqual(str(eg), "flat (2 sub-exceptions)")
184 self.assertEqual(repr(eg), "MyEG('flat', [ValueError(1), TypeError(2)])")
186 eg = MyEG(
187 'nested', [eg, ValueError(1), eg, TypeError(2)])
189 self.assertEqual(str(eg), "nested (4 sub-exceptions)")
190 self.assertEqual(repr(eg), (
225 raise ExceptionGroup('simple eg', excs)
232 eg = create_simple_eg()
235 self.assertEqual(eg.message, 'simple eg')
236 self.assertEqual(eg.args[0], 'simple eg')
239 self.assertIsInstance(eg.exceptions[0], ValueError)
240 self.assertIsInstance(eg.exceptions[0].__cause__, MemoryError)
241 self.assertIsInstance(eg.exceptions[0].__context__, MemoryError)
242 self.assertIsInstance(eg.exceptions[1], TypeError)
243 self.assertIsNone(eg.exceptions[1].__cause__)
244 self.assertIsInstance(eg.exceptions[1].__context__, OSError)
245 self.assertIsInstance(eg.exceptions[2], ValueError)
246 self.assertIsNone(eg.exceptions[2].__cause__)
247 self.assertIsInstance(eg.exceptions[2].__context__, ImportError)
253 self.assertEqual(eg.__traceback__.tb_lineno, tb_linenos[0])
254 self.assertIsNone(eg.__traceback__.tb_next)
256 tb = eg.exceptions[i].__traceback__
261 eg = ExceptionGroup('eg', [TypeError(1), OSError(2)])
263 self.assertEqual(type(eg.exceptions), tuple)
265 eg.message
267 eg.message = "new msg"
269 eg.exceptions
271 eg.exceptions = [OSError('xyz')]
301 self.eg = create_simple_eg()
311 self.eg.subgroup(arg)
313 self.eg.split(arg)
316 eg = self.eg
317 self.assertIs(eg, eg.subgroup(BaseException))
318 self.assertIs(eg, eg.subgroup(Exception))
319 self.assertIs(eg, eg.subgroup(BaseExceptionGroup))
320 self.assertIs(eg, eg.subgroup(ExceptionGroup))
323 self.assertIsNone(self.eg.subgroup(OSError))
326 eg = self.eg
335 subeg = eg.subgroup(match_type)
336 self.assertEqual(subeg.message, eg.message)
340 self.assertIs(self.eg, self.eg.subgroup(lambda e: True))
343 self.assertIsNone(self.eg.subgroup(lambda e: False))
346 eg = self.eg
354 subeg = eg.subgroup(lambda e: isinstance(e, match_type))
355 self.assertEqual(subeg.message, eg.message)
361 self.eg = create_simple_eg()
367 match, rest = self.eg.split(E)
373 match, rest = self.eg.split(OSError)
379 eg = self.eg
391 match, rest = eg.split(match_type)
392 self.assertEqual(match.message, eg.message)
396 self.assertEqual(rest.message, eg.message)
403 match, rest = self.eg.split(lambda e: True)
408 match, rest = self.eg.split(lambda e: False)
413 eg = self.eg
424 match, rest = eg.split(lambda e: isinstance(e, match_type))
425 self.assertEqual(match.message, eg.message)
429 self.assertEqual(rest.message, eg.message)
438 e = ExceptionGroup('eg', [e])
473 eg = create_simple_eg()
476 [e for e, _ in leaf_generator(eg)],
477 eg.exceptions)
479 for e, tbs in leaf_generator(eg):
481 tbs, [eg.__traceback__, e.__traceback__])
504 except ExceptionGroup as eg:
505 return eg
510 eg = create_nested_eg()
512 eg,
517 eg = create_nested_eg()
518 self.assertIsInstance(eg.exceptions[1].__context__, MemoryError)
519 self.assertIsInstance(eg.exceptions[1].__cause__, MemoryError)
520 self.assertIsInstance(eg.exceptions[0].__context__, TypeError)
523 eg = create_nested_eg()
527 (eg.__traceback__, line0 + 19),
528 (eg.exceptions[0].__traceback__, line0 + 6),
529 (eg.exceptions[1].__traceback__, line0 + 14),
530 (eg.exceptions[0].exceptions[0].__traceback__, line0 + 4),
536 eg = create_nested_eg()
539 self.assertEqual(len(list(leaf_generator(eg))), 2)
545 for (i, (_, tbs)) in enumerate(leaf_generator(eg)):
553 def split_exception_group(self, eg, types):
555 self.assertIsInstance(eg, BaseExceptionGroup)
557 match, rest = eg.split(types)
558 sg = eg.subgroup(types)
581 # each leaf exception of eg is in exactly one of match and rest
583 len(leaves(eg)),
586 for e in leaves(eg):
591 # message, cause and context, traceback and note equal to eg
594 self.assertEqual(eg.message, part.message)
595 self.assertIs(eg.__cause__, part.__cause__)
596 self.assertIs(eg.__context__, part.__context__)
597 self.assertIs(eg.__traceback__, part.__traceback__)
599 getattr(eg, '__notes__', None),
602 def tbs_for_leaf(leaf, eg):
603 for e, tbs in leaf_generator(eg):
614 tb_linenos(tbs_for_leaf(e, eg)),
666 eg = e
686 self.assertMatchesTemplate(eg, ExceptionGroup, eg_template)
689 match, rest = self.split_exception_group(eg, SyntaxError)
694 match, rest = self.split_exception_group(eg, BaseException)
697 match, rest = self.split_exception_group(eg, (ValueError, TypeError))
702 match, rest = self.split_exception_group(eg, ValueError)
707 match, rest = self.split_exception_group(eg, (TypeError, SyntaxError))
712 match, rest = eg.split(ExceptionGroup)
713 self.assertIs(match, eg)
717 match, rest = eg.split(MyExceptionGroup)
763 eg = ExceptionGroup("eg", [ValueError(1), TypeError(2)])
764 eg.add_note("note1")
765 eg.add_note("note2")
766 orig_notes = list(eg.__notes__)
767 match, rest = eg.split(TypeError)
768 self.assertEqual(eg.__notes__, orig_notes)
771 self.assertIsNot(eg.__notes__, match.__notes__)
772 self.assertIsNot(eg.__notes__, rest.__notes__)
774 eg.add_note("eg")
777 self.assertEqual(eg.__notes__, orig_notes + ["eg"])
784 eg = ExceptionGroup("eg", [ValueError(1), TypeError(2)])
785 eg.__notes__ = 123
786 match, rest = eg.split(TypeError)
807 raise EG("eg", [ve, nested])
809 eg = e
811 self.assertMatchesTemplate(eg, EG, [ValueError(1), [TypeError(2)]])
814 match, rest = self.split_exception_group(eg, OSError)
820 match, rest = self.split_exception_group(eg, (ValueError, TypeError))
826 match, rest = self.split_exception_group(eg, ValueError)
831 match, rest = self.split_exception_group(eg, TypeError)
845 raise EG("eg", [ValueError(1), KeyboardInterrupt(2)], "unused")
847 eg = e
850 eg, EG, [ValueError(1), KeyboardInterrupt(2)])
853 match, rest = self.split_exception_group(eg, OSError)
860 eg, (ValueError, KeyboardInterrupt))
866 match, rest = self.split_exception_group(eg, ValueError)
872 match, rest = self.split_exception_group(eg, KeyboardInterrupt)
897 raise EG("eg", [ve, nested], 42)
899 eg = e
901 self.assertMatchesTemplate(eg, EG, [ValueError(1), [TypeError(2)]])
904 match, rest = self.split_exception_group(eg, OSError)
911 match, rest = self.split_exception_group(eg, (ValueError, TypeError))
918 match, rest = self.split_exception_group(eg, ValueError)
926 match, rest = self.split_exception_group(eg, TypeError)