Exemple #1
0
def setup_module(module):
    global smache, score, h, f, with_raw
    DummyA.unsubscribe_all()
    DummyB.unsubscribe_all()
    DummyC.unsubscribe_all()

    smache = Smache(scheduler=InProcessScheduler(),
                    write_through=False)

    @smache.sources(DummyB, DummyC)
    @smache.computed(DummyA)
    def score(a):
        return a.value + 5 + 10

    @smache.computed(DummyB, DummyC)
    def h(b, c):
        return b.value + c.value

    @smache.computed(DummyA, DummyB, DummyC)
    def f(a, b, c):
        return a.value * h(b, c)

    @smache.computed(DummyA, DummyB, Raw)
    def with_raw(a, b, static_value):
        return (a.value + b.value) * static_value
Exemple #2
0
def test_computed_function_are_updated_when_relations_are():
    ax = DummyA('1', 10)
    ax2 = DummyA('2', 500)
    cx = DummyC('20', 500)
    cx2 = DummyC('30', 500)

    assert f(ax, cx, 5, 10) == 200
    assert f(ax2, cx2, 5, 10) == 10000

    DummyC.update('30', {'value': 30})

    assert smache.is_fun_fresh(f, ax, cx, 5, 10) == True
    assert smache.is_fun_fresh(f, ax2, cx2, 5, 10) == False
Exemple #3
0
def test_cache():
    ax = DummyA(1, 10)
    bx = DummyB(2, 2)
    cx = DummyC(3, 3)

    assert f(ax, bx, cx) == 50
    assert h(bx, cx) == 5
    assert score(ax)

    assert smache.is_fun_fresh(score, ax) == True
    assert smache.is_fun_fresh(f, ax, bx, cx) == True
    assert smache.is_fun_fresh(h, bx, cx) == True

    DummyB.update(0, {})

    assert smache.is_fun_fresh(score, ax) == False
    assert smache.is_fun_fresh(f, ax, bx, cx) == True
    assert smache.is_fun_fresh(h, bx, cx) == True

    DummyA.update(1, {})

    assert smache.is_fun_fresh(score, ax) == False
    assert smache.is_fun_fresh(f, ax, bx, cx) == False
    assert smache.is_fun_fresh(h, bx, cx) == True

    DummyB.update(2, {})

    assert smache.is_fun_fresh(score, ax) == False
    assert smache.is_fun_fresh(f, ax, bx, cx) == False
    assert smache.is_fun_fresh(h, bx, cx) == False
Exemple #4
0
def setup_module(module):
    global smache, f, h

    DummyA.unsubscribe_all()
    DummyB.unsubscribe_all()
    DummyC.unsubscribe_all()

    smache = Smache(scheduler=InProcessScheduler(), write_through=False)

    @smache.relations((DummyB, lambda b: DummyC.find('30')))
    @smache.computed(DummyA, DummyC, Raw, Raw)
    def f(a, dummyc, c, d):
        b = DummyB.find('2')
        return a.value * b.value

    @smache.relations((DummyB, lambda b: [DummyA.find('1'), DummyA.find('2')]))
    @smache.computed(DummyA, Raw, Raw)
    def h(a, c, d):
        b = DummyB.find('2')
        return a.value * b.value
Exemple #5
0
def setup_module(module):
    global smache, score, h, f, with_raw
    DummyA.unsubscribe_all()
    DummyB.unsubscribe_all()
    DummyC.unsubscribe_all()

    smache = Smache(scheduler=InProcessScheduler(), write_through=False)

    @smache.sources(DummyB, DummyC)
    @smache.computed(DummyA)
    def score(a):
        return a.value + 5 + 10

    @smache.computed(DummyB, DummyC)
    def h(b, c):
        return b.value + c.value

    @smache.computed(DummyA, DummyB, DummyC)
    def f(a, b, c):
        return a.value * h(b, c)

    @smache.computed(DummyA, DummyB, Raw)
    def with_raw(a, b, static_value):
        return (a.value + b.value) * static_value
Exemple #6
0
def teardown_module(module):
    DummyA.unsubscribe_all()
    DummyB.unsubscribe_all()
    DummyC.unsubscribe_all()
Exemple #7
0
def teardown_module(module):
    DummyA.unsubscribe_all()
    DummyB.unsubscribe_all()
    DummyC.unsubscribe_all()
Exemple #8
0
def flush_before_each_test_case():
    redis_con.flushall()
    DummyA.set_data({'1': {'value': 10}, '2': {'value': 500}})
    DummyB.set_data({'2': {'value': 20}})
    DummyC.set_data({'20': {'value': -1}, '30': {'value': -2}})
    yield