def test_object(): with MemFile('test', 'recreate'): for cls in iter_rootpy_classes(): # avoid RooStats bugs for now if getattr(cls, '_ROOT', object).__name__.startswith('Roo'): continue if hasattr(cls, 'dynamic_cls'): cls = cls.dynamic_cls() assert hasattr(cls, '_ROOT'), \ "rootpy class {0} does not have a _ROOT attribute".format( cls.__name__) if issubclass(cls, ROOT.TDirectory): continue obj = asrootpy(cls._ROOT()) if isinstance(obj, Object): clone = obj.Clone()
def run(self): path = self.path output_path = self.output_path kwargs = self.kwargs measurements = measurements_from_xml(path, cd_parent=True, collect_histograms=True, silence=not self.verbose) for meas in measurements: root_file = os.path.join(output_path, '{0}.root'.format(meas.name)) xml_path = os.path.join(output_path, meas.name) with MemFile(): fix_measurement(meas, **kwargs) write_measurement(meas, root_file=root_file, xml_path=xml_path, write_workspaces=True, silence=not self.verbose)
def test_context(): with MemFile() as a: assert_equal(ROOT.gDirectory, a) with MemFile() as b: d = Directory('test') with d: assert_equal(ROOT.gDirectory, d) assert_equal(ROOT.gDirectory, b) assert_equal(ROOT.gDirectory, a) # test out of order f1 = MemFile() f2 = MemFile() with f1: assert_equal(ROOT.gDirectory, f1) assert_equal(ROOT.gDirectory, f2) f1.Close() f2.Close() d = Directory('test') d.cd() # test without with statement f1 = MemFile() f2 = TemporaryFile() assert_equal(ROOT.gDirectory, f2) f2.Close() assert_equal(ROOT.gDirectory, f1) f1.Close()
def test_memfile(): with MemFile() as f: hist = Hist(1, 0, 1, name='test') hist.Write() assert_equal(f['test'], hist)
def foo(): f = MemFile()