Skip to content

Commit e1865b5

Browse files
committed
Enable test_contextlib
1 parent 29308e7 commit e1865b5

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
@@ -276,9 +276,6 @@ public BaseException? __context__ {
276276
get {
277277
return _context ?? __cause__;
278278
}
279-
internal set {
280-
_context = value;
281-
}
282279
}
283280

284281
public bool __suppress_context__ { get; set; }
@@ -361,7 +358,7 @@ protected internal virtual void InitializeFromClr(System.Exception/*!*/ exceptio
361358

362359
internal Exception CreateClrExceptionWithCause(BaseException? cause, BaseException? context, bool suppressContext) {
363360
_cause = cause;
364-
_context = context;
361+
if (context != this) _context = context;
365362
__suppress_context__ = suppressContext;
366363
_traceback = null;
367364

tests/IronPython.Tests/Cases/CPythonCasesManifest.ini

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

280-
[CPython.test_contextlib]
281-
Ignore=true
282-
Reason=Hangs
283-
284280
[CPython.test_copy]
285281
IsolationLevel=ENGINE
286282
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)