[python-dtcwt] 444/497: ensure preserve_backend_stack() preserves backend name
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Tue Jul 21 18:06:36 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/sid
in repository python-dtcwt.
commit 8ee7ae0df494e64f76894e3282e889b99cebb889
Author: Rich Wareham <rjw57 at cam.ac.uk>
Date: Mon Apr 7 17:10:47 2014 +0100
ensure preserve_backend_stack() preserves backend name
The backend name was incorrectly being modified outside of the with
clause when using preserve_backend_stack().
---
README.rst | 2 ++
dtcwt/__init__.py | 2 ++
tests/testswitchbackends.py | 12 ++++++++----
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/README.rst b/README.rst
index 6a31e77..1e41cd7 100644
--- a/README.rst
+++ b/README.rst
@@ -73,6 +73,8 @@ Changes
* Add queue parameter to low-level OpenCL ``colifilt`` and ``coldfilt`` functions.
* Significantly increase speed of ``dtcwt.registration.estimatereg`` function.
+* Fix bug whereby ``dtcwt.backend_name`` was not restored when using
+ ``preserve_backend_stack``.
0.9.1
'''''
diff --git a/dtcwt/__init__.py b/dtcwt/__init__.py
index ccbd63d..1971d59 100644
--- a/dtcwt/__init__.py
+++ b/dtcwt/__init__.py
@@ -48,6 +48,7 @@ def _update_from_current_backend():
class _BackendGuard(object):
def __init__(self, stack):
+ # Explicitly copy the stack
self._stack = list(stack)
def __enter__(self):
@@ -55,6 +56,7 @@ class _BackendGuard(object):
def __exit__(self, exc_type, exc_value, exc_tb):
dtcwt._BACKEND_STACK = self._stack
+ _update_from_current_backend()
# only re-raise if it's *not* the exception that was
# passed to throw(), because __exit__() must not raise
# an exception unless __exit__() itself failed. But
diff --git a/tests/testswitchbackends.py b/tests/testswitchbackends.py
index 4e1841b..72c558f 100644
--- a/tests/testswitchbackends.py
+++ b/tests/testswitchbackends.py
@@ -80,11 +80,15 @@ def test_backend_with_guard_and_exception():
correctly propagated.
"""
- assert len(dtcwt._BACKEND_STACK) == 1
+ dtcwt.push_backend('numpy')
+ assert len(dtcwt._BACKEND_STACK) == 2
+ assert dtcwt.backend_name == 'numpy'
def tst():
with dtcwt.preserve_backend_stack():
- dtcwt.push_backend('numpy')
- assert len(dtcwt._BACKEND_STACK) == 2
+ dtcwt.push_backend('opencl')
+ assert dtcwt.backend_name == 'opencl'
+ assert len(dtcwt._BACKEND_STACK) == 3
raise RuntimeError('test error')
assert_raises(RuntimeError, tst)
- assert len(dtcwt._BACKEND_STACK) == 1
+ assert dtcwt.backend_name == 'numpy'
+ assert len(dtcwt._BACKEND_STACK) == 2
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-dtcwt.git
More information about the debian-science-commits
mailing list