Example #1
0
def test_jug_invalidate():
    def setAi(i):
        A[i] = True
    N = 1024
    A = [False for i in range(N)]
    setall = [Task(setAi, i) for i in range(N)]
    store = dict_store()
    jug.task.Task.store = store
    for t in setall: t.run()

    opts = Options(default_options)
    opts.invalid_name = setall[0].name
    jug.subcommands.invalidate.invalidate(store, opts)
    assert not list(store.store.keys()), list(store.store.keys())
    jug.task.Task.store = dict_store()
Example #2
0
def test_jug_invalidate():
    def setAi(i):
        A[i] = True
    N = 1024
    A = [False for i in range(N)]
    setall = [Task(setAi, i) for i in range(N)]
    store = dict_store()
    jug.task.Task.store = store
    for t in setall: t.run()

    opts = Options(default_options)
    opts.invalid_name = setall[0].name
    jug.jug.invalidate(store, opts)
    assert not list(store.store.keys()), list(store.store.keys())
    jug.task.Task.store = dict_store()
Example #3
0
def test_currymap():
    np.random.seed(33)
    jug.task.Task.store = dict_store()
    A = np.random.rand(100)
    ts = jug.mapreduce.currymap(mapper2, list(zip(A,A)))
    simple_execute()
    assert np.allclose(np.array(value(ts)) , A*2)
Example #4
0
def test_jug_check():
    N = 16
    A = [False for i in range(N)]
    def setAi(i):
        A[i] = True
        return i
    def first_two(one, two):
        return one+two

    setall = [Task(setAi, i) for i in range(N)]
    check = Task(first_two, setall[0], setall[1])
    check2 = Task(first_two, setall[1], setall[2])
    store = dict_store()
    jug.task.Task.store = store
    try:
        jug.jug.check(store, default_options)
    except SystemExit as e:
        assert e.code == 1
    else:
        assert False
    savedtasks = jug.task.alltasks[:]
    simple_execute()
    jug.task.alltasks = savedtasks

    try:
        jug.jug.check(store, default_options)
        assert False
    except SystemExit as e:
        assert e.code == 0
    else:
        assert False
Example #5
0
def test_currymap():
    np.random.seed(33)
    jug.task.Task.store = dict_store()
    A = np.random.rand(100)
    ts = jug.mapreduce.currymap(mapper2, list(zip(A, A)))
    simple_execute()
    assert np.allclose(np.array(value(ts)), A * 2)
Example #6
0
def test_mapreduce():
    np.random.seed(33)
    jug.task.Task.store = dict_store()
    A = np.random.rand(10000)
    t = jug.mapreduce.mapreduce(reducer, mapper, A)
    dfs_run(t)
    assert np.abs(t.result - (A**2).sum()) < 1.
Example #7
0
def test_jug_check():
    N = 16
    A = [False for i in range(N)]
    def setAi(i):
        A[i] = True
        return i
    def first_two(one, two):
        return one+two

    setall = [Task(setAi, i) for i in range(N)]
    check = Task(first_two, setall[0], setall[1])
    check2 = Task(first_two, setall[1], setall[2])
    store = dict_store()
    jug.task.Task.store = store
    e = None
    try:
        jug.jug.check(store, default_options)
    except SystemExit as e:
        pass
    assert e is not None
    assert e.code == 1
    savedtasks = jug.task.alltasks[:]
    simple_execute()
    jug.task.alltasks = savedtasks

    e = None
    try:
        jug.jug.check(store, default_options)
        assert False
    except SystemExit as e:
        pass
    assert e is not None
    assert e.code == 0
Example #8
0
def test_mapreduce():
    np.random.seed(33)
    jug.task.Task.store = dict_store()
    A = np.random.rand(10000)
    t = jug.mapreduce.mapreduce(reducer, mapper, A)
    dfs_run(t)
    assert np.abs(t.result - (A**2).sum()) < 1.
Example #9
0
def test_map():
    np.random.seed(33)
    jug.task.Task.store = dict_store()
    A = np.random.rand(10000)
    ts = jug.mapreduce.map(mapper, A)
    simple_execute()
    ts = value(ts)
    assert np.all(ts == np.array(list(map(mapper,A))))
Example #10
0
def test_map():
    np.random.seed(33)
    jug.task.Task.store = dict_store()
    A = np.random.rand(10000)
    ts = jug.mapreduce.map(mapper, A)
    simple_execute()
    ts = value(ts)
    assert np.all(ts == np.array(list(map(mapper, A))))
Example #11
0
def test_reduce():
    np.random.seed(33)
    jug.task.Task.store = dict_store()
    A = np.random.rand(128)
    A = (A*32).astype(int) # This makes the reduction exactly cummutative (instead of approximately so as with floating point)
    t = jug.mapreduce.reduce(reducer, A)
    dfs_run(t)
    assert t.value() == reduce(reducer,A)
Example #12
0
def test_map():
    np.random.seed(33)
    jug.task.Task.store = dict_store()
    A = np.random.rand(10000)
    t = jug.mapreduce.map(mapper, A)
    dfs_run(t)
    ts = value(t)
    assert np.all(ts == np.array(map(mapper,A)))
Example #13
0
def test_reduce():
    np.random.seed(33)
    jug.task.Task.store = dict_store()
    A = np.random.rand(128)
    A = (A*32).astype(int) # This makes the reduction exactly cummutative (instead of approximately so as with floating point)
    t = jug.mapreduce.reduce(reducer, A)
    dfs_run(t)
    assert t.value() == reduce(reducer,A)
Example #14
0
def test_compound():
    jug.task.Task.store = dict_store()
    A = np.random.rand(10000)
    x = CompoundTask(jug.mapreduce.mapreduce,reducer, mapper, A)
    dfs_run(x)
    y = CompoundTask(jug.mapreduce.mapreduce,reducer, mapper, A)

    assert y.can_load()
    assert y.result == x.result
Example #15
0
def task_reset_at_exit():
    jug.task.Task.store = dict_store()
    while jug.task.alltasks:
        jug.task.alltasks.pop()

    yield

    jug.task.Task.store = None
    while jug.task.alltasks:
        jug.task.alltasks.pop()
    reset_all_hooks()
Example #16
0
def test_jug_execute_simple():
    N = 1024
    random.seed(232)
    A = [False for i in range(N)]
    def setAi(i):
        A[i] = True
    setall = [Task(setAi, i) for i in range(N)]
    store = dict_store()
    jug.task.Task.store = store
    simple_execute()
    assert False not in A
    assert max(store.counts.values()) < 4
Example #17
0
def test_jug_execute_simple():
    N = 1024
    random.seed(232)
    A = [False for i in range(N)]
    def setAi(i):
        A[i] = True
    setall = [Task(setAi, i) for i in range(N)]
    store = dict_store()
    jug.task.Task.store = store
    simple_execute()
    assert False not in A
    assert max(store.counts.values()) < 4
Example #18
0
def test_util_timed_path():
    Task = jug.task.Task
    jug.task.Task.store = dict_store()
    system("touch test_file")
    t0 = jug.utils.timed_path('test_file')
    t1 = jug.utils.timed_path('test_file')
    assert t0.hash() == t1.hash()
    sleep(1.1)
    system("touch test_file")
    t1 = jug.utils.timed_path('test_file')
    assert t0.hash() != t1.hash()
    assert t0.run() == 'test_file'
    assert t1.run() == 'test_file'
Example #19
0
def test_util_timed_path():
    Task = jug.task.Task
    jug.task.Task.store = dict_store()
    system("touch test_file")
    t0 = jug.utils.timed_path('test_file')
    t1 = jug.utils.timed_path('test_file')
    assert t0.hash() == t1.hash()
    sleep(1.1)
    system("touch test_file")
    t1 = jug.utils.timed_path('test_file')
    assert t0.hash() != t1.hash()
    assert t0.run() == 'test_file'
    assert t1.run() == 'test_file'
Example #20
0
def test_util_timed_path():
    from jug.hash import hash_one
    jug.task.Task.store = dict_store()
    system("touch test_file")
    t0 = jug.utils.timed_path('test_file')
    t1 = jug.utils.timed_path('test_file')
    h0 = hash_one(t0)
    h1 = hash_one(t1)
    assert h0 == h1
    sleep(1.1)
    system("touch test_file")
    h1 = hash_one(t1)
    assert h0 != h1
    assert value(t0) == 'test_file'
    assert value(t1) == 'test_file'
Example #21
0
def test_util_timed_path():
    from jug.hash import hash_one
    jug.task.Task.store = dict_store()
    system("touch test_file")
    t0 = jug.utils.timed_path('test_file')
    t1 = jug.utils.timed_path('test_file')
    h0 = hash_one(t0)
    h1 = hash_one(t1)
    assert h0 == h1
    sleep(1.1)
    system("touch test_file")
    h1 = hash_one(t1)
    assert h0 != h1
    assert value(t0) == 'test_file'
    assert value(t1) == 'test_file'
Example #22
0
def test_jug_execute_deps():
    N = 256
    random.seed(234)
    A = [False for i in range(N)]
    def setAi(i, other):
        A[i] = True
    idxs = list(range(N))
    random.shuffle(idxs)
    prev = None
    for idx in idxs:
        prev = Task(setAi, idx, prev)
    store = dict_store()
    jug.task.Task.store = store
    simple_execute()
    assert False not in A
    assert max(store.counts.values()) < 5
Example #23
0
def test_jug_execute_deps():
    N = 256
    random.seed(234)
    A = [False for i in range(N)]
    def setAi(i, other):
        A[i] = True
    idxs = list(range(N))
    random.shuffle(idxs)
    prev = None
    for idx in idxs:
        prev = Task(setAi, idx, prev)
    store = dict_store()
    jug.task.Task.store = store
    simple_execute()
    assert False not in A
    assert max(store.counts.values()) < 5
Example #24
0
def test_util_timed_path(tmpdir):
    from jug.hash import hash_one
    jug.task.Task.store = dict_store()
    tmpdir = str(tmpdir)
    test_file = path.join(tmpdir, 'test_file')
    with open(test_file, 'wt') as out:
        out.write("Hello World")
    t0 = jug.utils.timed_path(test_file)
    t1 = jug.utils.timed_path(test_file)
    h0 = hash_one(t0)
    h1 = hash_one(t1)
    assert h0 == h1
    sleep(1.1)
    with open(test_file, 'wt') as out:
        out.write("Hello World")
    h1 = hash_one(t1)
    assert h0 != h1
    assert value(t0) == test_file
    assert value(t1) == test_file
Example #25
0
def test_jug_check():
    N = 16
    A = [False for i in xrange(N)]
    def setAi(i):
        A[i] = True
        return i
    def first_two(one, two):
        return one+two

    setall = [Task(setAi, i) for i in xrange(N)]
    check = Task(first_two, setall[0], setall[1])
    check2 = Task(first_two, setall[1], setall[2])
    store = dict_store()
    jug.task.Task.store = store
    e = None
    try:
        jug.jug.check(store, default_options)
    except SystemExit, e:
        pass
Example #26
0
def test_lock_bytes2():
    store = dict_store()
    lock = store.getlock('foo')
    lock2 = store.getlock(b'foo')
    lock.get()
    assert lock2.is_locked()
Example #27
0
def _setup():
    jug.task.Task.store = dict_store()
Example #28
0
import inspect
import os

from nose.tools import with_setup
import jug.task
from jug.backends.dict_store import dict_store
from jug.tests.task_reset import task_reset
from jug.tests.utils import simple_execute


_jugdir = os.path.abspath(inspect.getfile(inspect.currentframe()))
_jugdir = os.path.join(os.path.dirname(_jugdir), 'jugfiles')


Task = jug.task.Task
jug.task.Task.store = dict_store()
def _setup():
    jug.task.Task.store = dict_store()

def _teardown():
    jug.task.alltasks = []

task_reset = with_setup(_setup, _teardown)

def add1(x):
    return x + 1
def add2(x):
    return x + 2

def _assert_tsorted(tasks):
    from itertools import chain
Example #29
0
def test_lock_bytes2():
    store = dict_store()
    lock = store.getlock('foo')
    lock2 = store.getlock(b'foo')
    lock.get()
    assert lock2.is_locked()
Example #30
0
def _setup():
    jug.task.Task.store = dict_store()
    while jug.task.alltasks:
        jug.task.alltasks.pop()
Example #31
0
def _setup():
    jug.task.Task.store = dict_store()
    while jug.task.alltasks:
        jug.task.alltasks.pop()