def test_keepalive_canvas(): gc.collect() assert list(R.gROOT.GetListOfFiles()) == [], "There exist open ROOT files when there should not be" with invisible_canvas() as c: get_file().Get("means/hist1").Draw() gc.collect() assert list(R.gROOT.GetListOfFiles()) != [], "Expected an open ROOT file.." gc.collect() assert list(R.gROOT.GetListOfFiles()) == [], "There exist open ROOT files when there should not be"
def test_file_get(): with get_file() as f: d = f.Get('means', rootpy=False) assert_equal(d.__class__.__name__, 'TDirectoryFile') d = f.Get('means') assert_equal(d.__class__.__name__, 'Directory') h = f.Get('means/hist1', rootpy=False) assert_equal(h.__class__.__name__, 'TH1F') h = f.Get('means/hist1') assert_equal(h.__class__.__name__, 'Hist')
def test_csv(): f = testdata.get_file('test_csv.root') tree = f.ParTree_Postselect tree.create_buffer(ignore_unsupported=True) output = StringIO() tree.csv(stream=output) f.close() # compare with existing txt output true_output_filename = testdata.get_filepath('test_csv.txt') with open(true_output_filename, 'r') as true_output_file: true_output = true_output_file.read() assert_equal(output.getvalue(), true_output)
def test_csv(): from cStringIO import StringIO f = testdata.get_file('test_csv.root') tree = f.ParTree_Postselect tree.create_buffer(ignore_unsupported=True) output = StringIO() tree.csv(stream=output) f.close() # compare with existing txt output true_output_filename = testdata.get_filepath('test_csv.txt') with open(true_output_filename, 'r') as true_output_file: true_output = true_output_file.read() assert_equal(output.getvalue(), true_output)
def test_root2hdf5_chunked_selected(): try: import tables except ImportError: raise SkipTest from rootpy.root2hdf5 import root2hdf5 rfile = get_file('test_tree.root') hfilename = os.path.join(TEMPDIR, 'out.h5') root2hdf5(rfile, hfilename, entries=90, selection='i % 2 == 0') hfile = tables.openFile(hfilename) assert_equal(len(hfile.root.test), 500) hfile.close()
def test_root2hdf5(): try: import tables except ImportError: raise SkipTest from rootpy.root2hdf5 import root2hdf5 rfile = get_file('test_tree.root') hfilename = os.path.join(TEMPDIR, 'out.h5') root2hdf5(rfile, hfilename) hfile = tables.openFile(hfilename) assert_equal(len(hfile.root.test), 1000) hfile.close()
def test_root2hdf5_chunked(): try: import tables except ImportError: raise SkipTest from rootpy.root2hdf5 import root2hdf5, tables_open rfile = get_file("test_tree.root") hfilename = os.path.join(TEMPDIR, "out.h5") root2hdf5(rfile, hfilename, entries=10) hfile = tables_open(hfilename) assert_equal(len(hfile.root.test), 1000) hfile.close()
def test_keepalive(): gc.collect() assert list(R.gROOT.GetListOfFiles()) == [], "There exist open ROOT files when there should not be" # Ordinarily this would lead to h with a value of `None`, since the file # gets garbage collected. However, File.Get uses keepalive to prevent this. # The purpose of this test is to ensure that everything is working as # expected. h = get_file().Get("means/hist1") gc.collect() assert h, "hist1 is not being kept alive" assert list(R.gROOT.GetListOfFiles()) != [], "Expected an open ROOT file.." h = None gc.collect() assert list(R.gROOT.GetListOfFiles()) == [], "There exist open ROOT files when there should not be"
def test_require_file_not_writable(): with testdata.get_file(): t = Tree()
from rootpy.testdata import get_file with get_file() as f: # access objects by name as properties of the current dir myhist = f.dimensions.hist2d # recursively walk through the file for path, dirs, objects in f.walk(): print path, dirs, objects
def load_tree(*args): with get_file('test_dicts.root') as f: t = f.data # this will trigger the generation of the required dicts t.create_buffer()