Example #1
0
    def run(self, pav_cfg, args):
        """Run this command."""

        filter_func = None
        if not args.all:
            filter_func = filters.make_test_run_filter(
                complete=args.complete,
                failed=args.failed,
                incomplete=args.incomplete,
                name=args.name,
                newer_than=args.newer_than,
                older_than=args.older_than,
                passed=args.passed,
                result_error=args.result_error,
                show_skipped=args.show_skipped,
                sys_name=args.sys_name,
                user=args.user)

        end = '\n' if args.verbose else '\r'

        # Clean Tests
        tests_dir = pav_cfg.working_dir / 'test_runs'  # type: Path
        output.fprint("Removing Tests...", file=self.outfile, end=end)
        rm_tests_count, msgs = clean.delete_tests(tests_dir, filter_func,
                                                  args.verbose)
        if args.verbose:
            for msg in msgs:
                output.fprint(msg, color=output.YELLOW)
        output.fprint("Removed {} test(s).".format(rm_tests_count),
                      file=self.outfile,
                      color=output.GREEN,
                      clear=True)

        # Clean Series
        series_dir = pav_cfg.working_dir / 'series'  # type: Path
        output.fprint("Removing Series...", file=self.outfile, end=end)
        rm_series_count, msgs = clean.delete_series(series_dir, args.verbose)
        if args.verbose:
            for msg in msgs:
                output.fprint(msg, color=output.YELLOW)
        output.fprint("Removed {} series.".format(rm_series_count),
                      file=self.outfile,
                      color=output.GREEN,
                      clear=True)

        # Clean Builds
        builds_dir = pav_cfg.working_dir / 'builds'  # type: Path
        output.fprint("Removing Builds...", file=self.outfile, end=end)
        rm_builds_count, msgs = clean.delete_builds(builds_dir, tests_dir,
                                                    args.verbose)
        if args.verbose:
            for msg in msgs:
                output.fprint(msg, color=output.YELLOW)
        output.fprint("Removed {} build(s).".format(rm_builds_count),
                      file=self.outfile,
                      color=output.GREEN,
                      clear=True)

        return 0
Example #2
0
    def test_make_test_run_filter(self):
        """Check that the series filter options all work."""

        now = dt.datetime.now()

        always_match_test = TestAttributes(Path('dummy'))
        always_match_test._attrs = {
            'complete': True,
            'created': now - dt.timedelta(minutes=5),
            'name': 'mytest.always_match',
            'result': TestRun.PASS,
            'skipped': False,
            'sys_name': 'this',
            'user': '******',
        }
        never_match_test = TestAttributes(Path('dummy'))
        never_match_test._attrs = {
            'complete': False,
            'created': now - dt.timedelta(minutes=1),
            'name': 'yourtest.never_match',
            'result': TestRun.FAIL,
            'skipped': True,
            'sys_name': 'that',
            'user': '******',
        }

        # Setting any of this will be ok for the 'always' pass test,
        # but never ok for the 'never' pass test.
        opt_set = {
            'show_skipped': 'no',
            'complete': True,
            'user': '******',
            'sys_name': 'this',
            'passed': True,
            'older_than': now - dt.timedelta(minutes=2),
            'name': 'mytest.*',
        }

        # These are the opposite. The 'always' pass test won't, and the
        # 'never' pass will.
        inv_opt_set = {
            'incomplete': True,
            'failed': True,
            'result_error': True,
            'newer_than': now - dt.timedelta(minutes=2),
        }

        for opt, val in opt_set.items():
            tr_filter = filters.make_test_run_filter(**{opt: val})

            self.assertTrue(tr_filter(always_match_test),
                            msg="Failed on opt, val ({}, {})\n{}".format(
                                opt, val, always_match_test.attr_dict()))
            self.assertFalse(tr_filter(never_match_test),
                             msg="Failed on opt, val ({}, {})\n{}".format(
                                 opt, val, never_match_test.attr_dict()))

        for opt, val in inv_opt_set.items():
            tr_filter = filters.make_test_run_filter(**{opt: val})

            self.assertFalse(tr_filter(always_match_test),
                             msg="Failed on opt, val ({}, {})\n{}".format(
                                 opt, val, always_match_test.attr_dict()))
            if opt != 'result_error':  # Fails on this one (expected)
                self.assertTrue(tr_filter(never_match_test),
                                msg="Failed on opt, val ({}, {})\n{}".format(
                                    opt, val, never_match_test.attr_dict()))
Example #3
0
    def test_make_series_filter(self):
        """Check the filter maker function."""

        now = dt.datetime.now()

        class DummySeriesInfo:
            """A class to assign arbitrary attributes to."""

        base = {
            'complete': False,
            'incomplete': False,
            'user': None,
            'sys_name': None,
            'older_than': None,
            'newer_than': None,
        }

        always_match_series = DummySeriesInfo()
        always_match_series.complete = True
        always_match_series.created = now - dt.timedelta(minutes=5)
        always_match_series.sys_name = 'this'
        always_match_series.user = '******'

        never_match_series = DummySeriesInfo()
        never_match_series.complete = False
        never_match_series.created = now - dt.timedelta(minutes=1)
        never_match_series.sys_name = 'that'
        never_match_series.user = '******'

        # Setting any of this will be ok for the 'always' pass test,
        # but never ok for the 'never' pass test.
        opt_set = {
            'complete': True,
            'user': '******',
            'sys_name': 'this',
            'older_than': now - dt.timedelta(minutes=2),
        }

        # These are the opposite. The 'always' pass test won't, and the
        # 'never' pass will.
        inv_opt_set = {
            'incomplete': True,
            'newer_than': now - dt.timedelta(minutes=2),
        }

        for opt, val in opt_set.items():
            opts = base.copy()
            opts[opt] = val

            series_filter = filters.make_series_filter(**opts)

            self.assertTrue(series_filter(always_match_series),
                            msg="Failed on opt, val ({}, {})".format(opt, val))
            self.assertFalse(series_filter(never_match_series),
                             msg="Failed on opt, val ({}, {})".format(
                                 opt, val))

        for opt, val in inv_opt_set.items():
            opts = base.copy()
            opts[opt] = val
            series_filter = filters.make_test_run_filter(**opts)

            self.assertFalse(series_filter(always_match_series),
                             msg="Failed on opt, val ({}, {})".format(
                                 opt, val))
            self.assertTrue(series_filter(never_match_series),
                            msg="Failed on opt, val ({}, {})".format(opt, val))
Example #4
0
    def _test_runs_cmd(self, pav_cfg, args):
        """
        :param pav_cfg:
        :param args:
        :return:
        """

        if args.show_fields:
            for field in TestAttributes.list_attrs():
                output.fprint(field,
                              '-',
                              TestAttributes.attr_doc(field),
                              file=self.outfile)
            return 0

        fields, mode = self.get_fields(
            fields_arg=args.out_fields,
            mode_arg=args.output_mode,
            default_single_field='id',
            default_fields=self.RUN_LONG_FIELDS,
            avail_fields=TestAttributes.list_attrs())

        filter_func = filters.make_test_run_filter(
            complete=args.complete,
            failed=args.failed,
            incomplete=args.incomplete,
            name=args.name,
            newer_than=args.newer_than,
            older_than=args.older_than,
            passed=args.passed,
            show_skipped=args.show_skipped,
            sys_name=args.sys_name,
            user=args.user,
        )

        order_func, ascending = filters.get_sort_opts(args.sort_by,
                                                      filters.TEST_SORT_FUNCS)

        if args.series:
            picked_runs = []
            for series_id in args.series:
                try:
                    picked_runs.extend(
                        TestSeries.list_series_tests(pav_cfg=pav_cfg,
                                                     sid=series_id))
                except TestSeriesError as err:
                    output.fprint("Invalid test series '{}'.\n{}".format(
                        series_id, err.args[0]),
                                  color=output.RED,
                                  file=self.errfile)
                    return errno.EINVAL
            runs = dir_db.select_from(
                paths=picked_runs,
                transform=TestAttributes,
                filter_func=filter_func,
                order_func=order_func,
                order_asc=ascending,
                limit=args.limit,
            )
        else:
            runs = dir_db.select(
                id_dir=pav_cfg.working_dir / 'test_runs',
                transform=TestAttributes,
                filter_func=filter_func,
                order_func=order_func,
                order_asc=ascending,
                limit=args.limit,
            )

        self.write_output(
            mode=mode,
            rows=[run.attr_dict(include_empty=False) for run in runs],
            fields=fields,
            header=args.header,
            vsep=args.vsep,
            wrap=args.wrap,
        )
Example #5
0
    def test_make_series_filter(self):
        """Check the filter maker function."""

        now = time.time()

        base = {
            'complete': False,
            'incomplete': False,
            'user': None,
            'sys_name': None,
            'older_than': None,
            'newer_than': None,
        }

        always_match_series = {
            'complete': True,
            'created': now - 5*60,
            'sys_name': 'this',
            'user': '******',
        }

        never_match_series = {
            'complete': False,
            'created': now - 1*60,
            'sys_name': 'that',
            'user': '******',
        }

        # Setting any of this will be ok for the 'always' pass test,
        # but never ok for the 'never' pass test.
        opt_set = {
            'complete': True,
            'user': '******',
            'sys_name': 'this',
            'older_than': now - 2*60,
        }

        # These are the opposite. The 'always' pass test won't, and the
        # 'never' pass will.
        inv_opt_set = {
            'incomplete': True,
            'newer_than': now - 2*60,
        }

        for opt, val in opt_set.items():
            opts = base.copy()
            opts[opt] = val

            series_filter = filters.make_series_filter(**opts)

            self.assertTrue(series_filter(always_match_series),
                            msg="Failed on opt, val ({}, {})"
                            .format(opt, val))
            self.assertFalse(series_filter(never_match_series),
                             msg="Failed on opt, val ({}, {})"
                             .format(opt, val))

        for opt, val in inv_opt_set.items():
            opts = base.copy()
            opts[opt] = val
            series_filter = filters.make_test_run_filter(**opts)

            self.assertFalse(series_filter(always_match_series),
                             msg="Failed on opt, val ({}, {})"
                             .format(opt, val))
            self.assertTrue(series_filter(never_match_series),
                            msg="Failed on opt, val ({}, {})"
                            .format(opt, val))
Example #6
0
def arg_filtered_tests(pav_cfg,
                       args: argparse.Namespace,
                       verbose: TextIO = None) -> List[int]:
    """Search for test runs that match based on the argument values in args,
    and return a list of matching test id's.

    Note: I know this violates the idea that we shouldn't be passing a
    generic object around and just using random bits of an undefined interface.
    BUT:

    1. The interface is well defined, by `filters.add_test_filter_args`.
    2. All of the used bits are *ALWAYS* used, so any errors will pop up
       immediately in unit tests.

    :param pav_cfg: The Pavilion config.
    :param args: An argument namespace with args defined by
        `filters.add_test_filter_args`, plus one additional `tests` argument
        that should contain a list of test id's, series id's, or the 'last'
        keyword.
    :param verbose: A file like object to report test search status.
    :return: A list of test id ints.
    """

    limit = args.limit

    filter_func = filters.make_test_run_filter(
        complete=args.complete,
        incomplete=args.incomplete,
        passed=args.passed,
        failed=args.failed,
        name=args.name,
        user=args.user,
        sys_name=args.sys_name,
        older_than=args.older_than,
        newer_than=args.newer_than,
        show_skipped=args.show_skipped,
    )

    order_func, order_asc = filters.get_sort_opts(
        sort_name=args.sort_by,
        choices=filters.TEST_SORT_FUNCS,
    )

    if args.tests:
        test_paths = test_list_to_paths(pav_cfg, args.tests)

        if args.disable_filter:
            test_ids = dir_db.paths_to_ids(test_paths)
        else:
            tests = dir_db.select_from(paths=test_paths,
                                       transform=test_run_attr_transform,
                                       filter_func=filter_func,
                                       order_func=order_func,
                                       order_asc=order_asc,
                                       limit=limit).data
            test_ids = [test['id'] for test in tests]

    else:
        tests = dir_db.select(id_dir=pav_cfg.working_dir / 'test_runs',
                              transform=test_run_attr_transform,
                              filter_func=filter_func,
                              order_func=order_func,
                              order_asc=order_asc,
                              verbose=verbose,
                              limit=limit).data
        test_ids = [test['id'] for test in tests]

    return test_ids