Ejemplo n.º 1
0
def test_backend_with_guard():
    """Test that manipulating the stack with preserve_backend_stack() will
    return the stack to its pristine state even i pushes and pops are
    imbalanced.

    """
    assert len(dtcwt._BACKEND_STACK) == 1
    with dtcwt.preserve_backend_stack():
        dtcwt.push_backend('numpy')
        assert len(dtcwt._BACKEND_STACK) == 2
    assert len(dtcwt._BACKEND_STACK) == 1
Ejemplo n.º 2
0
def test_backend_with_guard_and_exception():
    """Tests that even when preserving the backend stack, an exception is
    correctly propagated.

    """
    dtcwt.push_backend('numpy')
    assert len(dtcwt._BACKEND_STACK) == 2
    assert dtcwt.backend_name == 'numpy'
    with raises(RuntimeError):
        with dtcwt.preserve_backend_stack():
            dtcwt.push_backend('opencl')
            assert dtcwt.backend_name == 'opencl'
            assert len(dtcwt._BACKEND_STACK) == 3
            raise RuntimeError('test error')
    assert dtcwt.backend_name == 'numpy'
    assert len(dtcwt._BACKEND_STACK) == 2
Ejemplo n.º 3
0
 def tst():
     with dtcwt.preserve_backend_stack():
         dtcwt.push_backend('numpy')
         assert len(dtcwt._BACKEND_STACK) == 2
         raise RuntimeError('test error')