Conditions | 1 |
Total Lines | 30 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import copy |
||
107 | def test_catch_all_1(): |
||
108 | def objective_function(access): |
||
109 | x = y |
||
110 | a = 1 + "str" |
||
111 | math.sqrt(-10) |
||
112 | x = 1 / 0 |
||
113 | |||
114 | return 0, {"error": False} |
||
115 | |||
116 | catch_return = (np.nan, {"error": True}) |
||
117 | |||
118 | hyper = Hyperactive() |
||
119 | hyper.add_search( |
||
120 | objective_function, |
||
121 | search_space, |
||
122 | n_iter=100, |
||
123 | catch={ |
||
124 | NameError: catch_return, |
||
125 | TypeError: catch_return, |
||
126 | ValueError: catch_return, |
||
127 | ZeroDivisionError: catch_return, |
||
128 | }, |
||
129 | ) |
||
130 | hyper.run() |
||
131 | |||
132 | nan_ = hyper.search_data(objective_function)["score"].values[0] |
||
133 | error_ = hyper.search_data(objective_function)["error"].values[0] |
||
134 | |||
135 | assert math.isnan(nan_) |
||
136 | assert error_ == True |
||
137 |