Ejemplo n.º 1
0
def test_get_modified():
    test_obj = MPCache(1)
    modified_time = time.time()
    test_obj.refresh("some_key", 43, modified_time)
    assert test_obj.get_modified("some_key") == modified_time
    test_obj.write("some_key", 42)
    assert test_obj.get_modified("some_key") <= time.time()
Ejemplo n.º 2
0
def test_get_keys():
    test_obj = MPCache(1)
    test_obj.refresh("some_key", 43, time.time())
    test_obj.write("some_other_key", 42)
    assert "some_key" in test_obj.get_keys()
    assert "some_other_key" in test_obj.get_keys()
    assert not "some_keyXYZ" in test_obj.get_keys()
Ejemplo n.º 3
0
def test_get_size_of_cached_data():
    test_obj = MPCache(1)
    modified_time = time.time()
    assert test_obj.get_size_of_cached_data() == 0
    test_obj.refresh("some_key", "abcd", modified_time)
    assert test_obj.get_size_of_cached_data() == sys.getsizeof("abcd")
    test_obj.write("some_other_key", 42)
    assert test_obj.get_size_of_cached_data() == sys.getsizeof(42)+sys.getsizeof("abcd")
    test_obj.write("some_other_key", 52)
    assert test_obj.get_size_of_cached_data() == sys.getsizeof(52)+sys.getsizeof("abcd")
    test_obj.refresh("some_key", "abcd", modified_time)
    assert test_obj.get_size_of_cached_data() == sys.getsizeof(52)+sys.getsizeof("abcd")
Ejemplo n.º 4
0
def test_get_size_of_dirty_data():
    test_obj = MPCache(1)
    assert test_obj.get_size_of_dirty_data() == 0
    test_obj.refresh("some_key", "abcd",  time.time())
    assert test_obj.get_size_of_dirty_data() == 0
    test_obj.write("some_other_key", 42)
    assert test_obj.get_size_of_dirty_data() == sys.getsizeof(42)
    test_obj.write("some_other_key", 52)
    assert test_obj.get_size_of_dirty_data() == sys.getsizeof(52)
    test_obj.write("some_key", "abcd")
    assert test_obj.get_size_of_dirty_data() == sys.getsizeof(52)+sys.getsizeof("abcd")
    test_obj.refresh("some_other_key", 42, time.time())
    assert test_obj.get_size_of_dirty_data() == sys.getsizeof("abcd")
Ejemplo n.º 5
0
def test_refresh():
    test_obj = MPCache(1)
    test_obj.refresh("some_key", 43, time.time())
    test_obj.refresh("some_key",42, time.time())
    assert test_obj.get_value("some_key") == 42
    test_obj.refresh("some_key",43, time.time()-1000)
    assert test_obj.get_value("some_key") == 42, "Refresh should not have worked since the modified time of the 'disk' entry is older than the cache entry."
    assert not test_obj.is_dirty("some_key")
Ejemplo n.º 6
0
def test_get_value():
    test_obj = MPCache(1)
    test_obj.refresh("some_key", 43, time.time())
    assert test_obj.get_value("some_key") == 43
    test_obj.write("some_key", 42)
    assert test_obj.get_value("some_key") == 42
Ejemplo n.º 7
0
def test_is_dirty():
    test_obj = MPCache(1)
    test_obj.refresh("some_key", 43, time.time())
    assert not test_obj.is_dirty("some_key")
    test_obj.write("some_key", 42)
    assert test_obj.is_dirty("some_key")