def test_get_laziness(): def isconcrete(arg): return isinstance(arg, list) d = {'x': 1, 'y': 2, 'z': (isconcrete, ['x', 'y'])} assert get(d, ['x', 'y']) == [1, 2] assert get(d, 'z') == False
def test_get_stack_limit(): d = dict(('x%s' % (i+1), (inc, 'x%s' % i)) for i in range(10000)) d['x0'] = 0 assert get(d, 'x10000') == 10000 # introduce cycle d['x5000'] = (inc, 'x5001') assert raises(RuntimeError, lambda: get(d, 'x10000')) assert get(d, 'x4999') == 4999
def test_get_stack_limit(): d = dict(('x%s' % (i + 1), (inc, 'x%s' % i)) for i in range(10000)) d['x0'] = 0 assert get(d, 'x10000') == 10000 # introduce cycle d['x5000'] = (inc, 'x5001') assert raises(RuntimeError, lambda: get(d, 'x10000')) assert get(d, 'x4999') == 4999
def test_insert_to_ooc(): x = np.arange(600).reshape((20, 30)) y = np.empty(shape=x.shape, dtype=x.dtype) a = convert(Array, x, blockshape=(4, 5)) dsk = insert_to_ooc(y, a) core.get(merge(dsk, a.dask), list(dsk.keys())) assert eq(y, x)
def test_insert_to_ooc(): x = np.arange(600).reshape((20, 30)) y = np.empty(shape=x.shape, dtype=x.dtype) a = convert(Array, x, chunks=(4, 5)) dsk = insert_to_ooc(y, a) core.get(merge(dsk, a.dask), list(dsk.keys())) assert eq(y, x)
def test_quote(): literals = [[1, 2, 3], (add, 1, 2), [1, [2, 3]], (add, 1, (add, 2, 3)), { "x": "x" }] for l in literals: assert core.get({"x": quote(l)}, "x") == l
def test_get_with_nested_list(): d = {'x': 1, 'y': 2, 'z': (sum, ['x', 'y'])} assert get(d, [['x'], 'y']) == [[1], 2] assert get(d, 'z') == 3
def test_get_with_list(): d = {'x': 1, 'y': 2, 'z': (sum, ['x', 'y'])} assert get(d, ['x', 'y']) == [1, 2] assert get(d, 'z') == 3
def test_data_not_in_dict_is_ok(): d = {'x': 1, 'y': (add, 'x', 10)} assert get(d, 'y') == 11
def test_get(): assert get(d, ':x') == 1 assert get(d, ':y') == 2 assert get(d, ':z') == 3 assert get(d, 'pass-through') == 'pass-through'
def test_quote(): literals = [[1, 2, 3], (add, 1, 2), [1, [2, 3]], (add, 1, (add, 2, 3))] for l in literals: assert get({'x': quote(l)}, 'x') == l
def test_nested_tasks(): d = {'x': 1, 'y': (inc, 'x'), 'z': (add, (inc, 'x'), 'y')} assert get(d, 'z') == 4
def test_quote(): literals = [[1, 2, 3], (add, 1, 2), [1, [2, 3]], (add, 1, (add, 2, 3))] for l in literals: assert core.get({'x': quote(l)}, 'x') == l
class TestRecursiveGet(GetFunctionTestMixin): get = staticmethod(lambda d, k: core.get(d, k, recursive=True)) def test_get_stack_limit(self): # will blow stack in recursive mode pass
def test_get_works_with_unhashables_in_values(): f = lambda x, y: x + len(y) d = {'x': 1, 'y': (f, 'x', set([1]))} assert get(d, 'y') == 2
def __call__(self, *args): if not len(args) == len(self.inkeys): raise ValueError("Expected %d args, got %d" % (len(self.inkeys), len(args))) return core.get(self.dsk, self.outkey, dict(zip(self.inkeys, args)))