-
Notifications
You must be signed in to change notification settings - Fork 33
/
test_rucio.py
78 lines (70 loc) · 3.17 KB
/
test_rucio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import straxen
import unittest
import strax
import socket
class TestBasics(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
"""
For testing purposes, slightly alter the RucioFrontend such that
we can run tests outside of dali too
"""
if not straxen.utilix_is_configured():
return
if 'rcc' not in socket.getfqdn():
# If we are not on RCC, for testing, add some dummy site
straxen.RucioFrontend.local_rses = {'UC_DALI_USERDISK': r'.rcc.',
'test_rucio': f'{socket.getfqdn()}'}
straxen.RucioFrontend.get_rse_prefix = lambda *x: 'test_rucio'
# Some non-existing keys that we will try finding in the test cases.
cls.test_keys = [
strax.DataKey(run_id=run_id,
data_type='dtype',
lineage={'dtype': ['Plugin', '0.0.0.', {}], }
)
for run_id in ('-1', '-2')
]
@unittest.skipIf(not straxen.utilix_is_configured(), "No db access, cannot test!")
def test_load_context_defaults(self):
"""Don't fail immediately if we start a context due to Rucio"""
st = straxen.contexts.xenonnt_online(_minimum_run_number=10_000,
_maximum_run_number=10_010,
)
st.select_runs()
@unittest.skipIf(not straxen.utilix_is_configured(), "No db access, cannot test!")
def test_find_local(self):
"""Make sure that we don't find the non existing data"""
rucio = straxen.RucioFrontend(include_remote=False,)
self.assertRaises(strax.DataNotAvailable,
rucio.find,
self.test_keys[0]
)
@unittest.skipIf(not straxen.utilix_is_configured(), "No db access, cannot test!")
def test_find_several_local(self):
"""Let's try finding some keys (won't be available)"""
rucio = straxen.RucioFrontend(include_remote=False,)
print(rucio)
found = rucio.find_several(self.test_keys)
# We shouldn't find any of these
assert found == [False for _ in self.test_keys]
@unittest.skipIf(not straxen.utilix_is_configured(), "No db access, cannot test!")
def test_find_several_remote(self):
"""
Let's try running a find_several with the include remote.
This should fail but when no rucio is installed or else it
shouldn't find any data.
"""
try:
rucio = straxen.RucioFrontend(include_remote=True,)
except ImportError:
pass
else:
found = rucio.find_several(self.test_keys)
# We shouldn't find any of these
assert found == [False for _ in self.test_keys]
@unittest.skipIf(not straxen.utilix_is_configured(), "No db access, cannot test!")
def test_find_local(self):
"""Make sure that we don't find the non existing data"""
run_db = straxen.RunDB(rucio_path='./rucio_test')
with self.assertRaises(strax.DataNotAvailable):
run_db.find(self.test_keys[0])