Skip to content

Commit

Permalink
Enable test_contextlib
Browse files Browse the repository at this point in the history
  • Loading branch information
slozier committed Jun 21, 2022
1 parent 2e5bb60 commit 5ba0513
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
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 Src/IronPythonTest/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/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 @@ -1046,4 +1043,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__)

0 comments on commit 5ba0513

Please sign in to comment.