示例#1
0
 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)
示例#2
0
 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 )
示例#3
0
    def testPythonPrinterSimple(self):
        self.removeOutputs ( './unitTestOutput/printer_output_simple.py' )
 
        mprinter = printer.MPrinter()
        mprinter.Printers['python'] = printer.PyPrinter(output = 'file')
        #Define options:
        mprinter.Printers['python'].addelementlist = True
         
        slhafile = "./testFiles/slha/simplyGluino.slha"
        mprinter.setOutPutFiles('./unitTestOutput/printer_output_simple',silent=True)
        self.runPrinterMain(slhafile,mprinter,addTopList=True)
        
        smodelsOutput = importlib.import_module( "unitTestOutput.printer_output_simple" ).smodelsOutput
        # from unitTestOutput.printer_output_simple import smodelsOutput
        from simplyGluino_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.05,
                            ignore=ignoreFields )
        try:
            self.assertTrue(equals)
        except AssertionError as e:
            print ( "Error: %s, when comparing %s \nwith %s." % (e,"outputSimple.py","simplyGluino_default.py" ) )
            raise AssertionError(e)
        self.removeOutputs('./unitTestOutput/printer_output_simple.py')
示例#4
0
 def testCombinedResult(self):
     filename = "./testFiles/slha/gluino_squarks.slha"
     outputfile = runMain(filename,
                          inifile="testParameters_agg.ini",
                          suppressStdout=True)
     with open(outputfile, 'rb') as fp:  ## imports file with dots in name
         output_module = imp.load_module("output", fp, outputfile,
                                         ('.py', 'rb', imp.PY_SOURCE))
         smodelsOutput = output_module.smodelsOutput
         from gluino_squarks_default_agg 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)
         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)
示例#5
0
 def testRuntimeImport(self):
     filename = "./testFiles/slha/idm_example.slha"
     runtime.modelFile = 'idm'
     reload(particlesLoader)
     outputfile = runMain(filename,
                          inifile='testParameters_noModel.ini',
                          suppressStdout=True)
     with open(outputfile, 'rb') as fp:  ## imports file with dots in name
         output_module = imp.load_module("output", fp, outputfile,
                                         ('.py', 'rb', imp.PY_SOURCE))
         smodelsOutput = output_module.smodelsOutput
     from idm_example_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)
     self.assertTrue(equals)
     self.removeOutputs(outputfile)
示例#6
0
 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 )
示例#7
0
 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)
示例#8
0
    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 )
示例#9
0
    def testGoodFile13(self):

        filename = "./testFiles/slha/simplyGluino.slha"
        outputfile = runMain(filename, suppressStdout=True)
        with open(outputfile, 'rb') as fp:  ## imports file with dots in name
            output_module = imp.load_module("output", fp, outputfile,
                                            ('.py', 'rb', imp.PY_SOURCE))
            smodelsOutput = output_module.smodelsOutput
        from simplyGluino_default import smodelsOutputDefault
        ignoreFields = [
            'input file', 'smodels version', 'ncpus', 'Element',
            'database version'
        ]
        smodelsOutputDefault['ExptRes'] = sorted(
            smodelsOutputDefault['ExptRes'],
            key=lambda res: res['r'],
            reverse=True)
        equals = equalObjs(smodelsOutput,
                           smodelsOutputDefault,
                           allowedDiff=0.02,
                           ignore=ignoreFields)
        if not equals:
            e = "output13.py and simplyGluino_default.py differ!"
            logger.error(e)
            # raise AssertionError ( e )

        self.assertTrue(equals)

        ## test went through, so remove the output files
        self.removeOutputs(outputfile)
示例#10
0
    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)
示例#11
0
    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)
示例#12
0
    def testPythonPrinter(self):

        self.removeOutputs('./unitTestOutput/printer_output.py')
        mprinter = printer.MPrinter()
        mprinter.Printers['python'] = printer.PyPrinter(output='file')
        #Define options:
        mprinter.Printers['python'].addElementList = False

        slhafile = "./testFiles/slha/gluino_squarks.slha"
        mprinter.setOutPutFiles('./unitTestOutput/printer_output', silent=True)
        self.runPrinterMain(slhafile, mprinter)

        try:
            smodelsOutput = importlib.import_module(
                "unitTestOutput.printer_output").smodelsOutput
        except ImportError:  #Python2 fallback
            import imp
            pM = imp.load_source("smodels",
                                 "./unitTestOutput/printer_output.py")
            smodelsOutput = pM.smodelsOutput
        #Test python output
        from gluino_squarks_default import smodelsOutputDefault
        ignoreFields = [
            'input file', 'smodels version', 'ncpus', '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)
        smodelsOutput['ExptRes'] = sorted(smodelsOutputDefault['ExptRes'],
                                          key=lambda res: res['r'],
                                          reverse=True)
        equals = equalObjs(smodelsOutput,
                           smodelsOutputDefault,
                           allowedDiff=0.05,
                           ignore=ignoreFields,
                           where="top",
                           fname="./unitTestOutput/printer_output.py")
        try:
            self.assertTrue(equals)
        except AssertionError as e:
            print("Error: %s, when comparing %s \nwith %s." %
                  (e, "output.py", "gluino_squarks_default.py"))
            raise AssertionError(e)
        self.removeOutputs('./unitTestOutput/printer_output.py')
示例#13
0
 def testParameterFile(self):
     filename = "./testFiles/slha/idm_example.slha"
     outputfile = runMain(filename,inifile='testParameters_idm.ini',suppressStdout=True)        
     with open( outputfile, 'rb') as fp: ## imports file with dots in name
         output_module = imp.load_module("output",fp,outputfile, ('.py', 'rb', imp.PY_SOURCE) )
         smodelsOutput = output_module.smodelsOutput
     from idm_example_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)
     self.assertTrue(equals)
     self.removeOutputs(outputfile)
示例#14
0
    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)
示例#15
0
 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)
示例#16
0
 def testCombinedResult(self):
     filename = "./testFiles/slha/gluino_squarks.slha"
     outputfile = runMain(filename,inifile="testParameters_agg.ini", suppressStdout=True )
     with open( outputfile, 'rb') as fp: ## imports file with dots in name
         output_module = imp.load_module("output",fp,outputfile, 
                                         ('.py', 'rb', imp.PY_SOURCE) )
         smodelsOutput = output_module.smodelsOutput
         from gluino_squarks_default_agg 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)
         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 )
示例#17
0
 def testGoodFile(self):
     filename = "./testFiles/slha/gluino_squarks.slha"
     outputfile = runMain(filename)
     with open(outputfile, 'rb') as fp:  ## imports file with dots in name
         output_module = imp.load_module("output", fp, outputfile,
                                         ('.py', 'rb', imp.PY_SOURCE))
         smodelsOutput = output_module.smodelsOutput
     from gluino_squarks_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)
     self.assertTrue(equals)
     self.removeOutputs(outputfile)
示例#18
0
    def testGoodFile13(self):
            
        filename = "./testFiles/slha/simplyGluino.slha"
        outputfile = runMain(filename,suppressStdout = True )
        with open( outputfile, 'rb') as fp: ## imports file with dots in name
            output_module = imp.load_module("output",fp,outputfile, ('.py', 'rb', imp.PY_SOURCE) )
            smodelsOutput = output_module.smodelsOutput
        from simplyGluino_default import smodelsOutputDefault
        ignoreFields = ['input file','smodels version', 'ncpus', 'Element', 'database version' ]
        smodelsOutputDefault['ExptRes'] = sorted(smodelsOutputDefault['ExptRes'],
                    key=lambda res: res['r'], reverse=True)
        equals = equalObjs(smodelsOutput,smodelsOutputDefault,allowedDiff=0.02,
                           ignore=ignoreFields)
        if not equals:
            e =  "output13.py and simplyGluino_default.py differ!" 
            logger.error ( e )
            # raise AssertionError ( e )

        self.assertTrue(equals)        

        ## test went through, so remove the output files
        self.removeOutputs ( outputfile )
示例#19
0
    def testPythonPrinterSimple(self):
        self.removeOutputs('./unitTestOutput/printer_output_simple.py')

        mprinter = printer.MPrinter()
        mprinter.Printers['python'] = printer.PyPrinter(output='file')
        #Define options:
        mprinter.Printers['python'].addelementlist = True

        slhafile = "./testFiles/slha/simplyGluino.slha"
        mprinter.setOutPutFiles('./unitTestOutput/printer_output_simple',
                                silent=True)
        self.runPrinterMain(slhafile, mprinter, addTopList=True)

        smodelsOutput = importlib.import_module(
            "unitTestOutput.printer_output_simple").smodelsOutput
        # from unitTestOutput.printer_output_simple import smodelsOutput
        from simplyGluino_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.05,
                           ignore=ignoreFields)
        try:
            self.assertTrue(equals)
        except AssertionError as e:
            print("Error: %s, when comparing %s \nwith %s." %
                  (e, "outputSimple.py", "simplyGluino_default.py"))
            raise AssertionError(e)
        self.removeOutputs('./unitTestOutput/printer_output_simple.py')
示例#20
0
    def testPythonPrinterSimple(self):
        outfile = './unitTestOutput/printer_output_simple.py'
        self.removeOutputs(outfile)

        mprinter = printer.MPrinter()
        mprinter.Printers['python'] = printer.PyPrinter(output='file')
        #Define options:
        mprinter.Printers['python'].addelementlist = True

        slhafile = "./testFiles/slha/simplyGluino.slha"
        mprinter.setOutPutFiles(outfile.replace(".py", ""), silent=True)
        self.runPrinterMain(slhafile, mprinter, addTopList=True)

        if self.definingRun:
            from smodels.tools.smodelsLogging import logger
            logger.error("This is a definition run! Know what youre doing!")
            default = "simplyGluino_default.py"
            outputfile = './unitTestOutput/printer_output_simple.py'
            cmd = "cat %s | sed -e 's/smodelsOutput/smodelsOutputDefault/' > %s" % (
                outputfile, default)
            a = subprocess.getoutput(cmd)

        impfile = outfile.replace(".py", "").replace("/",
                                                     ".").replace("..", "")
        try:
            smodelsOutput = importlib.import_module(impfile).smodelsOutput
        except ImportError:  #Python2 fallback
            import imp
            pM = imp.load_source("smodels", outfile)
            smodelsOutput = pM.smodelsOutput

        from simplyGluino_default import smodelsOutputDefault

        ignoreFields = [
            'input file', 'smodels version', 'ncpus', '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)
        smodelsOutput['ExptRes'] = sorted(smodelsOutputDefault['ExptRes'],
                                          key=lambda res: res['r'],
                                          reverse=True)
        equals = equalObjs(smodelsOutput,
                           smodelsOutputDefault,
                           allowedDiff=0.05,
                           ignore=ignoreFields,
                           fname="./unitTestOutput/printer_output_simple.py")
        try:
            self.assertTrue(equals)
            self.removeOutputs(outfile)
        except AssertionError as e:
            print("Error: %s, when comparing %s \nwith %s." %
                  (e, "outputSimple.py", "simplyGluino_default.py"))
            raise AssertionError(e)