Skip to content

Enable test_contextlib #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,6 @@ public BaseException? __context__ {
get {
return _context ?? __cause__;
}
internal set {
_context = value;
}
}

public bool __suppress_context__ { get; set; }
Expand Down Expand Up @@ -363,7 +360,7 @@ protected internal virtual void InitializeFromClr(System.Exception/*!*/ exceptio

internal Exception CreateClrExceptionWithCause(BaseException? cause, BaseException? context, bool suppressContext) {
_cause = cause;
_context = context;
if (context != this) _context = context;
__suppress_context__ = suppressContext;
_traceback = null;

Expand Down
4 changes: 0 additions & 4 deletions tests/IronPython.Tests/Cases/CPythonCasesManifest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,6 @@ Ignore=true
Ignore=true
Reason=ImportError: Cannot import name SemLock

[CPython.test_contextlib]
Ignore=true
Reason=Hangs

[CPython.test_copy]
IsolationLevel=ENGINE
MaxRecursion=100
Expand Down
29 changes: 25 additions & 4 deletions tests/suite/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ def test_finally_continue_nested_finally_fails(self):
finally:
continue
'''
try:
with self.assertRaises(SyntaxError):
compile(t, '<test>', 'exec')
self.fail("Should raise SyntaxError")
except SyntaxError:
pass

def test_bigint_division(self):
def divide(a, b):
Expand Down Expand Up @@ -1079,4 +1076,28 @@ def f():

self.assertRaises(error, f)

def test_reraise_context(self):
# reraising an exception should preserve the context
ex1 = Exception(1)
try:
try:
raise ex1
except:
raise ex1
except Exception as e:
self.assertIsNone(e.__context__)

ex1 = Exception(1)
ex2 = Exception(2)
try:
try:
try:
raise ex2
except:
raise ex1
except:
raise ex1
except Exception as e:
self.assertIs(e.__context__, ex2)

run_test(__name__)
Loading