1717from baybe ._optional .info import CHEM_INSTALLED , POLARS_INSTALLED
1818from baybe .constraints import SubSelectionCondition
1919from baybe .constraints import base as base_module
20+ from baybe .constraints import discrete as discrete_module
2021from baybe .constraints .discrete import (
22+ DiscreteDegeneracyConstraint ,
2123 DiscreteExcludeConstraint ,
2224 DiscreteSelectionConstraint ,
2325)
@@ -603,23 +605,6 @@ def test_discrete_exclude_constraint_deserialization(annotation):
603605 assert result == ref
604606
605607
606- def test_concrete_constraint_rejects_mismatched_type ():
607- """Structuring into a concrete class rejects a mismatched ``type`` field."""
608- from baybe .constraints .discrete import (
609- DiscreteCardinalityConstraint ,
610- )
611- from baybe .serialization import converter
612-
613- payload = {
614- "type" : "DiscreteSelectionConstraint" ,
615- "parameters" : ["A" ],
616- "conditions" : [{"type" : "SubSelectionCondition" , "selection" : ["a" ]}],
617- "combiner" : "AND" ,
618- }
619- with pytest .raises (ValueError , match = "does not match the target" ):
620- converter .structure (payload , DiscreteCardinalityConstraint )
621-
622-
623608@pytest .mark .parametrize (
624609 ("legacy_name" , "kwargs" , "expected" ),
625610 [
@@ -639,22 +624,16 @@ def test_concrete_constraint_rejects_mismatched_type():
639624)
640625def test_degeneracy_constraint_deprecation (legacy_name , kwargs , expected ):
641626 """Deprecated degeneracy constraints map to DiscreteDegeneracyConstraint."""
642- import baybe .constraints .discrete as m
643- from baybe .constraints .base import DiscreteFilteringConstraint
644- from baybe .constraints .discrete import DiscreteDegeneracyConstraint
645- from baybe .serialization import converter
646-
647- # Construction path: warns and returns correctly configured new object
648627 with pytest .warns (DeprecationWarning , match = legacy_name ):
649- c = getattr (m , legacy_name )(** kwargs )
650- assert isinstance (c , DiscreteDegeneracyConstraint )
651- assert c .n_max_occurrences == expected ["n_max_occurrences" ]
652- assert c .exclude is expected ["exclude" ]
628+ c = getattr (discrete_module , legacy_name )(** kwargs )
629+ ref = DiscreteDegeneracyConstraint (
630+ parameters = kwargs ["parameters" ],
631+ n_max_occurrences = expected ["n_max_occurrences" ],
632+ exclude = expected ["exclude" ],
633+ )
634+ assert c == ref
653635
654- # Deserialization path: legacy type name maps to the new object
655636 result = converter .structure (
656- {"type" : legacy_name , ** kwargs }, DiscreteFilteringConstraint
637+ {"type" : legacy_name , ** kwargs }, base_module . DiscreteFilteringConstraint
657638 )
658- assert isinstance (result , DiscreteDegeneracyConstraint )
659- assert result .n_max_occurrences == expected ["n_max_occurrences" ]
660- assert result .exclude is expected ["exclude" ]
639+ assert result == ref
0 commit comments