cubed icon indicating copy to clipboard operation
cubed copied to clipboard

Add `raise_if_computes` for testing

Open tomwhite opened this issue 1 year ago • 2 comments

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.

tomwhite avatar Aug 08 '24 11:08 tomwhite