From 8912fb2d6f159dbb00dfa48869c7580d5f6b9ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Sat, 7 Nov 2026 23:28:47 -0500 Subject: [PATCH] Fix remaining test_contextlib tests --- src/core/IronPython/Runtime/Generator.cs | 10 +++---- tests/suite/stdlib/test_contextlib.py | 33 ------------------------ tests/suite/stdlib/test_yield_from.py | 1 - 3 files changed, 3 insertions(+), 41 deletions(-) delete mode 100644 tests/suite/stdlib/test_contextlib.py diff --git a/src/core/IronPython/Runtime/Generator.cs b/src/core/IronPython/Runtime/Generator.cs index 61be1e766..1014f0e4b 100644 --- a/src/core/IronPython/Runtime/Generator.cs +++ b/src/core/IronPython/Runtime/Generator.cs @@ -159,12 +159,8 @@ private object @throw(object? type, object? value, object? traceback, bool final // We create the actual exception from inside the generator so that if the exception's __init__ // throws, the traceback matches that which we get from CPython. Debug.Assert(_sendValue == null); - _excInfo = new object?[] { type, value, traceback }; - - if (!MoveNextCore()) { - return LightExceptions.Throw(PythonOps.StopIteration()); - } - return CurrentValue; + _excInfo = [ type, value, traceback ]; + return Next(); } } finally { ClearActive(); @@ -492,7 +488,7 @@ private object NextWorker() { // 1. return an item: _next() returns true and 'next' is set to the next item in the enumeration. // 2. Exit normally: _next returns false. // 3. Exit with a StopIteration exception: for-loops and other enumeration consumers will - // catch this and terminate the loop without propogating the exception. + // catch this and terminate the loop without propagating the exception. // 4. Exit via some other unhandled exception: This will close the generator, but the exception still propagates. // _next does not return, so ret is left assigned to false (closed), which we detect in the finally. if (!(ret = GetNext())) { diff --git a/tests/suite/stdlib/test_contextlib.py b/tests/suite/stdlib/test_contextlib.py deleted file mode 100644 index c68980d55..000000000 --- a/tests/suite/stdlib/test_contextlib.py +++ /dev/null @@ -1,33 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the Apache 2.0 License. -# See the LICENSE file in the project root for more information. - -## -## Run selected tests from test_contextlib from StdLib -## - -import sys - -from iptest import is_ironpython, generate_suite, run_test - -import test.test_contextlib - -def load_tests(loader, standard_tests, pattern): - tests = loader.loadTestsFromModule(test.test_contextlib, pattern=pattern) - - if is_ironpython: - failing_tests = [] - if sys.version_info >= (3, 6): - failing_tests += [ - test.test_contextlib.ContextManagerTestCase('test_contextmanager_except_pep479'), # AssertionError: StopIteration was suppressed - test.test_contextlib.ContextManagerTestCase('test_contextmanager_except_stopiter'), # AssertionError: DeprecationWarning not triggered - ] - - skip_tests = [] - - return generate_suite(tests, failing_tests, skip_tests) - - else: - return tests - -run_test(__name__) diff --git a/tests/suite/stdlib/test_yield_from.py b/tests/suite/stdlib/test_yield_from.py index ade9c8625..3bdee1163 100644 --- a/tests/suite/stdlib/test_yield_from.py +++ b/tests/suite/stdlib/test_yield_from.py @@ -19,7 +19,6 @@ def load_tests(loader, standard_tests, pattern): if is_ironpython: failing_tests = [ test_yield_from.TestPEP380Operation('test_broken_getattr_handling'), # TODO: figure out - test_yield_from.TestPEP380Operation('test_catching_exception_from_subgen_and_returning'), # TODO: figure out ] skip_tests = []