def discover(self, reference, which_tests=loader.DiscoverMode.DEFAULT): avocado_suite = [] subtests_filter = None if reference is None: return [] if ':' in reference: reference, _subtests_filter = reference.split(':', 1) subtests_filter = re.compile(_subtests_filter) if (os.path.isfile(reference) and path.PathInspector(reference).has_exec_permission()): try: cmd = '%s -l' % (reference) result = process.run(cmd) except Exception as details: if which_tests == loader.DiscoverMode.ALL: return [(NotGLibTest, {"name": "%s: %s" % (reference, details)})] return [] for test_item in result.stdout.splitlines(): test_name = "%s:%s" % (reference, test_item) if subtests_filter and not subtests_filter.search(test_name): continue avocado_suite.append((GLibTest, {'name': test_name, 'executable': test_name})) if which_tests == loader.DiscoverMode.ALL and not avocado_suite: return [(NotGLibTest, {"name": "%s: No GLib-like tests found" % reference})] return avocado_suite
def discover_test(self, params): """ Try to discover and resolve a test. :param params: dictionary with test parameters. :type params: dict :return: a test factory (a pair of test class and test parameters) or `None`. """ test_name = test_path = params.get('id') if os.path.exists(test_path): if os.access(test_path, os.R_OK) is False: return (AccessDeniedPath, {'params': {'id': test_path}}) path_analyzer = path.PathInspector(test_path) if path_analyzer.is_python(): test_class, test_parameters = self._make_test(test_name, test_path, params) else: if os.access(test_path, os.X_OK): test_class, test_parameters = self._make_simple_test(test_path, params) else: test_class, test_parameters = self._make_not_a_test(test_path, params) else: if os.path.islink(test_path): try: if not os.path.isfile(os.readlink(test_path)): return BrokenSymlink, {'params': {'id': test_path}} except OSError: return AccessDeniedPath, {'params': {'id': test_path}} # Try to resolve test ID (keep compatibility) rel_path = '%s.py' % test_name test_path = os.path.join(data_dir.get_test_dir(), rel_path) if os.path.exists(test_path): test_class, test_parameters = self._make_test(rel_path, test_path, params) else: test_class, test_parameters = self._make_missing_test( test_name, params) return test_class, test_parameters