File tree Expand file tree Collapse file tree
pyrit/datasets/seed_datasets Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -269,7 +269,9 @@ def _validate(self) -> None:
269269 # over criteria in _match_filter_to_metadata vacuously False, so the filter
270270 # would silently match no dataset at all.
271271 if not self .criteria :
272- raise ValueError ("'criteria' must contain at least one metadata criterion." )
272+ raise ValueError (
273+ "'criteria' must contain at least one criterion. Omit 'criteria' for an unconstrained filter."
274+ )
273275
274276 # An empty set is not a filter. Without strict_match nothing can overlap with it,
275277 # and with strict_match nothing can be outside it, so the same filter would match
Original file line number Diff line number Diff line change @@ -375,3 +375,18 @@ def test_tags_values(self):
375375 def test_harm_categories_values (self ):
376376 f = SeedDatasetFilter (harm_categories = {"violence" , "cybercrime" })
377377 assert "violence" in f .criteria [0 ].harm_categories
378+
379+
380+ @pytest .mark .parametrize ("strict_match" , [False , True ])
381+ def test_empty_criteria_raises (strict_match : bool ) -> None :
382+ with pytest .raises (ValueError , match = "at least one criterion" ):
383+ SeedDatasetFilter (criteria = [], strict_match = strict_match )
384+
385+
386+ def test_empty_criteria_with_kwargs_preserves_conflicting_arguments_error () -> None :
387+ with pytest .raises (ValueError , match = "Cannot pass both" ):
388+ SeedDatasetFilter (criteria = [], tags = {"safety" })
389+
390+
391+ def test_unconstrained_criterion_preserves_default_filter () -> None :
392+ assert SeedDatasetFilter (criteria = [SeedDatasetMetadata ()]).criteria == SeedDatasetFilter ().criteria
You can’t perform that action at this time.
0 commit comments