cubed
cubed copied to clipboard
Add `raise_if_computes` for testing
Fixes #310
This is useful for xarray testing.
I had hoped to be able to implement this by writing an executor that raises when its execute_dag method is called - but that doesn't work. The problem is that the second part of this test fails, since b's spec object contains the raise-if-computes executor since it was created within the context manager. Even though compute is called outside the context manager, the executor is still set on the spec, so that is what is used.
def test_raise_if_computes():
# shouldn't raise since compute has not been called
with raise_if_computes():
a = xp.ones((3, 3), chunks=(2, 2))
b = xp.negative(a)
# shouldn't raise since we are outside the context manager
assert_array_equal(b.compute(), -np.ones((3, 3)))
I'm not sure that changing this is the right thing to do, hence this PR which does things a bit more directly.