[autotest] Extract _ComposedPredicate
BUG=chromium:672348
TEST=None
Change-Id: I66d40324a27950363cd05a94a7ba271190a72e7f
Reviewed-on: https://chromium-review.googlesource.com/452950
Commit-Ready: Allen Li <ayatane@chromium.org>
Tested-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Prathmesh Prabhu <pprabhu@chromium.org>
diff --git a/server/cros/dynamic_suite/suite.py b/server/cros/dynamic_suite/suite.py
index 36b855e..d931685 100644
--- a/server/cros/dynamic_suite/suite.py
+++ b/server/cros/dynamic_suite/suite.py
@@ -1670,7 +1670,7 @@
self.tests = find_and_parse_tests(
cf_getter,
- lambda control_data: all(f(control_data) for f in predicates),
+ _ComposedPredicate(predicates),
tag,
add_experimental=True,
forgiving_parser=forgiving_parser,
@@ -1679,6 +1679,32 @@
)
+class _ComposedPredicate(object):
+ """Return the composition of the predicates.
+
+ Predicates are functions that take a test control data object and
+ return True of that test is to be included. The returned
+ predicate's set is the intersection of all of the input predicates'
+ sets (it returns True if all predicates return True).
+ """
+
+ def __init__(self, predicates):
+ """Initialize instance.
+
+ @param predicates: Iterable of predicates.
+ """
+ self._predicates = list(predicates)
+
+ def __repr__(self):
+ return '{cls}({this._predicates!r})'.format(
+ cls=type(self).__qualname__,
+ this=self,
+ )
+
+ def __call__(self, control_data_):
+ return all(f(control_data_) for f in self._predicates)
+
+
def _is_nonexistent_board_error(e):
"""Return True if error is caused by nonexistent board label.