Test the _print_step method.
()
| 145 | |
| 146 | |
| 147 | def test_step(): |
| 148 | """Test the _print_step method.""" |
| 149 | optimizer = BayesianOptimization(target_func, PBOUNDS, random_state=1) |
| 150 | |
| 151 | logger = ScreenLogger() |
| 152 | |
| 153 | # Register a point so we have something to log |
| 154 | optimizer.register(params={"p1": 1.5, "p2": 2.5}, target=4.0) |
| 155 | |
| 156 | # Test default color |
| 157 | step_str = logger._print_step( |
| 158 | optimizer._space.keys, optimizer._space.res()[-1], optimizer._space.params_config |
| 159 | ) |
| 160 | assert "|" in step_str |
| 161 | assert "1" in step_str # iteration |
| 162 | assert "4.0" in step_str # target value |
| 163 | |
| 164 | # Test with custom color |
| 165 | custom_color = Fore.RED |
| 166 | step_str_colored = logger._print_step( |
| 167 | optimizer._space.keys, optimizer._space.res()[-1], optimizer._space.params_config, color=custom_color |
| 168 | ) |
| 169 | assert custom_color in step_str_colored |
| 170 | |
| 171 | |
| 172 | def test_print_header(): |
nothing calls this directly
no test coverage detected