コード例 #1
0
ファイル: testPrinter.py プロジェクト: ismailturan/smodels
    def testXmlPrinterSimple(self):
        self.removeOutputs('./unitTestOutput/printer_output_simple.xml')

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

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

        defFile = os.path.join(idir(), "test/default_outputSimplyGluino.xml")
        outFile = os.path.join(
            idir(), "test/unitTestOutput/printer_output_simple.xml")

        #Test xml output
        xmlDefault = ElementTree.parse(defFile).getroot()
        xmlNew = ElementTree.parse(outFile).getroot()
        sortXML(xmlDefault)
        sortXML(xmlNew)
        try:
            self.assertTrue(
                compareXML(xmlDefault,
                           xmlNew,
                           allowedDiff=0.05,
                           ignore=['input_file', 'smodels_version', 'ncpus']))
        except AssertionError as e:
            msg = "%s != %s" % (defFile, outFile) + "\n" + str(e)
            raise AssertionError(msg)
        self.removeOutputs('./unitTestOutput/printer_output_simple.xml')
コード例 #2
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')
コード例 #3
0
    def testXmlPrinterSimple(self):
        self.removeOutputs('./unitTestOutput/printer_output_simple.xml')

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

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

        defFile = "default_outputSimplyGluino.xml"
        outFile = "./unitTestOutput/printer_output_simple.xml"

        #Test xml output
        xmlDefault = ElementTree.parse(defFile).getroot()
        xmlNew = ElementTree.parse(outFile).getroot()
        sortXML(xmlDefault)
        sortXML(xmlNew)
        try:
            self.assertTrue(
                compareXML(
                    xmlDefault,
                    xmlNew,
                    allowedDiff=0.05,
                    ignore=[
                        'input_file', 'smodels_version', 'ncpus',
                        '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)'
                    ]))
        except AssertionError as e:
            msg = "%s != %s" % (defFile, outFile) + "\n" + str(e)
            raise AssertionError(msg)
        self.removeOutputs('./unitTestOutput/printer_output_simple.xml')
コード例 #4
0
    def testSLHAPrinter(self):
        self.removeOutputs('./unitTestOutput/printer_output.smodelsslha')

        mprinter = printer.MPrinter()
        mprinter.Printers['slha'] = printer.SLHAPrinter(output='file')
        #Define options:
        mprinter.Printers['slha'].addelementlist = True
        mprinter.Printers['slha'].docompress = 1

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

        slhaDefaultFile = "./gluino_squarks_default.slha.smodelsslha"
        slhaNewFile = './unitTestOutput/printer_output.smodelsslha'
        try:
            self.assertTrue(compareSLHA(slhaDefaultFile, slhaNewFile))
        except AssertionError:
            msg = "%s != %s" % (slhaDefaultFile, slhaNewFile)
            raise AssertionError(msg)
        self.removeOutputs('./unitTestOutput/printer_output.smodelsslha')
コード例 #5
0
    def testTextPrinter(self):
        outputfile = "./unitTestOutput/printer_output.smodels"
        self.removeOutputs(outputfile)
        mprinter = printer.MPrinter()
        mprinter.Printers['summary'] = printer.SummaryPrinter(output='file')
        #Define options:
        mprinter.Printers['summary'].expandedSummary = True

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

        samplefile = "gluino_squarks_default.txt"
        #Test summary output
        output = summaryReader.Summary(outputfile, allowedDiff=0.05)
        sample = summaryReader.Summary(samplefile, allowedDiff=0.05)
        try:
            self.assertEqual(sample, output)
        except AssertionError:
            msg = "%s != %s" % (sample, output)
            raise AssertionError(msg)
        self.removeOutputs(outputfile)
コード例 #6
0
ファイル: testPrinter.py プロジェクト: ismailturan/smodels
    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')
コード例 #7
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)