Exemple #1
0
 def run(self, result):
     with chtempdir(prefix="tmp.", dir=os.getcwd()) as temp_dir_info:
         num_prev_failures = len(result.failures)
         num_prev_errors = len(result.errors)
         super(RubikTestSuite, self).run(result)
         num_curr_failures = len(result.failures)
         num_curr_errors = len(result.errors)
         num_failures = num_curr_failures - num_prev_failures
         num_errors = num_curr_errors - num_prev_errors
         if num_failures > 0 or num_errors > 0:
             self.logger.error("suite {}: {} errors, {} failures: leaving dir {}".format(self.suite_name, num_errors, num_failures, temp_dir_info.dirname))
             temp_dir_info.clear = False
def main(arguments=None):
    if arguments is None:
        arguments = sys.argv[1:]

    description = """\
================================================================================
Rubik example testing system {version}
================================================================================
This tool can be used to validate rubik examples, such as wiki md files.

""".format(version=conf.VERSION)
    epilog = ""
    
    parser = argparse.ArgumentParser(
        description=description,
        epilog=epilog,
        add_help=True,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )

    parser.add_argument("--verbose", "-v",
        dest="verbose_level",
        action="count",
        default=1,
        help="increase verbose level")

    parser.add_argument("--verbose-level",
        metavar="VL",
        dest="verbose_level",
        type=int,
        default=1,
        help="set verbose level")

    parser.add_argument("--quiet", "--silent", "-q",
        dest="verbose_level",
        action="store_const",
        const=0,
        default=0,
        help="set quiet mode (warning messages are disabled)")

    parser.add_argument("--trace-errors", "-E",
        dest="trace_errors",
        action="store_true",
        default=False,
        help="show error traceback")

    parser.add_argument("--list", "-l",
        dest="list",
        action="store_true",
        default=False,
        help="list selected examples")

    parser.add_argument("--dry-run", "-d",
        dest="dry_run",
        action="store_true",
        default=False,
        help="dry run (do not validate examples)")

    parser.add_argument("--warnings", "-W",
        action="append",
        choices=conf.ALL_WARNINGS,
        default=[],
        help="enable warnings")

    parser.add_argument("--version",
        action="version",
        version='{program} {version}'.format(program=conf.PROGRAM_NAME, version=conf.VERSION))

    parser.add_argument("filenames",
        type=str,
        nargs='*',
        help="pattern matching example files, for instance '*.md'")

    try:
        args = parser.parse_args(arguments)
    except Exception as err:
        sys.stderr.write("error: {0}: {1}\n".format(err.__class__.__name__, err))
        return 1

    conf.enable_warnings(*args.warnings)
    PRINT = rubik_log.PRINT

    # test
    test_logger = log.set_test_logger(args.verbose_level)

    for c, filename in enumerate(iterfilenames(args.filenames)):
        if args.list:
            test_logger.info("{:8d}) {}".format(c, filename))
        if not args.dry_run:
            with open(filename, "rb") as f_in:
                text = f_in.read()
            example = Example(text=text)
            with chtempdir(prefix="tmp.ex.", dir=os.getcwd()) as temp_dir_info:
                try:
                    example.show(test=True)
                except Exception as err:
                    rubik_log.trace_error(args.trace_errors)
                    temp_dir_info.clear = False
                    test_logger.warning("example file {} failed - leaving test dir {}".format(filename, temp_dir_info.dirname))
                    return 1
    return 0
Exemple #3
0
def main(arguments=None):
    if arguments is None:
        arguments = sys.argv[1:]

    description = """\
================================================================================
Rubik example testing system {version}
================================================================================
This tool can be used to validate rubik examples, such as wiki md files.

""".format(version=conf.VERSION)
    epilog = ""

    parser = argparse.ArgumentParser(
        description=description,
        epilog=epilog,
        add_help=True,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )

    parser.add_argument("--verbose",
                        "-v",
                        dest="verbose_level",
                        action="count",
                        default=1,
                        help="increase verbose level")

    parser.add_argument("--verbose-level",
                        metavar="VL",
                        dest="verbose_level",
                        type=int,
                        default=1,
                        help="set verbose level")

    parser.add_argument("--quiet",
                        "--silent",
                        "-q",
                        dest="verbose_level",
                        action="store_const",
                        const=0,
                        default=0,
                        help="set quiet mode (warning messages are disabled)")

    parser.add_argument("--trace-errors",
                        "-E",
                        dest="trace_errors",
                        action="store_true",
                        default=False,
                        help="show error traceback")

    parser.add_argument("--list",
                        "-l",
                        dest="list",
                        action="store_true",
                        default=False,
                        help="list selected examples")

    parser.add_argument("--dry-run",
                        "-d",
                        dest="dry_run",
                        action="store_true",
                        default=False,
                        help="dry run (do not validate examples)")

    parser.add_argument("--warnings",
                        "-W",
                        action="append",
                        choices=conf.ALL_WARNINGS,
                        default=[],
                        help="enable warnings")

    parser.add_argument("--version",
                        action="version",
                        version='{program} {version}'.format(
                            program=conf.PROGRAM_NAME, version=conf.VERSION))

    parser.add_argument(
        "filenames",
        type=str,
        nargs='*',
        help="pattern matching example files, for instance '*.md'")

    try:
        args = parser.parse_args(arguments)
    except Exception as err:
        sys.stderr.write("error: {0}: {1}\n".format(err.__class__.__name__,
                                                    err))
        return 1

    conf.enable_warnings(*args.warnings)
    PRINT = rubik_log.PRINT

    # test
    test_logger = log.set_test_logger(args.verbose_level)

    for c, filename in enumerate(iterfilenames(args.filenames)):
        if args.list:
            test_logger.info("{:8d}) {}".format(c, filename))
        if not args.dry_run:
            with open(filename, "rb") as f_in:
                text = f_in.read()
            example = Example(text=text)
            with chtempdir(prefix="tmp.ex.", dir=os.getcwd()) as temp_dir_info:
                try:
                    example.show(test=True)
                except Exception as err:
                    rubik_log.trace_error(args.trace_errors)
                    temp_dir_info.clear = False
                    test_logger.warning(
                        "example file {} failed - leaving test dir {}".format(
                            filename, temp_dir_info.dirname))
                    return 1
    return 0