incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject git commit: [#7047] Fixed substitute_extensions not switching back on exception
Date Fri, 24 Jan 2014 16:39:51 GMT
Updated Branches:
  refs/heads/cj/7047 [created] 518a5cb46


[#7047] Fixed substitute_extensions not switching back on exception

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/518a5cb4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/518a5cb4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/518a5cb4

Branch: refs/heads/cj/7047
Commit: 518a5cb46258d274953e0ea663ffae74c3c463f7
Parents: 3f90515
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Fri Jan 24 16:39:34 2014 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Fri Jan 24 16:39:34 2014 +0000

----------------------------------------------------------------------
 Allura/allura/model/session.py           |  6 ++++--
 Allura/allura/tests/unit/test_session.py | 16 +++++++++++-----
 2 files changed, 15 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/518a5cb4/Allura/allura/model/session.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/session.py b/Allura/allura/model/session.py
index 82973ce..77f8645 100644
--- a/Allura/allura/model/session.py
+++ b/Allura/allura/model/session.py
@@ -222,8 +222,10 @@ def substitute_extensions(session, extensions=None):
         session.close()
         session._kwargs['extensions'] = exts
     _set_exts(extensions or [])
-    yield session
-    _set_exts(original_exts)
+    try:
+        yield session
+    finally:
+        _set_exts(original_exts)
 
 
 main_doc_session = Session.by_name('main')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/518a5cb4/Allura/allura/tests/unit/test_session.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_session.py b/Allura/allura/tests/unit/test_session.py
index b079004..1c5ea08 100644
--- a/Allura/allura/tests/unit/test_session.py
+++ b/Allura/allura/tests/unit/test_session.py
@@ -27,11 +27,17 @@ from allura.model.session import BatchIndexer, substitute_extensions
 def test_extensions_cm():
     session = mock.Mock(_kwargs=dict(extensions=[]))
     extension = mock.Mock()
-    with substitute_extensions(session, [extension]) as sess:
-        assert session.flush.call_count == 1
-        assert session.close.call_count == 1
-        assert sess == session
-        assert sess._kwargs['extensions'] == [extension]
+    try:
+        with substitute_extensions(session, [extension]) as sess:
+            assert session.flush.call_count == 1
+            assert session.close.call_count == 1
+            assert sess == session
+            assert sess._kwargs['extensions'] == [extension]
+            raise ValueError('test')
+    except ValueError as e:
+        pass
+    else:
+        assert False, "Exception didn't propagate"
     assert session.flush.call_count == 2
     assert session.close.call_count == 2
     assert session._kwargs['extensions'] == []


Mime
View raw message