Beispiel #1
0
def test_clear_cache_all(df):
    @orca.table(cache=True)
    def table():
        return df

    @orca.column('table', cache=True)
    def z(table):
        return df.a

    @orca.injectable(cache=True)
    def x():
        return 'x'

    @orca.injectable(autocall=False, memoize=True)
    def y(s):
        return s + 'y'

    orca.eval_variable('table.z')
    orca.eval_variable('x')
    orca.get_injectable('y')('x')

    assert list(orca._TABLE_CACHE.keys()) == ['table']
    assert list(orca._COLUMN_CACHE.keys()) == [('table', 'z')]
    assert list(orca._INJECTABLE_CACHE.keys()) == ['x']
    assert orca._MEMOIZED['y'].value.cache == {(('x',), None): 'xy'}

    orca.clear_cache()

    assert orca._TABLE_CACHE == {}
    assert orca._COLUMN_CACHE == {}
    assert orca._INJECTABLE_CACHE == {}
    assert orca._MEMOIZED['y'].value.cache == {}
Beispiel #2
0
def test_cache_disabled_cm():
    x = 3

    @orca.injectable(cache=True)
    def xi():
        return x

    assert orca.get_injectable('xi') == 3
    x = 5
    assert orca.get_injectable('xi') == 3

    with orca.cache_disabled():
        assert orca.get_injectable('xi') == 5

    # cache still gets updated even when cacheing is off
    assert orca.get_injectable('xi') == 5
Beispiel #3
0
def test_injectables():
    orca.add_injectable('answer', 42)

    @orca.injectable()
    def func1(answer):
        return answer * 2

    @orca.injectable('func2', autocall=False)
    def asdf(variable='x'):
        return variable / 2

    @orca.injectable()
    def func3(func2):
        return func2(4)

    @orca.injectable()
    def func4(func='func1'):
        return func / 2

    assert orca._INJECTABLES['answer'] == 42
    assert orca._INJECTABLES['func1']() == 42 * 2
    assert orca._INJECTABLES['func2'](4) == 2
    assert orca._INJECTABLES['func3']() == 2
    assert orca._INJECTABLES['func4']() == 42

    assert orca.get_injectable('answer') == 42
    assert orca.get_injectable('func1') == 42 * 2
    assert orca.get_injectable('func2')(4) == 2
    assert orca.get_injectable('func3') == 2
    assert orca.get_injectable('func4') == 42

    with pytest.raises(KeyError):
        orca.get_injectable('asdf')

    assert set(orca.list_injectables()) == \
        {'answer', 'func1', 'func2', 'func3', 'func4'}
Beispiel #4
0
 def getx():
     return orca.get_injectable('x')('y')