Exemple #1
0
    def _LoadTestRuns(self, input):
        """Load test runs from the provided input.

        'input' -- A list of pairs of file names referring to result files /
        expectation files. The expectation file member may be None.

        returns -- A list of pairs of TestRun objects."""

        runs = []
        for result_file, exp_file in input:
            results = None
            expectations = None

            try:
                file = result_file
                reader = base.load_results(file, self.database)
                results = ReaderTestRun(reader)
                if exp_file:
                    file = exp_file
                    reader = base.load_results(file, self.database)
                    expectations = ReaderTestRun(reader)
            except IOError, e:
                raise PythonException("Error reading '%s'"%file, IOError, e)
            except xml.sax.SAXException, e:
                raise PythonException("Error loading '%s'"%file,
                                      xml.sax.SAXException, e)
Exemple #2
0
    def _LoadTestRuns(self, input):
        """Load test runs from the provided input.

        'input' -- A list of pairs of file names referring to result files /
        expectation files. The expectation file member may be None.

        returns -- A list of pairs of TestRun objects."""

        runs = []
        for result_file, exp_file in input:
            results = None
            expectations = None

            try:
                file = result_file
                reader = base.load_results(file, self.database)
                results = ReaderTestRun(reader)
                if exp_file:
                    file = exp_file
                    reader = base.load_results(file, self.database)
                    expectations = ReaderTestRun(reader)
            except IOError, e:
                raise PythonException("Error reading '%s'" % file, IOError, e)
            except xml.sax.SAXException, e:
                raise PythonException("Error loading '%s'" % file,
                                      xml.sax.SAXException, e)
Exemple #3
0
    def __init__(self, **args):

        super(PreviousTestRun, self).__init__(**args)
        if not self.results_file:
            self.results_file = open(self.file_name, "rb")
        results = load_results(self.results_file, self.test_database)
        self._results = {}
        for r in results:
            # Keep test results only.
            if r.GetKind() == Result.TEST:
                self._results[r.GetId()] = r
    def _CreateResultStreams(self, input):
        """Create result streams for all result files.

        'input' -- A list of pairs of file names referring to result files /
        expectation files. The expectation file member may be None.

        returns -- A list of pairs of ResultStream / Expectation objects."""

        results = []
        for result_file, exp_file in input:
            try:
                result = base.load_results(open(result_file, "rb"), self.database)
            except IOError, e:
                raise PythonException("Error reading '%s'"%result_file,
                                      IOError, e)
            except xml.sax.SAXException, e:
                raise PythonException("Error loading '%s'"%result_file,
                                      xml.sax.SAXException, e)
    def __init__(self, directory, database):
        """Create a new 'DirRunDatabase'.

        'directory' -- The path to the directory containing the
        results files.

        'database' -- The test 'Database' to which the results files
        correspond."""

        self.__runs = []
        # Read through all the .qmr files.
        for f in glob(os.path.join(directory, "*.qmr")):
            try:
                # Create the ResultReader corresponding to f.
                reader = base.load_results(f, database)
                run = ReaderTestRun(reader)
            except:
                # If anything goes wrong reading the file, just skip
                # it.
                continue
            # Add this run to the list.
            self.__runs.append(run)
    def __init__(self, directory, database):
        """Create a new 'DirRunDatabase'.

        'directory' -- The path to the directory containing the
        results files.

        'database' -- The test 'Database' to which the results files
        correspond."""

        self.__runs = []
        # Read through all the .qmr files.
        for f in glob(os.path.join(directory, "*.qmr")):
            try:
                # Create the ResultReader corresponding to f.
                reader = base.load_results(f, database)
                run = ReaderTestRun(reader)
            except:
                # If anything goes wrong reading the file, just skip
                # it.
                continue
            # Add this run to the list.
            self.__runs.append(run)
class myReportGenerator:
    """A 'myReportGenerator' generates a test report from one or more
    result files."""

    class Expectation:
        """An internal helper class to facilitate access to expectations."""
        
        def __init__(self, outcome, cause):

            self.outcome, self.cause = outcome, cause
            

    def __init__(self, output, database=None):
        if output and output != '-':
            self.output = open(output, 'w+') # only option in qmtest 2.3.0
        else:
            import sys
            self.output = sys.stdout # new in qmtest 2.4.1
        self.database = database
        self.__document = qm.xmlutil.create_dom_document(
            public_id="QMTest/Report",
            document_element_tag="report")


    def GenerateReport(self, flat, arguments):
        """Generates a report file with results collected from a set of
        result files.

        'flat' -- ignored (added for compatibility with the qmtest 2.4.1 API)

        'arguments' -- command arguments of the form [result [-e expectation]]+

        returns -- None."""

        # Construct a list of (result / expectation file) tuples.
        # As the expectation file is optional, see whether there
        # is an '-e' option, and then adjust the remainder accordingly.
        input = []
        while arguments:
            if len(arguments) >= 3 and arguments[1] == '-e':
                input.append((arguments[0], arguments[2]))
                arguments = arguments[3:]
            else:
                input.append((arguments[0],None))
                arguments = arguments[1:]

        # Write out the prologue.
        self.output.write("<?xml version='1.0' encoding='ISO-8859-1'?>\n")
        self.output.write('<!DOCTYPE report PUBLIC "%s" "%s">\n'
                        % (qm.xmlutil.make_public_id("QMTest/Report"),
                           qm.xmlutil.make_system_id("qmtest/report.dtd")))
        self.output.write("<report>\n")
        self._WriteTestIds(input)

        results = self._CreateResultStreams(input)
        for result in results:
            self._Report(result)
        self.output.write("</report>\n")


    def _CreateResultStreams(self, input):
        """Create result streams for all result files.

        'input' -- A list of pairs of file names referring to result files /
        expectation files. The expectation file member may be None.

        returns -- A list of pairs of ResultStream / Expectation objects."""

        results = []
        for result_file, exp_file in input:
            try:
                result = base.load_results(open(result_file, "rb"), self.database)
            except IOError, e:
                raise PythonException("Error reading '%s'"%result_file,
                                      IOError, e)
            except xml.sax.SAXException, e:
                raise PythonException("Error loading '%s'"%result_file,
                                      xml.sax.SAXException, e)
            exp = {}
            if exp_file:
                try:
                    exp_reader = base.load_results(open(exp_file, "rb"),
                                                   self.database)
                    for e in exp_reader:
                        if e.GetKind() == Result.TEST:
                            outcome = e.GetOutcome()
                            cause = e.get('qmtest.cause')
                            exp[e.GetId()] = myReportGenerator.Expectation(outcome,
                                                                           cause)
                except IOError, e:
                    raise PythonException("Error reading '%s'"%exp_file,
                                          IOError, e)
                except xml.sax.SAXException, e:
                    raise PythonException("Error loading '%s'"%exp_file,
                                          xml.sax.SAXException, e)