Belle II Software light-2406-ragdoll
test_check_basf2_file.py
1#!/usr/bin/env python3
2
3
10
11import os
12
13# Test redirect_stdout, as we use that in b2file-check
14from contextlib import redirect_stdout
15with redirect_stdout(open(os.devnull, 'w')):
16 print('abc')
17
18import basf2 # noqa
19
20
21rootfile = basf2.find_file('/framework/tests/root_input.root')
22assert 0 == os.system('b2file-check ' + rootfile)
23
24assert 0 != os.system('b2file-check /THIS_DOESNT_EXIST')
25assert 0 != os.system('b2file-check /dev/null')
26
27
28assert 0 == os.system('b2file-check -n 5 ' + rootfile)
29assert 0 == os.system('b2file-check --events 5 ' + rootfile)
30assert 0 != os.system('b2file-check -n 10 ' + rootfile)
31
32assert 0 == os.system('b2file-check --mcevents 5 ' + rootfile)
33assert 0 != os.system('b2file-check --mcevents 0 ' + rootfile)
34
35assert 0 == os.system('b2file-check -n 5 -s 9.5 1 ' + rootfile)
36assert 0 == os.system('b2file-check -n 5 -s 9.5 0.05 ' + rootfile)
37assert 0 != os.system('b2file-check -n 5 -s 9.5 0 ' + rootfile)
38
39assert 0 == os.system('b2file-check -n 5 -s 10 1 ' + rootfile)
40assert 0 == os.system('b2file-check -n 5 -s 10 0.5 ' + rootfile)
41assert 0 == os.system('b2file-check -n 5 -s 10 0.2 ' + rootfile)
42assert 0 != os.system('b2file-check -n 5 -s 10 0.05 ' + rootfile)
43
44assert 0 == os.system('b2file-check -n 5 -s 10 0.5 ' + rootfile + ' EventMetaData')
45allbranches = 'EventMetaData PXDClusters PXDClustersToPXDDigits PXDClustersToPXDTrueHits PXDDigits PXDTrueHits'
46assert 0 == os.system('b2file-check -n 5 -s 10 0.5 ' + rootfile + ' ' + allbranches)
47assert 0 == os.system('b2file-check --json -n 5 -s 10 0.5 ' + rootfile + ' ' + allbranches)
48
49assert 0 != os.system('b2file-check -n 5 -s 10 0.5 ' + rootfile + ' NotThere')
50assert 0 != os.system('b2file-check -n 5 -s 10 0.5 ' + rootfile + ' EventMetaData NotThere')
51assert 0 != os.system('b2file-check -n 5 -s 10 0.5 ' + rootfile + ' NotThere EventMetaData')
52assert 0 != os.system('b2file-check -n 5 -s 10 0.5 ' + rootfile + ' FileMetaData')