def test_column_cache_disabled(df): orca.add_injectable('x', 2) series = pd.Series([1, 2, 3], index=['x', 'y', 'z']) key = ('table', 'col') @orca.table() def table(): return df @orca.column(*key, cache=True) def column(x): return series * x def c(): return orca._COLUMNS[key] orca.disable_cache() pdt.assert_series_equal(c()(), series * 2) orca.add_injectable('x', 3) pdt.assert_series_equal(c()(), series * 3) orca.enable_cache() orca.add_injectable('x', 4) pdt.assert_series_equal(c()(), series * 3)
def test_table_func_cache_disabled(df): orca.add_injectable('x', 2) @orca.table('table', cache=True) def asdf(x): return df * x orca.disable_cache() pdt.assert_frame_equal(orca.get_table('table').to_frame(), df * 2) orca.add_injectable('x', 3) pdt.assert_frame_equal(orca.get_table('table').to_frame(), df * 3) orca.enable_cache() orca.add_injectable('x', 4) pdt.assert_frame_equal(orca.get_table('table').to_frame(), df * 3)
def test_memoized_injectable_cache_off(): outside = 'x' @orca.injectable(autocall=False, memoize=True) def x(s): return outside + s def getx(): return orca.get_injectable('x')('y') orca.disable_cache() assert getx() == 'xy' outside = 'z' assert getx() == 'zy' orca.enable_cache() outside = 'a' assert getx() == 'zy' orca.disable_cache() assert getx() == 'ay'
def test_injectables_cache_disabled(): x = 2 @orca.injectable(autocall=True, cache=True) def inj(): return x * x def i(): return orca._INJECTABLES['inj'] orca.disable_cache() assert i()() == 4 x = 3 assert i()() == 9 orca.enable_cache() assert i()() == 9 x = 4 assert i()() == 9 orca.disable_cache() assert i()() == 16
def teardown_function(func): orca.clear_all() orca.enable_cache() # be nice to the others tests that expect decorated injectables to be there inject.reinject_decorated_tables()
def setup_function(func): orca.clear_all() orca.enable_cache()