Belle II Software  release-05-01-25
test_check_basf2_file.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import os
5 
6 # Test redirect_stdout, as we use that in b2file-check
7 from contextlib import redirect_stdout
8 with redirect_stdout(open(os.devnull, 'w')):
9  print('abc')
10 
11 import basf2
12 
13 
14 rootfile = basf2.find_file('/framework/tests/root_input.root')
15 assert 0 == os.system('b2file-check ' + rootfile)
16 
17 assert 0 != os.system('b2file-check /THIS_DOESNT_EXIST')
18 assert 0 != os.system('b2file-check /dev/null')
19 
20 
21 assert 0 == os.system('b2file-check -n 5 ' + rootfile)
22 assert 0 == os.system('b2file-check --events 5 ' + rootfile)
23 assert 0 != os.system('b2file-check -n 10 ' + rootfile)
24 
25 # sadly, our input file doesn't have mcEvents stored (==0)
26 assert 0 == os.system('b2file-check --mcevents 0 ' + rootfile)
27 assert 0 != os.system('b2file-check --mcevents 123 ' + rootfile)
28 
29 assert 0 == os.system('b2file-check -n 5 -s 12.4 1 ' + rootfile)
30 assert 0 == os.system('b2file-check -n 5 -s 12.4 0.05 ' + rootfile)
31 assert 0 != os.system('b2file-check -n 5 -s 12.4 0 ' + rootfile)
32 
33 assert 0 == os.system('b2file-check -n 5 -s 10 1 ' + rootfile)
34 assert 0 == os.system('b2file-check -n 5 -s 10 0.5 ' + rootfile)
35 assert 0 != os.system('b2file-check -n 5 -s 10 0.2 ' + rootfile)
36 assert 0 != os.system('b2file-check -n 5 -s 10 0.05 ' + rootfile)
37 
38 assert 0 == os.system('b2file-check -n 5 -s 10 0.5 ' + rootfile + ' EventMetaData')
39 allbranches = 'EventMetaData PXDClusters PXDClustersToPXDDigits PXDClustersToPXDTrueHits PXDDigits PXDTrueHits'
40 assert 0 == os.system('b2file-check -n 5 -s 10 0.5 ' + rootfile + ' ' + allbranches)
41 assert 0 == os.system('b2file-check --json -n 5 -s 10 0.5 ' + rootfile + ' ' + allbranches)
42 
43 assert 0 != os.system('b2file-check -n 5 -s 10 0.5 ' + rootfile + ' NotThere')
44 assert 0 != os.system('b2file-check -n 5 -s 10 0.5 ' + rootfile + ' EventMetaData NotThere')
45 assert 0 != os.system('b2file-check -n 5 -s 10 0.5 ' + rootfile + ' NotThere EventMetaData')
46 assert 0 != os.system('b2file-check -n 5 -s 10 0.5 ' + rootfile + ' FileMetaData')