[release] Accommodate multiple filters with same attribute#57577
[release] Accommodate multiple filters with same attribute#57577
Conversation
|
test run: https://buildkite.com/ray-project/release/builds/62511 with 2 prefix filters |
| for attr, values in test_filters.items(): | ||
| # Check if at least one value matches for this attribute (OR logic) | ||
| attr_matched = False | ||
| for value in values: | ||
| # Only prefix filter doesn't use regex | ||
| if attr == "prefix": | ||
| if test.get_name().startswith(value): | ||
| attr_matched = True | ||
| break | ||
| else: # Match filters using regex | ||
| attr_value = _unflattened_lookup(test, attr) or "" | ||
| if re.match(value, attr_value): | ||
| attr_matched = True | ||
| break | ||
|
|
||
| # If none of the values matched for this attribute, skip this test | ||
| if not attr_matched: | ||
| attr_mismatch = True | ||
| break |
There was a problem hiding this comment.
The current implementation for filtering tests can be made more concise and performant.
The nested loop structure can be simplified using Python's built-in any() function, which improves readability. Additionally, _unflattened_lookup is called on every iteration of the inner loop, which is inefficient. By using any(), we can ensure it's called just once per attribute.
Here's a suggested refactoring:
for attr, values in test_filters.items():
if attr == "prefix":
attr_matched = any(test.get_name().startswith(value) for value in values)
else:
attr_value = _unflattened_lookup(test, attr) or ""
attr_matched = any(re.match(value, attr_value) for value in values)
if not attr_matched:
attr_mismatch = True
break| # Support multiple values for the same attribute (OR logic) | ||
| if parts[0] not in test_filters: | ||
| test_filters[parts[0]] = [] | ||
| test_filters[parts[0]].append(parts[1]) |
| # Test OR logic with AND across attributes | ||
| filtered = self._filter_names( | ||
| tests, | ||
| frequency=Frequency.NIGHTLY, | ||
| test_filters={ | ||
| "name": ["^test_1$", "^test_3$"], | ||
| "team": ["team_1", "team_2"], | ||
| }, | ||
| ) | ||
| self.assertSequenceEqual(filtered, [("test_1", False), ("test_3", False)]) |
There was a problem hiding this comment.
The new test case for 'OR logic with AND across attributes' is good, but it could be stronger. Both test_1 and test_3 match the team filter ["team_1", "team_2"], so it doesn't fully test the AND part of the logic where one of the OR conditions for name is met but the AND condition for team is not.
I suggest adding another test case to cover this scenario, for example by filtering for a team that only one of the tests belongs to. This will ensure the filtering logic is robust.
# Test OR logic with AND across attributes
filtered = self._filter_names(
tests,
frequency=Frequency.NIGHTLY,
test_filters={
"name": ["^test_1$", "^test_3$"],
"team": ["team_1", "team_2"],
},
)
self.assertSequenceEqual(filtered, [("test_1", False), ("test_3", False)])
# Test OR logic with AND across attributes (negative case)
filtered = self._filter_names(
tests,
frequency=Frequency.NIGHTLY,
test_filters={"name": ["^test_1$", "^test_3$"], "team": ["team_1"]},
)
self.assertSequenceEqual(filtered, [("test_1", False)])| test_collection: List[Test], | ||
| frequency: Frequency, | ||
| test_filters: Optional[Dict[str, str]] = None, | ||
| test_filters: Optional[Dict[str, list]] = None, |
There was a problem hiding this comment.
is this list a List[str]?
There was a problem hiding this comment.
this does not seem to be fixed..
…ct#57577) and allow a test to match with one of filters in the same attribute instead of saying it's mismatch if any of the filter fail Signed-off-by: kevin <kevin@anyscale.com>
…ct#57577) and allow a test to match with one of filters in the same attribute instead of saying it's mismatch if any of the filter fail Signed-off-by: kevin <kevin@anyscale.com>
…ct#57577) and allow a test to match with one of filters in the same attribute instead of saying it's mismatch if any of the filter fail Signed-off-by: kevin <kevin@anyscale.com> Signed-off-by: Josh Kodi <joshkodi@gmail.com>
…ct#57577) and allow a test to match with one of filters in the same attribute instead of saying it's mismatch if any of the filter fail Signed-off-by: kevin <kevin@anyscale.com>
and allow a test to match with one of filters in the same attribute instead of saying it's mismatch if any of the filter fail Signed-off-by: kevin <kevin@anyscale.com>
…ct#57577) and allow a test to match with one of filters in the same attribute instead of saying it's mismatch if any of the filter fail Signed-off-by: kevin <kevin@anyscale.com>
…ct#57577) and allow a test to match with one of filters in the same attribute instead of saying it's mismatch if any of the filter fail Signed-off-by: kevin <kevin@anyscale.com> Signed-off-by: xgui <xgui@anyscale.com>
and allow a test to match with one of filters in the same attribute instead of saying it's mismatch if any of the filter fail Signed-off-by: kevin <kevin@anyscale.com> Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
…ct#57577) and allow a test to match with one of filters in the same attribute instead of saying it's mismatch if any of the filter fail Signed-off-by: kevin <kevin@anyscale.com>
…ct#57577) and allow a test to match with one of filters in the same attribute instead of saying it's mismatch if any of the filter fail Signed-off-by: kevin <kevin@anyscale.com> Signed-off-by: Aydin Abiar <aydin@anyscale.com>
…ct#57577) and allow a test to match with one of filters in the same attribute instead of saying it's mismatch if any of the filter fail Signed-off-by: kevin <kevin@anyscale.com> Signed-off-by: Future-Outlier <eric901201@gmail.com>
and allow a test to match with one of filters in the same attribute instead of saying it's mismatch if any of the filter fail