Skip to content

Commit

Permalink
fix: import error from exception module (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday authored Sep 30, 2024
1 parent 10ef3be commit 4646cdf
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions tests/test_acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from scipy.spatial.distance import pdist
from sklearn.gaussian_process import GaussianProcessRegressor

from bayes_opt import acquisition
from bayes_opt import acquisition, exception
from bayes_opt.constraint import ConstraintModel
from bayes_opt.target_space import TargetSpace

Expand Down Expand Up @@ -94,7 +94,7 @@ def test_upper_confidence_bound(gp, target_space, random_state):

# Test that the suggest method raises an error if the GP is unfitted
with pytest.raises(
acquisition.TargetSpaceEmptyError, match="Cannot suggest a point without previous samples"
exception.TargetSpaceEmptyError, match="Cannot suggest a point without previous samples"
):
acq.suggest(gp=gp, target_space=target_space)

Expand Down Expand Up @@ -122,7 +122,7 @@ def test_upper_confidence_bound_with_constraints(gp, constrained_target_space, r
acq = acquisition.UpperConfidenceBound(random_state=random_state)

constrained_target_space.register(params={"x": 2.5, "y": 0.5}, target=3.0, constraint_value=0.5)
with pytest.raises(acquisition.ConstraintNotSupportedError):
with pytest.raises(exception.ConstraintNotSupportedError):
acq.suggest(gp=gp, target_space=constrained_target_space)


Expand Down Expand Up @@ -157,11 +157,11 @@ def test_probability_of_improvement_with_constraints(gp, constrained_target_spac
with pytest.raises(ValueError, match="y_max is not set"):
acq.base_acq(0.0, 0.0)

with pytest.raises(acquisition.TargetSpaceEmptyError):
with pytest.raises(exception.TargetSpaceEmptyError):
acq.suggest(gp=gp, target_space=constrained_target_space)

constrained_target_space.register(params={"x": 2.5, "y": 0.5}, target=3.0, constraint_value=3.0)
with pytest.raises(acquisition.NoValidPointRegisteredError):
with pytest.raises(exception.NoValidPointRegisteredError):
acq.suggest(gp=gp, target_space=constrained_target_space)

constrained_target_space.register(params={"x": 1.0, "y": 0.0}, target=1.0, constraint_value=1.0)
Expand Down Expand Up @@ -199,11 +199,11 @@ def test_expected_improvement_with_constraints(gp, constrained_target_space, ran
with pytest.raises(ValueError, match="y_max is not set"):
acq.base_acq(0.0, 0.0)

with pytest.raises(acquisition.TargetSpaceEmptyError):
with pytest.raises(exception.TargetSpaceEmptyError):
acq.suggest(gp=gp, target_space=constrained_target_space)

constrained_target_space.register(params={"x": 2.5, "y": 0.5}, target=3.0, constraint_value=3.0)
with pytest.raises(acquisition.NoValidPointRegisteredError):
with pytest.raises(exception.NoValidPointRegisteredError):
acq.suggest(gp=gp, target_space=constrained_target_space)

constrained_target_space.register(params={"x": 1.0, "y": 0.0}, target=1.0, constraint_value=1.0)
Expand Down Expand Up @@ -250,11 +250,11 @@ def test_constant_liar_with_constraints(gp, constrained_target_space, random_sta
base_acq = acquisition.UpperConfidenceBound(random_state=random_state)
acq = acquisition.ConstantLiar(base_acquisition=base_acq, random_state=random_state)

with pytest.raises(acquisition.TargetSpaceEmptyError):
with pytest.raises(exception.TargetSpaceEmptyError):
acq.suggest(gp=gp, target_space=constrained_target_space)

constrained_target_space.register(params={"x": 2.5, "y": 0.5}, target=3.0, constraint_value=0.5)
with pytest.raises(acquisition.ConstraintNotSupportedError):
with pytest.raises(exception.ConstraintNotSupportedError):
acq.suggest(gp=gp, target_space=constrained_target_space)

mean = random_state.rand(10)
Expand Down Expand Up @@ -338,7 +338,7 @@ def test_gphedge_integration(gp, target_space, random_state):

acq = acquisition.GPHedge(base_acquisitions=base_acquisitions, random_state=random_state)
assert acq.base_acquisitions == base_acquisitions
with pytest.raises(acquisition.TargetSpaceEmptyError):
with pytest.raises(exception.TargetSpaceEmptyError):
acq.suggest(gp=gp, target_space=target_space)
target_space.register(params={"x": 2.5, "y": 0.5}, target=3.0)

Expand Down

0 comments on commit 4646cdf

Please sign in to comment.