Conditions | 1 |
Total Lines | 28 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import copy |
||
89 | def test_catch_all_1(): |
||
90 | def objective_function(access): |
||
91 | a = 1 + "str" |
||
92 | math.sqrt(-10) |
||
93 | x = 1 / 0 |
||
94 | |||
95 | return 0, {"error": False} |
||
96 | |||
97 | catch_return = (np.nan, {"error": True}) |
||
98 | |||
99 | hyper = Hyperactive() |
||
100 | hyper.add_search( |
||
101 | objective_function, |
||
102 | search_space, |
||
103 | n_iter=100, |
||
104 | catch={ |
||
105 | TypeError: catch_return, |
||
106 | ValueError: catch_return, |
||
107 | ZeroDivisionError: catch_return, |
||
108 | }, |
||
109 | ) |
||
110 | hyper.run() |
||
111 | |||
112 | nan_ = hyper.search_data(objective_function)["score"].values[0] |
||
113 | error_ = hyper.search_data(objective_function)["error"].values[0] |
||
114 | |||
115 | assert math.isnan(nan_) |
||
116 | assert error_ == True |
||
117 |