def test_compute_path():
    path = Cache.compute_path(cached_function, 10, y=100)

    assert not os.path.exists(path)   

    cached_function(10, y=100)

    assert os.path.exists(path)  
def test_embedding_xz():
    standard_test_dataframes(
        Cache(
            cache_path="{cache_dir}/{_hash}.embedding.xz",
            cache_dir="./test_cache",
            backup=False,
        )(cached_function))
    if os.path.exists("./test_cache"):
        rmtree("./test_cache")
Esempio n. 3
0
def test_get_params():
    c = Cache()

    c.function_info = c._compute_function_info(bad_function)

    assert get_params(c.function_info, (1, 2, 3), {
        "k": 4,
        "b": 5
    }) == {
        'z': 3,
        'y': 2,
        'k': 4,
        'b': 5,
        'x': 1
    }
    assert get_params(c.function_info, (1, ), {
        "k": 4,
        "b": 5
    }) == {
        'z': 2,
        'y': 1,
        'k': 4,
        'b': 5,
        'x': 1
    }
    assert get_params(c.function_info, (1, ), {"k": 4}) == {
        'z': 2,
        'y': 1,
        'k': 4,
        'b': 6,
        'x': 1
    }
    assert get_params(c.function_info, (1, ), {}) == {
        'z': 2,
        'y': 1,
        'k': 5,
        'b': 6,
        'x': 1
    }
def test_load_store():
    test_obj = {
        "c": "aaaaa",
        "f": 2123123,
    }
    Cache.store(test_obj, "./test_cache/test_load_store.json")

    assert test_obj == Cache.load("./test_cache/test_load_store.json")

    Cache.store(test_obj, "./test_cache/test_load_store.pkl")

    assert test_obj == Cache.load("./test_cache/test_load_store.pkl")

    if os.path.exists("./test_cache"):
        rmtree("./test_cache")