(self, *, raises)
| 2810 | self.do_test_remove_with_clear(raises=False) |
| 2811 | |
| 2812 | def do_test_remove_with_clear(self, *, raises): |
| 2813 | |
| 2814 | # Until the discrepency between "del root[:]" and "root.clear()" is |
| 2815 | # resolved, we need to keep two tests. Previously, using "del root[:]" |
| 2816 | # did not crash with the reproducer of gh-126033 while "root.clear()" |
| 2817 | # did. |
| 2818 | |
| 2819 | class E(ET.Element): |
| 2820 | """Local class to be able to mock E.__eq__ for introspection.""" |
| 2821 | |
| 2822 | class X(E): |
| 2823 | def __eq__(self, o): |
| 2824 | del root[:] |
| 2825 | return not raises |
| 2826 | |
| 2827 | class Y(E): |
| 2828 | def __eq__(self, o): |
| 2829 | root.clear() |
| 2830 | return not raises |
| 2831 | |
| 2832 | if raises: |
| 2833 | get_checker_context = lambda: self.assertRaises(ValueError) |
| 2834 | else: |
| 2835 | get_checker_context = nullcontext |
| 2836 | |
| 2837 | self.assertIs(E.__eq__, object.__eq__) |
| 2838 | |
| 2839 | for Z, side_effect in [(X, 'del root[:]'), (Y, 'root.clear()')]: |
| 2840 | self.enterContext(self.subTest(side_effect=side_effect)) |
| 2841 | |
| 2842 | # test removing R() from [U()] |
| 2843 | for R, U, description in [ |
| 2844 | (E, Z, "remove missing E() from [Z()]"), |
| 2845 | (Z, E, "remove missing Z() from [E()]"), |
| 2846 | (Z, Z, "remove missing Z() from [Z()]"), |
| 2847 | ]: |
| 2848 | with self.subTest(description): |
| 2849 | root = E('top') |
| 2850 | root.extend([U('one')]) |
| 2851 | with get_checker_context(): |
| 2852 | root.remove(R('missing')) |
| 2853 | |
| 2854 | # test removing R() from [U(), V()] |
| 2855 | cases = self.cases_for_remove_missing_with_mutations(E, Z) |
| 2856 | for R, U, V, description in cases: |
| 2857 | with self.subTest(description): |
| 2858 | root = E('top') |
| 2859 | root.extend([U('one'), V('two')]) |
| 2860 | with get_checker_context(): |
| 2861 | root.remove(R('missing')) |
| 2862 | |
| 2863 | # Test removing root[0] from [Z()]. |
| 2864 | # |
| 2865 | # Since we call root.remove() with root[0], Z.__eq__() |
| 2866 | # will not be called (we branch on the fast Py_EQ path). |
| 2867 | with self.subTest("remove root[0] from [Z()]"): |
| 2868 | root = E('top') |
| 2869 | root.append(Z('rem')) |
no test coverage detected