Belle II Software development
test_b2conditionsdb_commands.py
1
8
9'''
10Test for checking:
11 - b2conditionsdb iov
12 - b2conditionsdb iov --run-range
13 - b2conditionsdb diff
14 - b2conditionsdb diff --run-range
15 - b2conditionsdb legacydownload --run-range
16 - b2conditionsdb iovs delete --run-range
17 - b2conditionsdb iovs delete --run-range --fully-contained
18 - b2conditionsdb iovs copy --replace
19'''
20
21
22import subprocess
23import shlex
24import tempfile
25
26import b2test_utils as b2tu
27
28
29def call_command(command):
30 """Call command print output after having removed some lines from output
31
32 Args:
33 command (string): command to be called
34 """
35 output = subprocess.check_output(shlex.split(command), encoding='utf-8').strip().split('\n')
36 for line in output:
37 if "created" not in line and "modified" not in line:
38 print(line.strip())
39
40
41if __name__ == '__main__':
42
43 if b2tu.is_cdb_down():
44 b2tu.skip_test('Test currently disabled due to CDB troubles')
45
46 tags = ['main_tag_merge_test_1', 'main_tag_merge_test_2', 'main_tag_merge_test_3']
47
48 call_command('b2conditionsdb iov main_tag_merge_test_2')
49 call_command('b2conditionsdb iov main_tag_merge_test_2 --run-range 5 200 5 300')
50 call_command('b2conditionsdb diff main_tag_merge_test_2 main_tag_merge_test_3')
51 call_command('b2conditionsdb diff main_tag_merge_test_2 main_tag_merge_test_3 --run-range 5 200 5 300')
52
53 # As the output of b2conditionsdb legacydownload contains some
54 # irreproducible elements (times, tempfolder location) I remove those
55 with tempfile.TemporaryDirectory() as tmpdirname:
56 output = subprocess.check_output(
57 shlex.split(f'b2conditionsdb legacydownload -c main_tag_merge_test_3 {tmpdirname} --run-range 5 0 5 1000'),
58 encoding='utf-8').strip().split('\n')
59 for line in output:
60 print(line.replace(tmpdirname, "centraldb")[7:].strip())
61
62 call_command('b2conditionsdb iovs delete --dry-run main_tag_merge_test_2 --run-range 5 200 5 300')
63 call_command('b2conditionsdb iovs delete --dry-run main_tag_merge_test_2 --run-range 5 200 5 300 --fully-contained')
64 call_command('b2conditionsdb iovs copy --replace --dry-run main_tag_merge_test_2 main_tag_merge_test_1')