Example #1
0
def run(path, pattern):
    Vows.gather(path, pattern)

    result = Vows.ensure(VowsDefaultReporter.handle_success, VowsDefaultReporter.handle_error)

    reporter = VowsDefaultReporter(result)

    reporter.pretty_print()

    return result, reporter
Example #2
0
def run(path, pattern, verbosity, progress):
    # they need to be imported here, else the no-color option wont work
    from pyvows.core import Vows
    from pyvows.reporting import VowsDefaultReporter

    Vows.gather(path, pattern)

    handle_success = progress and VowsDefaultReporter.handle_success or None
    handle_error = progress and VowsDefaultReporter.handle_error or None
    result = Vows.ensure(handle_success, handle_error)

    reporter = VowsDefaultReporter(result, verbosity)

    return result, reporter
Example #3
0
        def setup(self):
            # The eval_context() method of the result object is called by
            # the reporter to decide if a context was successful or
            # not. Here we are testing the reporting of errors, so provide
            # a mock result which always says it has failed.
            class MockResult:
                def eval_context(self, context):
                    return False

            self.reporter = VowsDefaultReporter(MockResult(), 0)

            # Patch the print_traceback() method to just record its
            # arguments.
            self.print_traceback_args = None

            def print_traceback(*args, **kwargs):
                self.print_traceback_args = args

            self.reporter.print_traceback = print_traceback
Example #4
0
File: cli.py Project: 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)
Example #5
0
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)
Example #6
0
 def topic(self):
     return VowsDefaultReporter(None, 0)