Belle II Software  release-08-01-10
test_b2conditionsdb_commands.py
1 
8 
9 '''
10 Test 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 
22 import subprocess
23 import shlex
24 import tempfile
25 
26 
27 def call_command(command):
28  """Call command print output after having removed some lines from output
29 
30  Args:
31  command (string): command to be called
32  """
33  output = subprocess.check_output(shlex.split(command), encoding='utf-8').strip().split('\n')
34  for line in output:
35  if "created" not in line and "modified" not in line:
36  print(line)
37 
38 
39 if __name__ == '__main__':
40 
41  tags = ['main_tag_merge_test_1', 'main_tag_merge_test_2', 'main_tag_merge_test_3']
42 
43  call_command('b2conditionsdb iov main_tag_merge_test_2')
44  call_command('b2conditionsdb iov main_tag_merge_test_2 --run-range 5 200 5 300')
45  call_command('b2conditionsdb diff main_tag_merge_test_2 main_tag_merge_test_3')
46  call_command('b2conditionsdb diff main_tag_merge_test_2 main_tag_merge_test_3 --run-range 5 200 5 300')
47 
48  # As the output of b2conditionsdb legacydownload contains some
49  # irreproducible elements (times, tempfolder location) I remove those
50  with tempfile.TemporaryDirectory() as tmpdirname:
51  output = subprocess.check_output(
52  shlex.split(f'b2conditionsdb legacydownload -c main_tag_merge_test_3 {tmpdirname} --run-range 5 0 5 1000'),
53  encoding='utf-8').strip().split('\n')
54  for line in output:
55  print(line.replace(tmpdirname, "centraldb")[7:])
56 
57  call_command('b2conditionsdb iovs delete --dry-run main_tag_merge_test_2 --run-range 5 200 5 300')
58  call_command('b2conditionsdb iovs delete --dry-run main_tag_merge_test_2 --run-range 5 200 5 300 --fully-contained')
59  call_command('b2conditionsdb iovs copy --replace --dry-run main_tag_merge_test_2 main_tag_merge_test_1')