Skip to content

Commit

Permalink
test: add test_gpy_not_supported_on_py311_exception
Browse files Browse the repository at this point in the history
  • Loading branch information
marcofavorito authored and marcofavoritobi committed Aug 24, 2023
1 parent 24bc95e commit 72829de
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_samplers/test_gaussian_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""This module contains tests for the Gaussian process sampler."""
import unittest.mock
from typing import Optional, Tuple, cast

import numpy as np
import pytest
from numpy.typing import NDArray

from black_it._load_dependency import GPyNotSupportedOnPy311Exception
from black_it.samplers.gaussian_process import GaussianProcessSampler, _AcquisitionTypes
from black_it.search_space import SearchSpace
from tests.utils.base import no_gpy_installed, no_python311_for_gpy
Expand Down Expand Up @@ -151,3 +153,18 @@ def test_dependency_not_installed_error() -> None:
r"To solve the issue, you can install the extra 'gp-sampler': pip install black-it\[gp-sampler\]"
),
)


def test_gpy_not_supported_on_py311_exception() -> None:
"""Test the "GPyNotSupportedOnPy311Exception" exception in case the GPy package is not supported on Python 3.11."""
with unittest.mock.patch("sys.version_info", new=(3, 11, 0, "final", 0)):
generic_test_import_error(
module_dotted_path="black_it.samplers.gaussian_process",
import_error_global_variable_name="_GPY_IMPORT_ERROR",
component_initializer=lambda: GaussianProcessSampler(4),
expected_message_pattern=(
"The GaussianProcessSampler depends on 'GPy', which is not supported on Python 3.11; "
"see https://github.com/bancaditalia/black-it/issues/36"
),
expected_exception_cls=GPyNotSupportedOnPy311Exception,
)

0 comments on commit 72829de

Please sign in to comment.