def setUp(self): super(TestCustomChecker, self).setUp() from Ganga.GPI import Job, CustomChecker from GangaTest.Framework.utils import sleep_until_completed self.c = CustomChecker() self.j = None self.file_name_stdout = None self.file_name_fail = None # write string to tmpfile self.j = Job() self.j.submit() self.assertTrue( sleep_until_completed(self.j), 'Timeout on job submission: job is still not finished') self.assertEqual(self.j.status, 'completed') file_obj, file_name = tempfile.mkstemp() os.close(file_obj) os.unlink(file_name) os.mkdir(file_name) self.file_name_stdout = os.path.join(file_name, 'check_stdout.py') with open(self.file_name_stdout, 'w') as module_stdout: module_stdout.write("""import os def check(j): stdout = os.path.join(j.outputdir,'stdout') return os.path.exists(stdout) """) self.file_name_fail = os.path.join(file_name, 'check_fail.py') with open(self.file_name_fail, 'w') as module_fail: module_fail.write('will not run')
def setUp(self): super(TestCustomChecker, self).setUp() from Ganga.GPI import Job, CustomChecker from GangaTest.Framework.utils import sleep_until_completed self.c = CustomChecker() self.j = None self.file_name_stdout = None self.file_name_fail = None # write string to tmpfile self.j = Job() self.j.submit() self.assertTrue(sleep_until_completed(self.j), 'Timeout on job submission: job is still not finished') self.assertEqual(self.j.status, 'completed') file_obj, file_name = tempfile.mkstemp() os.close(file_obj) os.unlink(file_name) os.mkdir(file_name) self.file_name_stdout = os.path.join(file_name, 'check_stdout.py') with open(self.file_name_stdout, 'w') as module_stdout: module_stdout.write("""import os def check(j): stdout = os.path.join(j.outputdir,'stdout') return os.path.exists(stdout) """) self.file_name_fail = os.path.join(file_name, 'check_fail.py') with open(self.file_name_fail, 'w') as module_fail: module_fail.write('will not run')
class TestCustomChecker(GangaUnitTest): def setUp(self): super(TestCustomChecker, self).setUp() from Ganga.GPI import Job, CustomChecker from GangaTest.Framework.utils import sleep_until_completed self.c = CustomChecker() self.j = None self.file_name_stdout = None self.file_name_fail = None # write string to tmpfile self.j = Job() self.j.submit() self.assertTrue(sleep_until_completed(self.j), 'Timeout on job submission: job is still not finished') self.assertEqual(self.j.status, 'completed') file_obj, file_name = tempfile.mkstemp() os.close(file_obj) os.unlink(file_name) os.mkdir(file_name) self.file_name_stdout = os.path.join(file_name, 'check_stdout.py') with open(self.file_name_stdout, 'w') as module_stdout: module_stdout.write("""import os def check(j): stdout = os.path.join(j.outputdir,'stdout') return os.path.exists(stdout) """) self.file_name_fail = os.path.join(file_name, 'check_fail.py') with open(self.file_name_fail, 'w') as module_fail: module_fail.write('will not run') def checkFail(self, message): from Ganga.GPIDev.Adapters.IPostProcessor import PostProcessException try: self.c.check(self.j) except PostProcessException: pass else: self.fail('Should have thrown exception: ' + message) def testCustomChecker_badInput(self): self.checkFail('no module specified') self.c.module = '/not/a/file' self.checkFail('file does not exist') self.c.module = self.file_name_fail self.checkFail('module will not run') def testCustomChecker_standardCheck(self): print('%s' % str(self.file_name_stdout)) print('%s' % str(self.file_name_fail)) self.c.module = self.file_name_stdout print('%s' % type(self.c.module)) assert self.c.check(self.j)
def test_h_PostProcessors(self): from Ganga.GPI import Job, RootMerger, TextMerger, CustomMerger, SmartMerger, RootFileChecker, FileChecker, \ Notifier, CustomChecker j = Job() # -- POSTPROCESSORS APPEND START j.postprocessors.append( RootMerger(files=['thesis_data.root'], ignorefailed=True, overwrite=True)) # -- POSTPROCESSORS APPEND STOP # -- POSTPROCESSORS TEXTMERGER START TextMerger(compress=True) # -- POSTPROCESSORS TEXTMERGER STOP # -- POSTPROCESSORS ROOTMERGER START RootMerger(args='-T') # -- POSTPROCESSORS ROOTMERGER STOP # -- POSTPROCESSORS CUSTOMMERGER START CustomMerger().module = '~/mymerger.py' # -- POSTPROCESSORS CUSTOMMERGER STOP # -- POSTPROCESSORS SMARTMERGER START SmartMerger(files=['thesis_data.root', 'stdout'], overwrite=True) # -- POSTPROCESSORS SMARTMERGER STOP # -- POSTPROCESSORS SMARTMERGERAPPEND START j.postprocessors.append( SmartMerger(files=['thesis_data.root', 'stdout'], overwrite=True)) # -- POSTPROCESSORS SMARTMERGERAPPEND STOP # -- POSTPROCESSORS SMARTMERGERAPPEND2 START j.postprocessors.append(TextMerger(files=['stdout'], overwrite=True)) j.postprocessors.append( RootMerger(files=['thesis_data.root'], overwrite=False)) # -- POSTPROCESSORS SMARTMERGERAPPEND2 STOP # -- POSTPROCESSORS FILECHECKER START fc = FileChecker(files=['stdout'], searchStrings=['Segmentation']) # -- POSTPROCESSORS FILECHECKER STOP # -- POSTPROCESSORS FILECHECKERMUSTEXIST START fc.filesMustExist = True # -- POSTPROCESSORS FILECHECKERMUSTEXIST STOP # -- POSTPROCESSORS FILECHECKEROPTS START fc.searchStrings = ['SUCCESS'] fc.failIfFound = False # -- POSTPROCESSORS FILECHECKEROPTS STOP # -- POSTPROCESSORS FILECHECKEROPTS START rfc = RootFileChecker(files=["*.root"]) rfc.files = ["*.root"] j.postprocessors.append(rfc) # -- POSTPROCESSORS FILECHECKEROPTS STOP # -- POSTPROCESSORS CUSTOMCHECKER START cc = CustomChecker(module='~/mychecker.py') # -- POSTPROCESSORS CUSTOMCHECKER STOP # -- POSTPROCESSORS NOTIFIER START n = Notifier(address='myaddress.cern.ch') # -- POSTPROCESSORS NOTIFIER STOP # -- POSTPROCESSORS NOTIFIEROPTS START n.verbose = True # -- POSTPROCESSORS NOTIFIEROPTS STOP # -- POSTPROCESSORS MULTIPLE START tm = TextMerger(files=['stdout'], compress=True) rm = RootMerger(files=['thesis_data.root'], args='-f6') fc = FileChecker(files=['stdout'], searchStrings=['Segmentation']) cc = CustomChecker(module='~/mychecker.py') n = Notifier(address='myadress.cern.ch') j.postprocessors = [tm, rm, fc, cc, n] # -- POSTPROCESSORS MULTIPLE STOP # -- POSTPROCESSORS MULTIPLE2 START j.postprocessors.append(fc) j.postprocessors.append(tm) j.postprocessors.append(rm) j.postprocessors.append(cc) j.postprocessors.append(n) # -- POSTPROCESSORS MULTIPLE2 STOP j.postprocessors.remove(FileChecker())
class TestCustomChecker(GangaUnitTest): def setUp(self): super(TestCustomChecker, self).setUp() from Ganga.GPI import Job, CustomChecker from GangaTest.Framework.utils import sleep_until_completed self.c = CustomChecker() self.j = None self.file_name_stdout = None self.file_name_fail = None # write string to tmpfile self.j = Job() self.j.submit() self.assertTrue( sleep_until_completed(self.j), 'Timeout on job submission: job is still not finished') self.assertEqual(self.j.status, 'completed') file_obj, file_name = tempfile.mkstemp() os.close(file_obj) os.unlink(file_name) os.mkdir(file_name) self.file_name_stdout = os.path.join(file_name, 'check_stdout.py') with open(self.file_name_stdout, 'w') as module_stdout: module_stdout.write("""import os def check(j): stdout = os.path.join(j.outputdir,'stdout') return os.path.exists(stdout) """) self.file_name_fail = os.path.join(file_name, 'check_fail.py') with open(self.file_name_fail, 'w') as module_fail: module_fail.write('will not run') def checkFail(self, message): from Ganga.GPIDev.Adapters.IPostProcessor import PostProcessException try: self.c.check(self.j) except PostProcessException: pass else: self.fail('Should have thrown exception: ' + message) def testCustomChecker_badInput(self): self.checkFail('no module specified') self.c.module = '/not/a/file' self.checkFail('file does not exist') self.c.module = self.file_name_fail self.checkFail('module will not run') def testCustomChecker_standardCheck(self): print('%s' % str(self.file_name_stdout)) print('%s' % str(self.file_name_fail)) self.c.module = self.file_name_stdout print('%s' % type(self.c.module)) assert self.c.check(self.j)