def testGoodFile(self): filename = "./testFiles/slha/gluino_squarks.slha" outputfile = runMain(filename) if self.definingRun: logger.error ( "This is a definition run! Know what youre doing!" ) default = "gluino_squarks_default.py" cmd = "cat %s | sed -e 's/smodelsOutput/smodelsOutputDefault/' > %s" % ( outputfile, default ) a = subprocess.getoutput ( cmd ) smodelsOutput = importModule ( outputfile ) from gluino_squarks_default import smodelsOutputDefault ignoreFields = ['input file','smodels version', 'ncpus', 'Element', 'database version', 'Total missed xsec', 'Missed xsec long-lived', 'Missed xsec displaced', 'Missed xsec MET', 'Total outside grid xsec', 'Total xsec for missing topologies (fb)','Total xsec for missing topologies with displaced decays (fb)', 'Total xsec for missing topologies with prompt decays (fb)', 'Total xsec for topologies outside the grid (fb)'] smodelsOutputDefault['ExptRes'] = sorted(smodelsOutputDefault['ExptRes'], key=lambda res: res['r'], reverse=True) equals = equalObjs(smodelsOutput,smodelsOutputDefault,allowedDiff=0.02, ignore=ignoreFields, fname = outputfile ) for i in [ './output.py', './output.pyc' ]: if os.path.exists( i ): os.remove( i ) if not equals: p = outputfile.find ( "unitTestOutput" ) fname = outputfile if p > 0: fname = fname[p:] print ( "[testRunSModelS] %s != %s" % \ ( fname, "gluino_squarks_default.py" ) ) self.assertTrue(equals) self.removeOutputs( outputfile )
def testGoodFileWithModelFromSLHA(self): filename = "./testFiles/slha/gluino_squarks.slha" outputfile = runMain(filename,inifile='testParametersB.ini') smodelsOutput = importModule ( outputfile ) from gluino_squarks_default import smodelsOutputDefault ignoreFields = ['input file','smodels version', 'ncpus', 'Element', 'database version', 'Total missed xsec', 'Missed xsec long-lived', 'Missed xsec displaced', 'Missed xsec MET', 'Total outside grid xsec', 'Total xsec for missing topologies (fb)','Total xsec for missing topologies with displaced decays (fb)', 'Total xsec for missing topologies with prompt decays (fb)', 'Total xsec for topologies outside the grid (fb)'] smodelsOutputDefault['ExptRes'] = sorted(smodelsOutputDefault['ExptRes'], key=lambda res: res['r'], reverse=True) equals = equalObjs(smodelsOutput,smodelsOutputDefault,allowedDiff=0.02, ignore=ignoreFields, fname = outputfile ) for i in [ './output.py', './output.pyc' ]: if os.path.exists( i ): os.remove( i ) if not equals: p = outputfile.find ( "unitTestOutput" ) fname = outputfile if p > 0: fname = fname[p:] print ( "[testRunSModelS] %s != %s" % \ ( fname, "gluino_squarks_default.py" ) ) self.assertTrue(equals) self.removeOutputs( outputfile )
def testGoodFile13(self): filename = "./testFiles/slha/simplyGluino.slha" outputfile = runMain(filename,suppressStdout = True ) if self.definingRun: logger.error ( "This is a definition run! Know what youre doing!" ) default = "simplyGluino_default.py" cmd = "cat %s | sed -e 's/smodelsOutput/smodelsOutputDefault/' > %s" % ( outputfile, default ) a = subprocess.getoutput ( cmd ) smodelsOutput = importModule ( outputfile ) from simplyGluino_default import smodelsOutputDefault ignoreFields = ['input file','smodels version', 'ncpus', 'Element', 'database version', 'Total missed xsec', 'Missed xsec long-lived', 'Missed xsec displaced', 'Missed xsec MET', 'Total outside grid xsec', 'Total xsec for missing topologies (fb)','Total xsec for missing topologies with displaced decays (fb)', 'Total xsec for missing topologies with prompt decays (fb)', 'Total xsec for topologies outside the grid (fb)'] smodelsOutputDefault['ExptRes'] = sorted(smodelsOutputDefault['ExptRes'], key=lambda res: res['r'], reverse=True) equals = equalObjs(smodelsOutput,smodelsOutputDefault,allowedDiff=0.08, ignore=ignoreFields, fname = outputfile ) if not equals: e = "output13.py != simplyGluino_default.py" logger.error( e ) # raise AssertionError( e ) self.assertTrue(equals) ## test went through, so remove the output files self.removeOutputs( outputfile )
def testRuntimeImport(self): filename = "./testFiles/slha/idm_example.slha" runtime.modelFile = 'idm' reload(particlesLoader) outputfile = runMain(filename,inifile='testParameters_noModel.ini',suppressStdout=True) if self.definingRun: logger.error ( "This is a definition run! Know what youre doing!" ) default = "idm_example_defaultB.py" cmd = "cat %s | sed -e 's/smodelsOutput/smodelsOutputDefault/' > %s" % ( outputfile, default ) a = subprocess.getoutput ( cmd ) smodelsOutput = importModule ( outputfile ) from idm_example_defaultB import smodelsOutputDefault ignoreFields = ['input file','smodels version', 'ncpus', 'Element', 'database version', 'Total missed xsec', 'Missed xsec long-lived', 'Missed xsec displaced', 'Missed xsec MET', 'Total outside grid xsec', 'Total xsec for missing topologies (fb)', 'Total xsec for missing topologies with displaced decays (fb)', 'Total xsec for missing topologies with prompt decays (fb)', 'Total xsec for topologies outside the grid (fb)'] smodelsOutputDefault['ExptRes'] = sorted(smodelsOutputDefault['ExptRes'], key=lambda res: res['r'], reverse=True) equals = equalObjs(smodelsOutput,smodelsOutputDefault,allowedDiff=0.1, ignore=ignoreFields, fname = outputfile ) self.assertTrue(equals) self.removeOutputs(outputfile)
def testCombinedResult(self): filename = "./testFiles/slha/gluino_squarks.slha" outputfile = runMain(filename, inifile="testParameters_agg.ini", suppressStdout=True) smodelsOutput = importModule(outputfile) from gluino_squarks_default_agg import smodelsOutputDefault ignoreFields = [ 'input file', 'smodels version', 'ncpus', 'Element', 'database version', 'Total missed xsec', 'Missed xsec long-lived', 'Missed xsec displaced', 'Missed xsec MET', 'Total outside grid xsec', 'Total xsec for missing topologies (fb)', 'Total xsec for missing topologies with displaced decays (fb)', 'Total xsec for missing topologies with prompt decays (fb)', 'Total xsec for topologies outside the grid (fb)' ] smodelsOutputDefault['ExptRes'] = sorted( smodelsOutputDefault['ExptRes'], key=lambda res: res['r'], reverse=True) equals = equalObjs(smodelsOutput, smodelsOutputDefault, allowedDiff=0.02, ignore=ignoreFields, fname=outputfile) if equals != True: logger.error("%s differs from %s!" % ("gluino_squarks_default_agg.py", outputfile)) self.assertTrue(equals) for i in [outputfile, outputfile.replace(".py", ".pyc")]: if os.path.exists(i): os.remove(i)
def testWrongModel(self): runtime.modelFile = 'mssm' reload(particlesLoader) filename = "./testFiles/slha/idm_example.slha" outputfile = runMain(filename,suppressStdout=True) smodelsOutput = importModule ( outputfile ) self.assertTrue(smodelsOutput['OutputStatus']['decomposition status'] < 0) self.removeOutputs(outputfile)
def testCompare(self): warnings.simplefilter("ignore", ResourceWarning) from simplyGluino_default import smodelsOutputDefault filename = "./testFiles/slha/simplyGluino.slha" port = random.choice(range(31700, 42000)) # port = 31744 dbfile = "database/db30.pcl" dbfile = "unittest" startserver = f"../smodels/tools/smodelsTools.py proxydb -p {port} -i {dbfile} -o ./proxy.pcl -r -v error" cmd = startserver.split(" ") # print ( "starting server %s" % startserver ) myenv = os.environ.copy() pp = "" if "PYTHONPATH" in myenv: pp = ":" + myenv["PYTHONPATH"] myenv["PYTHONPATH"] = "../" + pp subprocess.Popen(cmd, env=myenv) time.sleep(3) db = Database("./proxy.pcl") outputfile = runMain(filename, suppressStdout=True, overridedatabase=db) smodelsOutput = importModule(outputfile) client = DatabaseClient(port=port, verbose="warn") client.send_shutdown() ignoreFields = [ 'input file', 'smodels version', 'ncpus', 'Element', 'database version', 'Total missed xsec', 'Missed xsec long-lived', 'Missed xsec displaced', 'Missed xsec MET', 'Total outside grid xsec', 'Total xsec for missing topologies (fb)', 'Total xsec for missing topologies with displaced decays (fb)', 'Total xsec for missing topologies with prompt decays (fb)', 'Total xsec for topologies outside the grid (fb)' ] smodelsOutputDefault['ExptRes'] = sorted( smodelsOutputDefault['ExptRes'], key=lambda res: res['r'], reverse=True) equals = equalObjs(smodelsOutput, smodelsOutputDefault, allowedDiff=0.08, ignore=ignoreFields, fname=outputfile) if not equals: e = "simplyGluino.py != simplyGluino_default.py" logger.error(e) # raise AssertionError( e ) self.assertTrue(equals) self.removeOutputs(outputfile)
def testPyhfCombination(self): filename = "./testFiles/slha/T6bbHH_pyhf.slha" inifile = "./testParameters_pyhf.ini" outputfile = runMain(filename, inifile=inifile, suppressStdout = True) smodelsOutput = importModule ( outputfile ) from T6bbHH_pyhf_default import smodelsOutputDefault ignoreFields = ['input file','smodels version', 'ncpus', 'database version'] equals = equalObjs(smodelsOutput,smodelsOutputDefault,allowedDiff=0.02, ignore=ignoreFields, fname=outputfile, fname2 = "T6bbHH_pyhf_default.py" ) self.assertTrue(equals)
def defineTest(self): """ define the current output as the default output. Use with care! """ filename = "./testFiles/slha/gluino_squarks.slha" outputfile = runMain(filename, inifile="testParameters_agg.ini", suppressStdout=True) smodelsOutput = importModule(outputfile) f = open("gluino_squarks_default_agg.py", "w") f.write("smodelsOutputDefault = %s\n" % smodelsOutput) f.close()
def testLifeTimeDependent(self): filename = "./testFiles/slha/lifetime.slha" outputfile = runMain(filename) if self.definingRun: logger.error ( "This is a definition run! Know what youre doing!" ) default = "lifetime_default.py" cmd = "cat %s | sed -e 's/smodelsOutput/smodelsOutputDefault/' > %s" % ( outputfile, default ) a = subprocess.getoutput ( cmd ) smodelsOutput = importModule ( outputfile ) from lifetime_default import smodelsOutputDefault ignoreFields = ['input file','smodels version', 'ncpus', 'database version'] smodelsOutputDefault['ExptRes'] = sorted(smodelsOutputDefault['ExptRes'], key=lambda res: res['r'], reverse=True) equals = equalObjs(smodelsOutput,smodelsOutputDefault,allowedDiff=0.02, ignore=ignoreFields, fname=outputfile ) for i in [ './outputHSCP.py', './outputHSCP.pyc' ]: if os.path.exists( i ): os.remove( i ) self.assertTrue(equals)
def testModelFromSLHA(self): filename = "./testFiles/slha/idm_example.slha" #Test the case where the BSM particles are defined by the SLHA file: outputfile = runMain(filename,inifile='testParameters_idmB.ini',suppressStdout=True) smodelsOutput = importModule ( outputfile ) from idm_example_default import smodelsOutputDefault ignoreFields = ['input file','smodels version', 'ncpus', 'Element', 'database version', 'Total missed xsec', 'Missed xsec long-lived', 'Missed xsec displaced', 'Missed xsec MET', 'Total outside grid xsec', 'Total xsec for missing topologies (fb)','Total xsec for missing topologies with displaced decays (fb)', 'Total xsec for missing topologies with prompt decays (fb)', 'Total xsec for topologies outside the grid (fb)'] smodelsOutputDefault['ExptRes'] = sorted(smodelsOutputDefault['ExptRes'], key=lambda res: res['r'], reverse=True) equals = equalObjs(smodelsOutput,smodelsOutputDefault,allowedDiff=0.1, ignore=ignoreFields, fname = outputfile ) self.assertTrue(equals) self.removeOutputs(outputfile)