()
| 2087 | |
| 2088 | |
| 2089 | def test_store_delayed_target(): |
| 2090 | from dask.delayed import delayed |
| 2091 | |
| 2092 | d = da.ones((4, 4), chunks=(2, 2)) |
| 2093 | a, b = d + 1, d + 2 |
| 2094 | |
| 2095 | # empty buffers to be used as targets |
| 2096 | targs = {} |
| 2097 | |
| 2098 | def make_target(key): |
| 2099 | a = np.empty((4, 4)) |
| 2100 | targs[key] = a |
| 2101 | return a |
| 2102 | |
| 2103 | # delayed calls to these targets |
| 2104 | atd = delayed(make_target)("at") |
| 2105 | btd = delayed(make_target)("bt") |
| 2106 | |
| 2107 | # test not keeping result |
| 2108 | st = store([a, b], [atd, btd]) |
| 2109 | |
| 2110 | at = targs["at"] |
| 2111 | bt = targs["bt"] |
| 2112 | |
| 2113 | assert st is None |
| 2114 | assert_eq(at, a) |
| 2115 | assert_eq(bt, b) |
| 2116 | |
| 2117 | # test keeping result |
| 2118 | for st_compute in [False, True]: |
| 2119 | targs.clear() |
| 2120 | st = store([a, b], [atd, btd], return_stored=True, compute=st_compute) |
| 2121 | if st_compute: |
| 2122 | for arr in st: |
| 2123 | assert_has_persisted_data(arr) |
| 2124 | |
| 2125 | st = dask.compute(*st) |
| 2126 | |
| 2127 | at = targs["at"] |
| 2128 | bt = targs["bt"] |
| 2129 | |
| 2130 | assert st is not None |
| 2131 | assert isinstance(st, tuple) |
| 2132 | assert all([isinstance(v, np.ndarray) for v in st]) |
| 2133 | assert_eq(at, a) |
| 2134 | assert_eq(bt, b) |
| 2135 | assert_eq(st[0], a) |
| 2136 | assert_eq(st[1], b) |
| 2137 | |
| 2138 | pytest.raises(ValueError, lambda at=at, bt=bt: store([a], [at, bt])) |
| 2139 | pytest.raises(ValueError, lambda at=at: store(at, at)) |
| 2140 | pytest.raises(ValueError, lambda at=at, bt=bt: store([at, bt], [at, bt])) |
| 2141 | |
| 2142 | |
| 2143 | def test_store(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…