Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  runtests.py

  Sprache: Python
 

import glob
import os
import unittest

from IPDLCompile import IPDLCompile


class IPDLTestCase(unittest.TestCase):
    def __init__(self, ipdlargv, filename):
        unittest.TestCase.__init__(self, "test")
        self.filename = filename
        self.compile = IPDLCompile(filename, ipdlargv)

    def test(self):
        self.compile.run()
        self.assertFalse(self.compile.exception(), self.mkFailMsg())
        self.checkPassed()

    def mkCustomMsg(self, msg):
        return f"""
### Command: {" ".join(self.compile.argv)}
### {msg}
### stderr:
{self.compile.stderr}"""

    def mkFailMsg(self):
        return f"""
### Command: {" ".join(self.compile.argv)}
### stderr:
{self.compile.stderr}"""

    def shortDescription(self):
        return f'{self.__class__.__name__} test of "{self.filename}"'


class OkTestCase(IPDLTestCase):
    """An invocation of the IPDL compiler on a valid specification.
    The IPDL compiler should not produce errors or exceptions."""

    def __init__(self, ipdlargv, filename):
        IPDLTestCase.__init__(self, ipdlargv, filename)

    def checkPassed(self):
        self.assertTrue(self.compile.ok(), self.mkFailMsg())


class ErrorTestCase(IPDLTestCase):
    """An invocation of the IPDL compiler on an *invalid* specification.
    The IPDL compiler *should* produce errors but not exceptions."""

    def __init__(self, ipdlargv, filename):
        IPDLTestCase.__init__(self, ipdlargv, filename)

        # Look for expected errors in the input file.
        f = open(filename)
        self.expectedErrorMessage = []
        for l in f:
            if l.startswith("//error:"):
                self.expectedErrorMessage.append(l[2:-1])
        f.close()

    def checkPassed(self):
        self.assertNotEqual(
            self.expectedErrorMessage,
            [],
            self.mkCustomMsg(
                "Error test should contain at least "
                + "one line starting with //error: "
                + "that indicates the expected failure."
            ),
        )

        for e in self.expectedErrorMessage:
            self.assertTrue(
                self.compile.error(e),
                self.mkCustomMsg('Did not see expected error "' + e + '"'),
            )


if __name__ == "__main__":
    import sys

    okdir = sys.argv[1]
    assert os.path.isdir(okdir)
    errordir = sys.argv[2]
    assert os.path.isdir(errordir)

    ipdlargv = []
    oksuite = unittest.TestSuite()
    errorsuite = unittest.TestSuite()

    oktests, errortests = FalseFalse
    for arg in sys.argv[3:]:
        if errortests:
            # The extra subdirectory is used for non-failing files we want
            # to include from failing files.
            errorIncludes = ["-I", os.path.join(errordir, "extra"), "-I", errordir]
            for test in glob.glob(arg):
                errorsuite.addTest(ErrorTestCase(ipdlargv + errorIncludes, test))
        elif oktests:
            if "--error-tests" == arg:
                errortests = True
                continue
            for test in glob.glob(arg):
                oksuite.addTest(OkTestCase(ipdlargv + ["-I", okdir], test))
        else:
            if "--ok-tests" == arg:
                oktests = True
                continue
            ipdlargv.append(arg)

    test_result = (unittest.TextTestRunner()).run(
        unittest.TestSuite([oksuite, errorsuite])
    )
    sys.exit(not test_result.wasSuccessful())

Messung V0.5 in Prozent
C=86 H=98 G=91

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002