|
3 | 3 | import pytest |
4 | 4 | from pytest import param |
5 | 5 |
|
6 | | -from baybe.objectives.single import SingleTargetObjective |
7 | | -from baybe.targets.enum import TargetMode |
8 | | -from baybe.targets.numerical import NumericalTarget |
9 | 6 | from baybe.utils.metadata import MeasurableMetadata, Metadata, to_metadata |
10 | 7 |
|
11 | 8 |
|
@@ -68,100 +65,3 @@ def test_invalid_input_conversion(invalid_input): |
68 | 65 | TypeError, match="must be a dictionary or a 'Metadata' instance." |
69 | 66 | ): |
70 | 67 | to_metadata(invalid_input, Metadata) |
71 | | - |
72 | | - |
73 | | -class TestTargetMetadataValidation: |
74 | | - """Validation tests for target metadata.""" |
75 | | - |
76 | | - def _create_target(self, **kwargs) -> NumericalTarget: |
77 | | - """Create a standard NumericalTarget for testing.""" |
78 | | - return NumericalTarget( |
79 | | - name="test", |
80 | | - mode=TargetMode.MAX, |
81 | | - transformation=None, |
82 | | - **kwargs, |
83 | | - ) |
84 | | - |
85 | | - def test_target_invalid_metadata_type(self): |
86 | | - """Creating target with invalid metadata type raises error.""" |
87 | | - with pytest.raises( |
88 | | - TypeError, match="must be a dictionary or a 'MeasurableMetadata' instance" |
89 | | - ): |
90 | | - self._create_target(metadata="invalid_string") |
91 | | - |
92 | | - def test_target_metadata_with_invalid_unit(self): |
93 | | - """Target metadata with invalid unit type raises error.""" |
94 | | - with pytest.raises(TypeError, match="must be <class 'str'>"): |
95 | | - self._create_target(metadata={"unit": 123}) # Invalid unit type |
96 | | - |
97 | | - def test_target_metadata_with_unit_field_separation(self): |
98 | | - """Target metadata should automatically separate unit from misc.""" |
99 | | - # This test shows that unit is automatically separated from misc |
100 | | - target = self._create_target( |
101 | | - metadata={"description": "test", "unit": "kg", "extra": "value"} |
102 | | - ) |
103 | | - # The unit should be extracted to the unit field |
104 | | - assert target.unit == "kg" |
105 | | - assert target.description == "test" |
106 | | - # Only extra should remain in misc |
107 | | - assert target.metadata is not None |
108 | | - assert target.metadata.misc == {"extra": "value"} |
109 | | - |
110 | | - def test_target_direct_metadata_with_unit_in_misc(self): |
111 | | - """Direct metadata creation with unit in misc should raise error.""" |
112 | | - with pytest.raises(ValueError, match="fields: {'unit'}"): |
113 | | - MeasurableMetadata(description="test", misc={"unit": "kg"}) |
114 | | - |
115 | | - |
116 | | -class TestObjectiveMetadataValidation: |
117 | | - """Validation tests for objective metadata.""" |
118 | | - |
119 | | - def _create_target(self, **kwargs) -> NumericalTarget: |
120 | | - """Create a standard NumericalTarget for testing.""" |
121 | | - return NumericalTarget( |
122 | | - name="test", |
123 | | - mode=TargetMode.MAX, |
124 | | - transformation=None, |
125 | | - **kwargs, |
126 | | - ) |
127 | | - |
128 | | - def test_objective_invalid_metadata_type(self): |
129 | | - """Creating objective with invalid metadata type raises error.""" |
130 | | - target = self._create_target() |
131 | | - |
132 | | - with pytest.raises( |
133 | | - TypeError, match="must be a dictionary or a 'Metadata' instance" |
134 | | - ): |
135 | | - SingleTargetObjective(target=target, metadata=["invalid_list"]) |
136 | | - |
137 | | - def test_objective_metadata_field_separation(self): |
138 | | - """Objective metadata should automatically separate description from misc.""" |
139 | | - target = self._create_target() |
140 | | - |
141 | | - # Test that description is automatically separated from other fields |
142 | | - objective = SingleTargetObjective( |
143 | | - target=target, |
144 | | - metadata={ |
145 | | - "description": "test objective", |
146 | | - "priority": "high", |
147 | | - "algorithm": "GP", |
148 | | - }, |
149 | | - ) |
150 | | - |
151 | | - assert objective.description == "test objective" |
152 | | - assert objective.metadata is not None |
153 | | - assert objective.metadata.misc == {"priority": "high", "algorithm": "GP"} |
154 | | - |
155 | | - def test_objective_direct_metadata_with_description_in_misc(self): |
156 | | - """Direct metadata creation with description in misc should raise error.""" |
157 | | - with pytest.raises(ValueError, match="fields: {'description'}"): |
158 | | - Metadata(misc={"description": "should not be here"}) |
159 | | - |
160 | | - def test_none_metadata_raises_error(self): |
161 | | - """Test that passing None for metadata raises TypeError.""" |
162 | | - from baybe.parameters.numerical import NumericalDiscreteParameter |
163 | | - |
164 | | - with pytest.raises( |
165 | | - TypeError, match="must be a dictionary or a 'MeasurableMetadata' instance" |
166 | | - ): |
167 | | - NumericalDiscreteParameter(name="test", values=(1, 2, 3), metadata=None) |
0 commit comments