Skip to content

Commit aff04ac

Browse files
committed
Enable test_contextlib
1 parent 2aca667 commit aff04ac

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

src/core/IronPython/Runtime/Exceptions/PythonExceptions.BaseException.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,6 @@ public BaseException? __context__ {
278278
get {
279279
return _context ?? __cause__;
280280
}
281-
internal set {
282-
_context = value;
283-
}
284281
}
285282

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

364361
internal Exception CreateClrExceptionWithCause(BaseException? cause, BaseException? context, bool suppressContext) {
365362
_cause = cause;
366-
_context = context;
363+
if (context != this) _context = context;
367364
__suppress_context__ = suppressContext;
368365
_traceback = null;
369366

tests/IronPython.Tests/Cases/CPythonCasesManifest.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,6 @@ Ignore=true
275275
Ignore=true
276276
Reason=ImportError: Cannot import name SemLock
277277

278-
[CPython.test_contextlib]
279-
Ignore=true
280-
Reason=Hangs
281-
282278
[CPython.test_copy]
283279
IsolationLevel=ENGINE
284280
MaxRecursion=100

tests/suite/test_exceptions.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,8 @@ def test_finally_continue_nested_finally_fails(self):
8787
finally:
8888
continue
8989
'''
90-
try:
90+
with self.assertRaises(SyntaxError):
9191
compile(t, '<test>', 'exec')
92-
self.fail("Should raise SyntaxError")
93-
except SyntaxError:
94-
pass
9592

9693
def test_bigint_division(self):
9794
def divide(a, b):
@@ -1079,4 +1076,28 @@ def f():
10791076

10801077
self.assertRaises(error, f)
10811078

1079+
def test_reraise_context(self):
1080+
# reraising an exception should preserve the context
1081+
ex1 = Exception(1)
1082+
try:
1083+
try:
1084+
raise ex1
1085+
except:
1086+
raise ex1
1087+
except Exception as e:
1088+
self.assertIsNone(e.__context__)
1089+
1090+
ex1 = Exception(1)
1091+
ex2 = Exception(2)
1092+
try:
1093+
try:
1094+
try:
1095+
raise ex2
1096+
except:
1097+
raise ex1
1098+
except:
1099+
raise ex1
1100+
except Exception as e:
1101+
self.assertIs(e.__context__, ex2)
1102+
10821103
run_test(__name__)

0 commit comments

Comments
 (0)