コード例 #1
0
ファイル: cli.py プロジェクト: thuyttn2020/test_junkie
    def run(self):
        parser = argparse.ArgumentParser(
            description='Run tests from command line',
            usage="tj run [OPTIONS]")

        parser.add_argument("-x",
                            "--suites",
                            nargs="+",
                            default=None,
                            help="Test Junkie will only run suites provided, "
                            "given that they are found in the SOURCE")

        parser.add_argument(
            "-v",
            "--verbose",
            action="store_true",
            default=False,
            help="Enables Test Junkie's logs for debugging purposes")

        parser.add_argument(
            "--config",
            type=str,
            default=Undefined,
            help=
            "Provide your own config FILE with settings for test execution.")

        CliUtils.add_standard_tj_args(parser)

        args = parser.parse_args(sys.argv[2:])

        if args.verbose:
            from test_junkie.debugger import LogJunkie
            LogJunkie.enable_logging(10)

        from test_junkie.cli.cli_runner import CliRunner
        try:
            tj = CliRunner(sources=args.sources,
                           ignore=[".git"],
                           suites=args.suites,
                           code_cov=args.code_cov,
                           cov_rcfile=args.cov_rcfile,
                           guess_root=args.guess_root,
                           config=args.config)
            tj.scan()
        except BadCliParameters as error:
            print("[{status}] {error}".format(
                status=CliUtils.format_color_string("ERROR", "red"),
                error=error))
            return
        tj.run_suites(args)
コード例 #2
0
from test_junkie.debugger import LogJunkie
from test_junkie.errors import BadParameters
from test_junkie.runner import Runner

LogJunkie.enable_logging(10)

LogJunkie.debug("1")
LogJunkie.info("2")
LogJunkie.warn("3")
LogJunkie.error("4")
LogJunkie.disable_logging()


def test_bad_runner_initiation1():
    try:
        Runner(suites=None)
        raise AssertionError(
            "Must have raised exception because bad args were passed in")
    except Exception as error:
        assert isinstance(error,
                          BadParameters), "Type of exception is incorrect"
コード例 #3
0
ファイル: cli.py プロジェクト: thuyttn2020/test_junkie
    def audit(self):
        parser = argparse.ArgumentParser(
            description=
            'Scan and display aggregated and/or filtered test information',
            usage="""tj audit [COMMAND] [OPTIONS]

Aggregate, pivot, and display data about your tests.

Commands:
suites\t\t Pivot test information from suite's perspective
features\t Pivot test information from feature's perspective
components\t Pivot test information from component's perspective
tags\t\t Pivot test information from tag's perspective
owners\t\t Pivot test information from owner's perspective

usage: tj audit [COMMAND] [OPTIONS]
""")
        parser.add_argument('command', help='command to run')

        parser.add_argument(
            "--by-components",
            action="store_true",
            default=False,
            help="Present aggregated data broken down by components")

        parser.add_argument(
            "--by-features",
            action="store_true",
            default=False,
            help="Present aggregated data broken down by features")

        parser.add_argument(
            "--no-rules",
            action="store_true",
            default=False,
            help="Aggregate data only for suites that do not have any rules set"
        )

        parser.add_argument(
            "--no-listeners",
            action="store_true",
            default=False,
            help=
            "Aggregate data only for suites that do not have any event listeners set"
        )

        parser.add_argument(
            "--no-suite-retries",
            action="store_true",
            default=False,
            help="Aggregate data only for suites that do not have retries set")

        parser.add_argument(
            "--no-test-retries",
            action="store_true",
            default=False,
            help="Aggregate data only for tests that do not have retries set")

        parser.add_argument(
            "--no-suite-meta",
            action="store_true",
            default=False,
            help=
            "Aggregate data only for suites that do not have any meta information set"
        )

        parser.add_argument(
            "--no-test-meta",
            action="store_true",
            default=False,
            help=
            "Aggregate data only for tests that do not have any meta information set"
        )

        parser.add_argument(
            "--no-owners",
            action="store_true",
            default=False,
            help=
            "Aggregate data only for tests that do not have any owners defined"
        )

        parser.add_argument(
            "--no-features",
            action="store_true",
            default=False,
            help=
            "Aggregate data only for suites that do not have features defined")

        parser.add_argument(
            "--no-components",
            action="store_true",
            default=False,
            help=
            "Aggregate data only for tests that do not have any components defined"
        )

        parser.add_argument(
            "--no-tags",
            action="store_true",
            default=False,
            help="Aggregate data only for tests that do not have tags defined")

        parser.add_argument("-x",
                            "--suites",
                            nargs="+",
                            default=None,
                            help="Test Junkie will only run suites provided, "
                            "given that they are found in the SOURCE")

        parser.add_argument(
            "-v",
            "--verbose",
            action="store_true",
            default=False,
            help="Enables Test Junkie's logs for debugging purposes")

        CliUtils.add_standard_tj_args(parser, audit=True)

        if len(sys.argv) >= 3:
            args = parser.parse_args(sys.argv[2:])
            command = args.command
            if command not in [
                    "suites", "features", "components", "tags", "owners"
            ]:
                print(
                    "[{status}]\t\'{command}\' is not a test-junkie command\n".
                    format(status=CliUtils.format_color_string(value="ERROR",
                                                               color="red"),
                           command=command))
                parser.print_help()
                exit(120)
            else:
                if args.verbose:
                    from test_junkie.debugger import LogJunkie
                    LogJunkie.enable_logging(10)

                from test_junkie.cli.cli_runner import CliRunner
                try:
                    tj = CliRunner(sources=args.sources,
                                   ignore=[".git"],
                                   suites=args.suites,
                                   guess_root=args.guess_root)
                    tj.scan()
                except BadCliParameters as error:
                    print("[{status}] {error}".format(
                        status=CliUtils.format_color_string("ERROR", "red"),
                        error=error))
                    return
                aggregator = CliAudit(suites=tj.suites, args=args)
                aggregator.aggregate()
                aggregator.print_results()
                return
        else:
            print("[{status}]\tDude, what do you want to audit?".format(
                status=CliUtils.format_color_string(value="ERROR",
                                                    color="red")))
        parser.print_help()