Edgewall Software

source: trunk/bitten/build/monotools.py @ 1001

Last change on this file since 1001 was 910, checked in by osimons, 13 years ago

Updated copyright to 2010.

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/python-source
File size: 3.4 KB
CovLine 
1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de>
4# Copyright (C) 2006 Matthew Good <matt@matt-good.net>
5# Copyright (C) 2007-2010 Edgewall Software
6# Copyright (C) 2009 Grzegorz Sobanski <silk@boktor.net>
7# All rights reserved.
8#
9# This software is licensed as described in the file COPYING, which
10# you should have received as part of this distribution. The terms
11# are also available at http://bitten.edgewall.org/wiki/License.
12
113"""Recipe commands for tools commonly used in Mono projects."""
14
115from glob import glob
116import logging
117import os
118import posixpath
119import shlex
120import tempfile
21
122from bitten.build import CommandLine
123from bitten.util import xmlio
24
125log = logging.getLogger('bitten.build.monotools')
26
127__docformat__ = 'restructuredtext en'
28
29
130def _parse_suite(element):
1031    for child in element.children('results'):
532        testcases = list(child.children('test-case'))
533        if testcases:
334            yield element, testcases
35
736        for xmlsuite in child.children('test-suite'):
437            for suite in _parse_suite(xmlsuite):
238                yield suite
39
40
141def _get_cases(fileobj):
742    for testsuite in xmlio.parse(fileobj).children('test-suite'):
643        for suite in _parse_suite(testsuite):
344            yield suite
45
46
147def nunit(ctxt, file_=None):
48    """Extract test results from a NUnit XML report.
49   
50    :param ctxt: the build context
51    :type ctxt: `Context`
52    :param file\_: path to the NUnit XML test results; may contain globbing
53                  wildcards for matching multiple results files
54    """
555    assert file_, 'Missing required attribute "file"'
456    try:
457        total, failed = 0, 0
458        results = xmlio.Fragment()
859        for path in glob(ctxt.resolve(file_)):
460            fileobj = file(path, 'r')
461            try:
762                for suite, testcases in _get_cases(fileobj):
663                    for testcase in testcases:
364                        test = xmlio.Element('test')
365                        test.attr['fixture'] = suite.attr['name']
366                        if 'time' in testcase.attr:
367                            test.attr['duration'] = testcase.attr['time']
368                        if testcase.attr['executed'] == 'True':
369                            if testcase.attr['success'] != 'True':
170                                test.attr['status'] = 'failure'
171                                failure = list(testcase.children('failure'))
172                                if failure:
173                                    stacktraceNode = list(failure[0].children('stack-trace'))
174                                    if stacktraceNode:
175                                        test.append(xmlio.Element('traceback')[
176                                            stacktraceNode[0].gettext()
177                                        ])
178                                    failed += 1
179                            else:
280                                test.attr['status'] = 'success'
281                        else:
082                            test.attr['status'] = 'ignore'
83
384                        results.append(test)
385                        total += 1
386            finally:
487                fileobj.close()
488        if failed:
189            ctxt.error('%d of %d test%s failed' % (failed, total,
190                       total != 1 and 's' or ''))
491        ctxt.report('test', results)
092    except IOError, e:
093        log.warning('Error opening NUnit results file (%s)', e)
094    except xmlio.ParseError, e:
095        log.warning('Error parsing NUnit results file (%s)', e)
96
97
Note: See TracBrowser for help on using the repository browser.