def test_data_file_location_twice(tmp_path):
    c = Cache(tmp_path)
    _ = c.data_file_location('123-456', 'junk1.root')
    p2 = c.data_file_location('123-456', 'junk2.root')
    assert not p2.exists()
    p2.touch()
    assert p2.exists()
def test_data_file_location(tmp_path):
    c = Cache(tmp_path)
    p = c.data_file_location('123-456', 'junk.root')
    assert not p.exists()
    p.touch()
    assert p.exists()
    assert str(p).startswith(str(tmp_path))
def test_ic_nesting(tmp_path):
    c = Cache(tmp_path)
    c.set_query({'hi': 'there'}, 'dude')
    with ignore_cache():
        with ignore_cache():
            pass
        assert c.lookup_query({'hi': 'there'}) is None
def test_query_cache_status(tmp_path):
    c = Cache(tmp_path)

    info = {'request_id': '111-222-333', 'key': 'bogus'}
    c.set_query_status(info)
    info1 = c.lookup_query_status('111-222-333')
    assert info1['key'] == 'bogus'
def test_ic_query_cache_status(tmp_path):
    'Query status should be cached and accessed *during* a query'
    c = Cache(tmp_path)
    info = {'request_id': '111-222-333', 'key': 'bogus'}
    c.set_query_status(info)
    with ignore_cache():
        info1 = c.lookup_query_status('111-222-333')
        assert info1['key'] == 'bogus'
def test_data_file_bad_file(tmp_path):
    c = Cache(tmp_path)
    p = c.data_file_location(
        '123-456',
        'root:::dcache-atlas-xrootd-wan.desy.de:1094::pnfs:desy.de:atlas'
        ':dq2:atlaslocalgroupdisk:rucio:mc15_13TeV:8a:f1:DAOD_STDM3.05630052'
        '._000001.pool.root.198fbd841d0a28cb0d9dfa6340c890273-1.part.minio')
    assert not p.exists()
    p.touch()
    assert p.exists()
def test_data_file_location_long_path(tmp_path):
    c = Cache(tmp_path)
    letters = string.ascii_lowercase
    file_significant_name = 'junk.root'
    long_file_name = ''.join(random.choice(letters) for i in range(230))

    p = c.data_file_location('123-456', long_file_name + file_significant_name)

    assert (len(p.name) == 235 - len(p.parent.name))
    assert p.name.endswith(file_significant_name)
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_1(tmp_path):
    c = Cache(tmp_path)
    c.set_query({'hi': 'there'}, 'dude')
    assert c.lookup_query({'hi': 'there'}) == 'dude'
Esempio n. 10
0
def test_ic_memory_hit_ds_context(tmp_path):
    c = Cache(tmp_path)
    r = 10
    c.set_inmem('dude', r)
    with c.ignore_cache():
        assert c.lookup_inmem('dude') is None
Esempio n. 11
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'
Esempio n. 12
0
def test_ic_memory_hit_ds_level(tmp_path):
    c = Cache(tmp_path, ignore_cache=True)
    r = 10
    c.set_inmem('dude', r)
    assert c.lookup_inmem('dude') is None
Esempio n. 13
0
def test_query_cache_status_bad(tmp_path):
    c = Cache(tmp_path)

    with pytest.raises(ServiceXException):
        c.lookup_query_status('111-222-333')
Esempio n. 14
0
def test_query_miss(tmp_path):
    c = Cache(tmp_path)

    assert c.lookup_query({'hi': 'there'}) is None
Esempio n. 15
0
def test_memory_hit(tmp_path):
    c = Cache(tmp_path)
    r = 10
    c.set_inmem('dude', r)
    assert c.lookup_inmem('dude') is r
Esempio n. 16
0
def test_ic_query_query_context(tmp_path):
    c = Cache(tmp_path)
    c.set_query({'hi': 'there'}, 'dude')
    with c.ignore_cache():
        assert c.lookup_query({'hi': 'there'}) is None
Esempio n. 17
0
def test_memory_hit_accross(tmp_path):
    c1 = Cache(tmp_path)
    r = 10
    c1.set_inmem('dude', r)
    c2 = Cache(tmp_path)
    assert c2.lookup_inmem('dude') is r
Esempio n. 18
0
def test_create_cache(tmp_path):
    _ = Cache(tmp_path)
Esempio n. 19
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
Esempio n. 20
0
def test_memory_miss(tmp_path):
    c = Cache(tmp_path)
    assert c.lookup_inmem('dude') is None