예제 #1
0
 def topic(self):
     result = ResultMock()
     result.successful_tests = 1
     result.errored_tests = 0
     result.skipped_tests = 0
     result.total_test_count = 1
     result.elapsed_time = 0
     result.contexts = [
         {
             'name': 'Context1',
             'tests': [
                 {
                     'name': 'Test1',
                     'succeeded': True,
                     'stdout': 'outline',
                     'stderr': 'errline'
                 }
             ],
             'contexts': [],
             'stdout': 'outline',
             'stderr': 'errline'
         }
     ]
     reporter = XUnitReporter(result)
     return reporter.create_report_document().firstChild
예제 #2
0
        def topic(self):
            try:
                raise Exception('fdsa')
            except:
                test_exc_info = sys.exc_info()

            result = ResultMock()
            result.successful_tests = 1
            result.errored_tests = 1
            result.skipped_tests = 0
            result.total_test_count = 2
            result.elapsed_time = 0
            result.contexts = [{
                'name':
                'ContextWithCapturedError',
                'error':
                None,
                'contexts': [],
                'stdout':
                '',
                'stderr':
                '',
                'tests': [{
                    'context_instance':
                    Vows.Context(),
                    'name':
                    'failedCheckOnException',
                    'enumerated':
                    False,
                    'result':
                    None,
                    'topic':
                    Exception('fdsa'),
                    'error':
                    dict(zip(['type', 'value', 'traceback'], test_exc_info)),
                    'succeeded':
                    False,
                    'file':
                    'asdf.py',
                    'lineno':
                    1,
                    'elapsed':
                    0,
                    'stdout':
                    '',
                    'stderr':
                    ''
                }]
            }]
            reporter = XUnitReporter(result)
            return reporter.create_report_document().firstChild
예제 #3
0
 def topic(self):
     result = ResultMock()
     result.successful_tests = 0
     result.errored_tests = 0
     result.elapsed_time = 0
     result.contexts = []
     reporter = XUnitReporter(result)
     return reporter
예제 #4
0
 def topic(self):
     result = ResultMock()
     result.successful_tests = 1
     result.errored_tests = 0
     result.elapsed_time = 0
     result.contexts = [
         {
             'name': 'Context1',
             'tests': [
                 {
                     'name': 'Test1',
                     'succeeded': True
                 }
             ],
             'contexts': []
         }
     ]
     reporter = XUnitReporter(result)
     return reporter.create_report_document().firstChild.firstChild
예제 #5
0
        def topic(self):
            try:
                raise Exception('asdf')
            except:
                test_exc_info = sys.exc_info()

            result = ResultMock()
            result.successful_tests = 1
            result.errored_tests = 0
            result.skipped_tests = 0
            result.total_test_count = 1
            result.elapsed_time = 0
            result.contexts = [{
                'name': 'Context1',
                'tests': [],
                'error': VowsTopicError('topic', test_exc_info),
                'contexts': [],
                'stdout': '',
                'stderr': ''
            }]
            reporter = XUnitReporter(result)
            return reporter.create_report_document().firstChild.firstChild
예제 #6
0
파일: cli.py 프로젝트: Zearin/pyvows
def main():
    '''PyVows' runtime implementation.
    '''
    # needs to be imported here, else the no-color option won't work
    from pyvows.reporting import VowsDefaultReporter

    arguments = Parser().parse_args()

    if arguments.template:
        from pyvows.utils import template
        template()
        sys.exit()  # Exit after printing template, since it's
                    # supposed to be redirected from STDOUT by the user

    path, pattern = arguments.path, arguments.pattern
    if path and isfile(path):
        path, pattern = split(path)
    if not path:
        path = os.curdir

    if arguments.no_color:
        for color_name, value in inspect.getmembers(Fore):
            if not color_name.startswith('_'):
                setattr(Fore, color_name, '')

    if arguments.cover and COVERAGE_AVAILABLE:
        cov = coverage(source=arguments.cover_package,
                       omit=arguments.cover_omit)
        cov.erase()
        cov.start()

    prune = arguments.exclude

    verbosity = len(arguments.verbosity) if arguments.verbosity else 2
    result = run(path, pattern, verbosity, arguments.progress, prune)
    reporter = VowsDefaultReporter(result, verbosity)

    # Print test results first
    reporter.pretty_print()

    # Print profile if necessary
    if arguments.profile:
        reporter.print_profile(arguments.profile_threshold)

    # Print coverage if necessary
    if result.successful and arguments.cover:
        # if coverage was requested, but unavailable, warn the user
        if not COVERAGE_AVAILABLE:
            print()
            print(yellow('WARNING: Cover disabled because coverage could not be found.'))
            print(yellow('Make sure it is installed and accessible.'))
            print()

        # otherwise, we're good
        else:
            cov.stop()
            xml = ''

            try:
                with tempfile.NamedTemporaryFile() as tmp:
                    cov.xml_report(outfile=tmp.name)
                    tmp.seek(0)
                    xml = tmp.read()
            except Exception:
                err = sys.exc_info()[1]
                print("Could not run coverage. Error: %s" % err)

            if xml:
                if arguments.cover_report:
                    with open(arguments.cover_report, 'w') as report:
                        report.write(xml)

                arguments.cover_threshold /= 100.0
                reporter.print_coverage(xml, arguments.cover_threshold)

    # Write XUnit if necessary
    if arguments.xunit_output:
        xunit = XUnitReporter(result)
        xunit.write_report(arguments.xunit_file)

    sys.exit(result.errored_tests)
예제 #7
0
 def topic(self, results):
     return XUnitReporter(results).create_report_document()
예제 #8
0
파일: cli.py 프로젝트: heynemann/pyvows
def main():
    '''PyVows' runtime implementation.
    '''
    # needs to be imported here, else the no-color option won't work
    from pyvows.reporting import VowsDefaultReporter

    arguments = Parser().parse_args()

    if arguments.template:
        from pyvows.utils import template
        template()
        sys.exit()  # Exit after printing template, since it's
        # supposed to be redirected from STDOUT by the user

    path, pattern = arguments.path, arguments.pattern
    if path and isfile(path):
        path, pattern = split(path)
    if not path:
        path = os.curdir

    if arguments.no_color:
        for color_name, value in inspect.getmembers(Fore):
            if not color_name.startswith('_'):
                setattr(Fore, color_name, '')

    if arguments.cover and COVERAGE_AVAILABLE:
        cov = coverage(source=arguments.cover_package,
                       omit=arguments.cover_omit)
        cov.erase()
        cov.start()

    verbosity = len(arguments.verbosity) if arguments.verbosity else 2
    result = run(path,
                 pattern,
                 verbosity,
                 arguments.progress,
                 exclusion_patterns=arguments.exclude,
                 inclusion_patterns=arguments.include,
                 capture_output=arguments.capture_output)
    reporter = VowsDefaultReporter(result, verbosity)

    # Print test results first
    reporter.pretty_print()

    # Print profile if necessary
    if arguments.profile:
        reporter.print_profile(arguments.profile_threshold)

    # Print coverage if necessary
    if result.successful and arguments.cover:
        # if coverage was requested, but unavailable, warn the user
        if not COVERAGE_AVAILABLE:
            print()
            print(
                yellow(
                    'WARNING: Cover disabled because coverage could not be found.'
                ))
            print(yellow('Make sure it is installed and accessible.'))
            print()

        # otherwise, we're good
        else:
            cov.stop()
            xml = ''

            try:
                with tempfile.NamedTemporaryFile() as tmp:
                    cov.xml_report(outfile=tmp.name)
                    tmp.seek(0)
                    xml = tmp.read()
            except Exception:
                err = sys.exc_info()[1]
                print("Could not run coverage. Error: %s" % err)

            if xml:
                if arguments.cover_report:
                    with open(arguments.cover_report, 'wb') as report:
                        report.write(xml)

                arguments.cover_threshold /= 100.0
                reporter.print_coverage(xml, arguments.cover_threshold)

    # Write XUnit if necessary
    if arguments.xunit_output:
        xunit = XUnitReporter(result)
        xunit.write_report(arguments.xunit_file)

    sys.exit(result.errored_tests)