Skip to content

Commit f08b0de

Browse files
committed
Enable test_contextlib
1 parent ef9a15e commit f08b0de

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

Src/IronPython/Runtime/Exceptions/PythonExceptions.BaseException.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,6 @@ public BaseException? __context__ {
280280
get {
281281
return _context ?? __cause__;
282282
}
283-
internal set {
284-
_context = value;
285-
}
286283
}
287284

288285
public bool __suppress_context__ { get; set; }
@@ -365,7 +362,7 @@ protected internal virtual void InitializeFromClr(System.Exception/*!*/ exceptio
365362

366363
internal Exception CreateClrExceptionWithCause(BaseException? cause, BaseException? context, bool suppressContext) {
367364
_cause = cause;
368-
_context = context;
365+
if (context != this) _context = context;
369366
__suppress_context__ = suppressContext;
370367
_traceback = null;
371368

Src/IronPythonTest/Cases/CPythonCasesManifest.ini

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Reason=ImportError: No module named audioop
186186
Ignore=true
187187

188188
[CPython.test_binhex]
189-
Ignore=true
189+
Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/673
190190

191191
[CPython.test_builtin] # IronPython.test_builtin_stdlib
192192
Ignore=true
@@ -297,10 +297,6 @@ Ignore=true
297297
Ignore=true
298298
Reason=ImportError: Cannot import name SemLock
299299

300-
[CPython.test_contextlib]
301-
Ignore=true
302-
Reason=Hangs
303-
304300
[CPython.test_copy]
305301
IsolationLevel=ENGINE
306302
MaxRecursion=100
@@ -661,6 +657,7 @@ Ignore=true
661657
Reason=unittest.case.SkipTest: No module named 'nis'
662658

663659
[CPython.test_nntplib]
660+
Ignore=true # currently failing in CI
664661
RunCondition=NOT $(IS_NETCOREAPP) # https://github.com/IronLanguages/ironpython3/issues/1058
665662

666663
[CPython.test_normalization]

Tests/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):
@@ -1046,4 +1043,28 @@ def f():
10461043

10471044
self.assertRaises(error, f)
10481045

1046+
def test_reraise_context(self):
1047+
# reraising an exception should preserve the context
1048+
ex1 = Exception(1)
1049+
try:
1050+
try:
1051+
raise ex1
1052+
except:
1053+
raise ex1
1054+
except Exception as e:
1055+
self.assertIsNone(e.__context__)
1056+
1057+
ex1 = Exception(1)
1058+
ex2 = Exception(2)
1059+
try:
1060+
try:
1061+
try:
1062+
raise ex2
1063+
except:
1064+
raise ex1
1065+
except:
1066+
raise ex1
1067+
except Exception as e:
1068+
self.assertIs(e.__context__, ex2)
1069+
10491070
run_test(__name__)

0 commit comments

Comments
 (0)