forked from optuna/optuna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_imports.py
32 lines (24 loc) · 856 Bytes
/
test_imports.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
import pytest
from optuna._imports import try_import
def test_try_import_is_successful() -> None:
with try_import() as imports:
pass
assert imports.is_successful()
imports.check()
def test_try_import_is_successful_other_error() -> None:
with pytest.raises(NotImplementedError):
with try_import() as imports:
raise NotImplementedError
assert imports.is_successful() # No imports failed so `imports` is successful.
imports.check()
def test_try_import_not_successful() -> None:
with try_import() as imports:
raise ImportError
assert not imports.is_successful()
with pytest.raises(ImportError):
imports.check()
with try_import() as imports:
raise SyntaxError
assert not imports.is_successful()
with pytest.raises(ImportError):
imports.check()