コード例 #1
0
    def test_get_sort_opts(self):
        """Check the sort operation manager."""

        tests = []
        for i in range(20):
            test = self._quick_test()
            tests.append(test)

        ids = [test.id for test in tests]
        ids.sort()

        random.shuffle(tests)
        paths = [test.path for test in tests]

        # Check sorting in ascending direction
        sort, ascending = filters.get_sort_opts('id', filters.TEST_SORT_FUNCS)
        self.assertTrue(ascending)
        sorted_tests = dir_db.select_from(paths=paths,
                                          transform=TestAttributes,
                                          order_func=sort,
                                          order_asc=ascending)[0]
        self.assertEqual([t.id for t in sorted_tests], ids)

        # And descending.
        sort, ascending = filters.get_sort_opts('-id', filters.TEST_SORT_FUNCS)
        self.assertFalse(ascending)
        sorted_tests = dir_db.select_from(paths=paths,
                                          transform=TestAttributes,
                                          order_func=sort,
                                          order_asc=ascending)[0]
        self.assertEqual([t.id for t in sorted_tests], list(reversed(ids)))
コード例 #2
0
ファイル: list_cmd.py プロジェクト: coneheadusa/pavilion2
    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,
        )
コード例 #3
0
ファイル: cmd_utils.py プロジェクト: paulbry/pavilion2
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