Esempio n. 1
0
def test_get_unique_key():
    keep = KeepThis('localhost', 11211)
    keep.drop()

    @keep.this
    def some_func(arg1, arg2, kwarg1=1, kwarg2=2):
        return arg1 + arg2 + kwarg1 + kwarg2

    a = some_func(1, 2, kwarg1=-1, kwarg2=-2)
    b = some_func(1, 2, kwarg1=-1, kwarg2=-2)
    assert a == b
import time

from keepthis import KeepThis

# provide connection parameters to memcached
# DO NOT PROVIDE PRODUCTION PARAMETERS! WE WILL FLUSH RESULT in the end! =)
keep = KeepThis('localhost', 11211)


@keep.this
def some_long_calculations(arg1, arg2, kwarg=100):
    """Implement some long to wait calculations"""
    time.sleep(3)
    return arg1 + arg2 + kwarg


if __name__ == '__main__':
    # do some calculations by your self
    print("Okay, it's time to work! Let's run my calculations!")
    time_start = time.time()
    result = some_long_calculations(1, 2, kwarg=40)
    print("My result: {}\nTime spent: {}".format(result, time.time() - time_start))

    print("Share same code with your teammate, and you will be inspired that he will reproduce results much faster!")
    time_start = time.time()
    result = some_long_calculations(1, 2, kwarg=40)
    print("Teammate got result: {}\nTime spent: {}".format(result, time.time() - time_start))

    # clear cacje
    keep.drop()
Esempio n. 3
0
def test_hash_ndarray():
    array = np.array([1, 2, 3, 4], np.int64)
    result_hash = KeepThis._hash_ndarray(array)
    assert isinstance(result_hash, str)
    assert result_hash == '46c4f0c1fb94a6327fafea6bb1ddf0dd4ddb09f77142e1afae176f96'
Esempio n. 4
0
def test_hash_index():
    df = pd.Index([1, 2, 3, 4])
    hash_result = KeepThis._hash_pandas(df)
    assert isinstance(hash_result, str)
    assert hash_result == '8c3496da2b4c2ce381069335b16e9a249c876c33f9729e8ba9abbd81'
Esempio n. 5
0
def test_hash_series():
    df = pd.Series([1, 2, 3, 4])
    hash_result = KeepThis._hash_pandas(df)
    assert isinstance(hash_result, str)
    assert hash_result == 'bf0f9ed39a15ccb47b3369d31fedc155c571da52f47a311fcff06cc7'
Esempio n. 6
0
def test_hash_dataframe():
    df = pd.DataFrame({'a': [1, 2, 3, 4], 'b': [5, 6, 7, 8]})
    hash_result = KeepThis._hash_pandas(df)
    assert isinstance(hash_result, str)
    assert hash_result == '41c84b3afe4f6affd02cc4c31030e433a6e9d5b52747f3d7c7e605fb'
Esempio n. 7
0
def test_hash_string():
    assert KeepThis._hash_string(
        'asd') == 'cda1d665441ef8120c3d3e82610e74ab0d3b043763784676654d8ef1'