def test_ic_enter_exit(tmp_path):
    c = Cache(tmp_path)
    c.set_query({'hi': 'there'}, 'dude')
    i = ignore_cache()
    i.__enter__()
    assert c.lookup_query({'hi': 'there'}) is None
    i.__exit__(None, None, None)
    assert c.lookup_query({'hi': 'there'}) == 'dude'
def test_query_hit_analysis_lookup_writes(tmp_path: Path):
    'make sure analysis query cache is written to'
    cache_loc_1 = tmp_path / 'cache1'
    cache_loc_2 = tmp_path / 'cache2'

    c1 = Cache(cache_loc_1)
    c1.set_query({'hi': 'there'}, 'dude')
    update_local_query_cache(tmp_path / 'analysis_cache.json')
    assert c1.lookup_query({'hi': 'there'}) == 'dude'

    c2 = Cache(cache_loc_2)
    assert c2.lookup_query({'hi': 'there'}) == 'dude'
def test_query_hit_analysis_cache_update(tmp_path: Path):
    'Make sure the analysis cache is updated'
    cache_loc_1 = tmp_path / 'cache1'
    cache_loc_2 = tmp_path / 'cache2'

    update_local_query_cache(tmp_path / 'analysis_cache.json')

    c1 = Cache(cache_loc_1)
    c1.set_query({'hi': 'there'}, 'dude')
    c1.set_query({'hi1': 'there1'}, 'dude1')

    c2 = Cache(cache_loc_2)
    assert c2.lookup_query({'hi': 'there'}) == 'dude'
    assert c2.lookup_query({'hi1': 'there1'}) == 'dude1'
def test_ic_nesting_ds_context(tmp_path):
    c = Cache(tmp_path)
    c.set_query({'hi': 'there'}, 'dude')
    with c.ignore_cache():
        with c.ignore_cache():
            pass
        assert c.lookup_query({'hi': 'there'}) is None
def test_query_hit_analysis_cache_not_triggered(tmp_path: Path):
    'Make sure analysis cache is not written by default'
    cache_loc_1 = tmp_path / 'cache1'
    cache_loc_2 = tmp_path / 'cache2'

    c1 = Cache(cache_loc_1)
    c1.set_query({'hi': 'there'}, 'dude')

    c2 = Cache(cache_loc_2)
    assert c2.lookup_query({'hi': 'there'}) is None
def test_query_hit_analysis_cache_removed_query_noupdate(tmp_path: Path):
    'Make sure to forget a query when we are not updating the analysis cache'
    cache_loc_1 = tmp_path / 'cache1'
    cache_loc_2 = tmp_path / 'cache2'
    cache_loc_3 = tmp_path / 'cache3'

    update_local_query_cache()

    c1 = Cache(cache_loc_1)
    c1.set_query({'hi': 'there'}, 'dude')

    reset_local_query_cache()

    c2 = Cache(cache_loc_2)
    c2.remove_query({'hi': 'there'})
    assert c2.lookup_query({'hi': 'there'}) is None

    reset_local_query_cache()

    # Make sure that the json file wasn't modified in this case!
    c3 = Cache(cache_loc_3)
    assert c3.lookup_query({'hi': 'there'}) == 'dude'
def test_query_hit_analysis_cache_silent_read(tmp_path: Path):
    'Make sure we read the analysis cache if it happens to be present'
    cache_loc_1 = tmp_path / 'cache1'
    cache_loc_2 = tmp_path / 'cache2'

    update_local_query_cache()

    c1 = Cache(cache_loc_1)
    c1.set_query({'hi': 'there'}, 'dude')

    reset_local_query_cache()

    c2 = Cache(cache_loc_2)
    assert c2.lookup_query({'hi': 'there'}) == 'dude'
def test_query_hit_analysis_cache_removed_query_update(tmp_path: Path):
    'If we are updating the query cache, make sure to remove an item'
    cache_loc_1 = tmp_path / 'cache1'
    cache_loc_2 = tmp_path / 'cache2'

    update_local_query_cache()

    c1 = Cache(cache_loc_1)
    c1.set_query({'hi': 'there'}, 'dude')
    c1.remove_query({'hi': 'there'})

    reset_local_query_cache()

    c2 = Cache(cache_loc_2)
    assert c2.lookup_query({'hi': 'there'}) is None
def test_query_hit_1(tmp_path):
    c = Cache(tmp_path)
    c.set_query({'hi': 'there'}, 'dude')
    assert c.lookup_query({'hi': 'there'}) == 'dude'
Beispiel #10
0
def test_ic_restore(tmp_path):
    c = Cache(tmp_path)
    c.set_query({'hi': 'there'}, 'dude')
    with ignore_cache():
        pass
    assert c.lookup_query({'hi': 'there'}) == 'dude'
Beispiel #11
0
def test_query_miss(tmp_path):
    c = Cache(tmp_path)

    assert c.lookup_query({'hi': 'there'}) is None
Beispiel #12
0
def test_query_remove(tmp_path):
    c1 = Cache(tmp_path)
    c1.set_query({'hi': 'there'}, 'dude')
    c1.remove_query({'hi': 'there'})
    assert c1.lookup_query({'hi': 'there'}) is None
Beispiel #13
0
def test_query_lookup_from_file(tmp_path):
    c1 = Cache(tmp_path)
    c1.set_query({'hi': 'there'}, 'dude')

    c2 = Cache(tmp_path)
    assert c2.lookup_query({'hi': 'there'}) == 'dude'
Beispiel #14
0
def test_query_hit_2(tmp_path):
    c = Cache(tmp_path)
    c.set_query({'hi': 'there'}, 'dude1')
    c.set_query({'hi': 'there_1'}, 'dude2')
    assert c.lookup_query({'hi': 'there'}) == 'dude1'
    assert c.lookup_query({'hi': 'there_1'}) == 'dude2'
Beispiel #15
0
def test_ic_query_ds_level(tmp_path):
    c = Cache(tmp_path, ignore_cache=True)
    c.set_query({'hi': 'there'}, 'dude')
    assert c.lookup_query({'hi': 'there'}) is None
Beispiel #16
0
def test_ic_query(tmp_path):
    c = Cache(tmp_path)
    c.set_query({'hi': 'there'}, 'dude')
    with ignore_cache():
        assert c.lookup_query({'hi': 'there'}) is None