Lines Matching refs:self

6     def test_mixed_except_and_except_star_is_syntax_error(self):
19 with self.assertRaises(SyntaxError):
22 def test_except_star_ExceptionGroup_is_runtime_error_single(self):
23 with self.assertRaises(TypeError):
29 def test_except_star_ExceptionGroup_is_runtime_error_tuple(self):
30 with self.assertRaises(TypeError):
36 def test_except_star_invalid_exception_type(self):
37 with self.assertRaises(TypeError):
43 with self.assertRaises(TypeError):
54 def check_invalid(self, src):
55 with self.assertRaisesRegex(SyntaxError, self.MSG):
58 def test_break_in_except_star(self):
59 self.check_invalid(
67 self.check_invalid(
77 self.check_invalid(
90 def test_continue_in_except_star_block_invalid(self):
91 self.check_invalid(
100 self.check_invalid(
110 self.check_invalid(
122 def test_return_in_except_star_block_invalid(self):
123 self.check_invalid(
132 self.check_invalid(
143 def test_break_continue_in_except_star_block_valid(self):
155 self.assertEqual(count, 3)
156 self.assertEqual(i, 4)
158 self.assertIsInstance(exc, ExceptionGroup)
160 def test_return_in_except_star_block_valid(self):
168 self.assertEqual(r, 6)
169 self.assertIsInstance(exc, ExceptionGroup)
173 def assertExceptionIsLike(self, exc, template):
178 self.fail(f"unexpected exception: {exc}")
181 self.fail(f"expected an exception like {template!r}, got None")
184 self.assertEqual(exc.__class__, template.__class__)
185 self.assertEqual(exc.args[0], template.args[0])
187 self.assertEqual(exc.message, template.message)
188 self.assertEqual(len(exc.exceptions), len(template.exceptions))
190 self.assertExceptionIsLike(e, t)
192 def assertMetadataEqual(self, e1, e2):
194 self.assertTrue(e1 is None and e2 is None)
196 self.assertEqual(e1.__context__, e2.__context__)
197 self.assertEqual(e1.__cause__, e2.__cause__)
198 self.assertEqual(e1.__traceback__, e2.__traceback__)
200 def assertMetadataNotEqual(self, e1, e2):
202 self.assertNotEqual(e1, e2)
210 def doSplitTestNamed(self, exc, T, match_template, rest_template):
222 self.assertEqual(sys_exception, match)
223 self.assertExceptionIsLike(match, match_template)
224 self.assertExceptionIsLike(rest, rest_template)
225 self.assertEqual(sys.exception(), initial_sys_exception)
227 def doSplitTestUnnamed(self, exc, T, match_template, rest_template):
237 self.fail("Exception not raised")
240 self.assertExceptionIsLike(match, match_template)
241 self.assertExceptionIsLike(rest, rest_template)
242 self.assertEqual(sys.exception(), initial_sys_exception)
244 def doSplitTestInExceptHandler(self, exc, T, match_template, rest_template):
248 self.doSplitTestNamed(exc, T, match_template, rest_template)
249 self.doSplitTestUnnamed(exc, T, match_template, rest_template)
251 def doSplitTestInExceptStarHandler(self, exc, T, match_template, rest_template):
255 self.doSplitTestNamed(exc, T, match_template, rest_template)
256 self.doSplitTestUnnamed(exc, T, match_template, rest_template)
258 def doSplitTest(self, exc, T, match_template, rest_template):
259 self.doSplitTestNamed(exc, T, match_template, rest_template)
260 self.doSplitTestUnnamed(exc, T, match_template, rest_template)
261 self.doSplitTestInExceptHandler(exc, T, match_template, rest_template)
262 self.doSplitTestInExceptStarHandler(exc, T, match_template, rest_template)
264 def test_no_match_single_type(self):
265 self.doSplitTest(
271 def test_match_single_type(self):
272 self.doSplitTest(
278 def test_match_single_type_partial_match(self):
279 self.doSplitTest(
287 def test_match_single_type_nested(self):
288 self.doSplitTest(
308 def test_match_type_tuple_nested(self):
309 self.doSplitTest(
326 def test_empty_groups_removed(self):
327 self.doSplitTest(
341 def test_singleton_groups_are_kept(self):
342 self.doSplitTest(
355 def test_naked_exception_matched_wrapped1(self):
356 self.doSplitTest(
362 def test_naked_exception_matched_wrapped2(self):
363 self.doSplitTest(
369 def test_exception_group_except_star_Exception_not_wrapped(self):
370 self.doSplitTest(
376 def test_plain_exception_not_matched(self):
377 self.doSplitTest(
383 def test_match__supertype(self):
384 self.doSplitTest(
390 def test_multiple_matches_named(self):
394 self.assertExceptionIsLike(e,
397 self.assertExceptionIsLike(e,
400 self.fail("Exception not raised")
402 def test_multiple_matches_unnamed(self):
407 self.assertExceptionIsLike(e,
411 self.assertExceptionIsLike(e,
414 self.fail("Exception not raised")
416 def test_first_match_wins_named(self):
420 self.assertExceptionIsLike(e,
423 self.fail("Should have been matched as OSError")
425 self.fail("Exception not raised")
427 def test_first_match_wins_unnamed(self):
432 self.assertExceptionIsLike(e,
437 self.fail("Exception not raised")
439 def test_nested_except_stars(self):
448 self.fail("Exception not raised")
450 self.assertExceptionIsLike(e,
453 self.fail("Exception not raised")
455 def test_nested_in_loop(self):
462 self.fail("Exception not raised")
466 def test_reraise_all_named(self):
479 self.assertExceptionIsLike(
483 def test_reraise_all_unnamed(self):
496 self.assertExceptionIsLike(
500 def test_reraise_some_handle_all_named(self):
513 self.assertExceptionIsLike(
516 def test_reraise_partial_handle_all_unnamed(self):
528 self.assertExceptionIsLike(
531 def test_reraise_partial_handle_some_named(self):
544 self.assertExceptionIsLike(
547 def test_reraise_partial_handle_some_unnamed(self):
559 self.assertExceptionIsLike(
562 def test_reraise_plain_exception_named(self):
571 self.assertExceptionIsLike(
574 def test_reraise_plain_exception_unnamed(self):
583 self.assertExceptionIsLike(
588 def test_raise_named(self):
598 self.assertExceptionIsLike(
603 self.assertExceptionIsLike(
607 self.assertMetadataNotEqual(orig, exc)
608 self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
610 def test_raise_unnamed(self):
620 self.assertExceptionIsLike(
625 self.assertExceptionIsLike(
629 self.assertMetadataNotEqual(orig, exc)
630 self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
632 def test_raise_handle_all_raise_one_named(self):
642 self.assertExceptionIsLike(exc, SyntaxError(3))
644 self.assertExceptionIsLike(
648 self.assertMetadataNotEqual(orig, exc)
649 self.assertMetadataEqual(orig, exc.__context__)
651 def test_raise_handle_all_raise_one_unnamed(self):
661 self.assertExceptionIsLike(exc, SyntaxError(3))
663 self.assertExceptionIsLike(
667 self.assertMetadataNotEqual(orig, exc)
668 self.assertMetadataEqual(orig, exc.__context__)
670 def test_raise_handle_all_raise_two_named(self):
682 self.assertExceptionIsLike(
685 self.assertExceptionIsLike(
689 self.assertExceptionIsLike(
693 self.assertMetadataNotEqual(orig, exc)
694 self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
695 self.assertMetadataEqual(orig, exc.exceptions[1].__context__)
697 def test_raise_handle_all_raise_two_unnamed(self):
709 self.assertExceptionIsLike(
712 self.assertExceptionIsLike(
716 self.assertExceptionIsLike(
720 self.assertMetadataNotEqual(orig, exc)
721 self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
722 self.assertMetadataEqual(orig, exc.exceptions[1].__context__)
726 def test_raise_named(self):
736 self.assertExceptionIsLike(
741 self.assertExceptionIsLike(
745 self.assertExceptionIsLike(
749 self.assertMetadataNotEqual(orig, exc)
750 self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
751 self.assertMetadataEqual(orig, exc.exceptions[0].__cause__)
752 self.assertMetadataNotEqual(orig, exc.exceptions[1].__context__)
753 self.assertMetadataNotEqual(orig, exc.exceptions[1].__cause__)
755 def test_raise_unnamed(self):
766 self.assertExceptionIsLike(
771 self.assertExceptionIsLike(
775 self.assertExceptionIsLike(
779 self.assertMetadataNotEqual(orig, exc)
780 self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
781 self.assertMetadataEqual(orig, exc.exceptions[0].__cause__)
782 self.assertMetadataNotEqual(orig, exc.exceptions[1].__context__)
783 self.assertMetadataNotEqual(orig, exc.exceptions[1].__cause__)
785 def test_raise_handle_all_raise_one_named(self):
795 self.assertExceptionIsLike(exc, SyntaxError(3))
797 self.assertExceptionIsLike(
801 self.assertExceptionIsLike(
805 self.assertMetadataNotEqual(orig, exc)
806 self.assertMetadataEqual(orig, exc.__context__)
807 self.assertMetadataEqual(orig, exc.__cause__)
809 def test_raise_handle_all_raise_one_unnamed(self):
820 self.assertExceptionIsLike(exc, SyntaxError(3))
822 self.assertExceptionIsLike(
826 self.assertExceptionIsLike(
830 self.assertMetadataNotEqual(orig, exc)
831 self.assertMetadataEqual(orig, exc.__context__)
832 self.assertMetadataEqual(orig, exc.__cause__)
834 def test_raise_handle_all_raise_two_named(self):
846 self.assertExceptionIsLike(
849 self.assertExceptionIsLike(
853 self.assertExceptionIsLike(
857 self.assertExceptionIsLike(
861 self.assertExceptionIsLike(
865 self.assertMetadataNotEqual(orig, exc)
866 self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
867 self.assertMetadataEqual(orig, exc.exceptions[0].__cause__)
869 def test_raise_handle_all_raise_two_unnamed(self):
883 self.assertExceptionIsLike(
886 self.assertExceptionIsLike(
890 self.assertExceptionIsLike(
894 self.assertExceptionIsLike(
898 self.assertExceptionIsLike(
902 self.assertMetadataNotEqual(orig, exc)
903 self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
904 self.assertMetadataEqual(orig, exc.exceptions[0].__cause__)
905 self.assertMetadataEqual(orig, exc.exceptions[1].__context__)
906 self.assertMetadataEqual(orig, exc.exceptions[1].__cause__)
910 def test_except_star_EG_subclass(self):
917 def derive(self, excs):
918 return EG(self.message, excs, self.code)
937 self.assertIsInstance(veg, EG)
938 self.assertIsInstance(teg, EG)
939 self.assertIsInstance(teg.exceptions[0], EG)
940 self.assertMetadataEqual(veg, teg)
941 self.assertEqual(veg.code, 42)
942 self.assertEqual(teg.code, 42)
943 self.assertEqual(teg.exceptions[0].code, 101)
945 def test_falsy_exception_group_subclass(self):
947 def __bool__(self):
950 def derive(self, excs):
951 return FalsyEG(self.message, excs)
966 self.assertFalse(e)
967 self.assertIsInstance(e, FalsyEG)
969 self.assertExceptionIsLike(exc, FalsyEG("eg", [TypeError(1)]))
970 self.assertExceptionIsLike(tes, FalsyEG("eg", [TypeError(1)]))
971 self.assertExceptionIsLike(ves, FalsyEG("eg", [ValueError(2)]))
975 def test_sys_exception_restored(self):
988 self.assertExceptionIsLike(exc, ZeroDivisionError('division by zero'))
989 self.assertExceptionIsLike(exc.__context__, ValueError(42))
990 self.assertEqual(sys.exception(), None)
1001 def __eq__(self, other):
1005 def __eq__(self, other):
1009 def __eq__(self, other):
1012 def setUp(self):
1013 self.bad_types = [self.UnhashableExc,
1014 self.AlwaysEqualExc,
1015 self.NeverEqualExc,
1016 self.BrokenEqualExc]
1018 def except_type(self, eg, type):
1029 def test_catch_unhashable_leaf_exception(self):
1030 for Bad in self.bad_types:
1031 with self.subTest(Bad):
1033 match, rest = self.except_type(eg, Bad)
1034 self.assertExceptionIsLike(
1036 self.assertExceptionIsLike(
1039 def test_propagate_unhashable_leaf(self):
1040 for Bad in self.bad_types:
1041 with self.subTest(Bad):
1043 match, rest = self.except_type(eg, TypeError)
1044 self.assertExceptionIsLike(
1046 self.assertExceptionIsLike(
1049 def test_catch_nothing_unhashable_leaf(self):
1050 for Bad in self.bad_types:
1051 with self.subTest(Bad):
1053 match, rest = self.except_type(eg, OSError)
1054 self.assertIsNone(match)
1055 self.assertExceptionIsLike(rest, eg)
1057 def test_catch_everything_unhashable_leaf(self):
1058 for Bad in self.bad_types:
1059 with self.subTest(Bad):
1061 match, rest = self.except_type(eg, Exception)
1062 self.assertExceptionIsLike(match, eg)
1063 self.assertIsNone(rest)
1065 def test_reraise_unhashable_leaf(self):
1066 for Bad in self.bad_types:
1067 with self.subTest(Bad):
1081 self.assertExceptionIsLike(
1092 def derive(self, excs):
1093 return type(self)(self.message, excs)
1096 def __eq__(self, other):
1099 def derive(self, excs):
1100 return type(self)(self.message, excs)
1103 def __eq__(self, other):
1106 def derive(self, excs):
1107 return type(self)(self.message, excs)
1110 def __eq__(self, other):
1113 def derive(self, excs):
1114 return type(self)(self.message, excs)
1116 def setUp(self):
1117 self.bad_types = [self.UnhashableEG,
1118 self.AlwaysEqualEG,
1119 self.NeverEqualEG,
1120 self.BrokenEqualEG]
1122 def except_type(self, eg, type):
1133 def test_catch_some_unhashable_exception_group_subclass(self):
1134 for BadEG in self.bad_types:
1135 with self.subTest(BadEG):
1140 match, rest = self.except_type(eg, TypeError)
1141 self.assertExceptionIsLike(match, BadEG("eg", [TypeError(1)]))
1142 self.assertExceptionIsLike(rest,
1145 def test_catch_none_unhashable_exception_group_subclass(self):
1146 for BadEG in self.bad_types:
1147 with self.subTest(BadEG):
1153 match, rest = self.except_type(eg, OSError)
1154 self.assertIsNone(match)
1155 self.assertExceptionIsLike(rest, eg)
1157 def test_catch_all_unhashable_exception_group_subclass(self):
1158 for BadEG in self.bad_types:
1159 with self.subTest(BadEG):
1165 match, rest = self.except_type(eg, Exception)
1166 self.assertExceptionIsLike(match, eg)
1167 self.assertIsNone(rest)
1169 def test_reraise_unhashable_eg(self):
1170 for BadEG in self.bad_types:
1171 with self.subTest(BadEG):
1187 self.assertExceptionIsLike(