forked from pytorch/botorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_errors.py
46 lines (40 loc) · 1.56 KB
/
test_errors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
from botorch.exceptions.errors import (
BotorchError,
BotorchTensorDimensionError,
CandidateGenerationError,
InputDataError,
OptimizationTimeoutError,
UnsupportedError,
)
from botorch.utils.testing import BotorchTestCase
class TestBotorchExceptions(BotorchTestCase):
def test_botorch_exception_hierarchy(self):
self.assertIsInstance(BotorchError(), Exception)
self.assertIsInstance(CandidateGenerationError(), BotorchError)
self.assertIsInstance(InputDataError(), BotorchError)
self.assertIsInstance(UnsupportedError(), BotorchError)
self.assertIsInstance(BotorchTensorDimensionError(), BotorchError)
def test_raise_botorch_exceptions(self):
for ErrorClass in (
BotorchError,
BotorchTensorDimensionError,
CandidateGenerationError,
InputDataError,
UnsupportedError,
):
with self.assertRaises(ErrorClass):
raise ErrorClass("message")
def test_OptimizationTimeoutError(self):
error = OptimizationTimeoutError(
"message", current_x=np.array([1.0]), runtime=0.123
)
self.assertEqual(error.runtime, 0.123)
self.assertTrue(np.array_equal(error.current_x, np.array([1.0])))
with self.assertRaises(OptimizationTimeoutError):
raise error