@@ -105,12 +105,15 @@ def generate_tests(self, effects: dict, mutates: dict, estimators: dict, f_flag:
105
105
abstract_test = self ._create_abstract_test_case (test , mutates , effects )
106
106
107
107
concrete_tests , dummy = abstract_test .generate_concrete_tests (5 , 0.05 )
108
- logger .info ("Executing test: %s" , test ["name" ])
109
- logger .info (abstract_test )
110
- logger .info ([abstract_test .treatment_variable .name , abstract_test .treatment_variable .distribution ])
111
- logger .info ("Number of concrete tests for test case: %s" , str (len (concrete_tests )))
112
108
failures = self ._execute_tests (concrete_tests , estimators , test , f_flag )
113
- logger .info ("%s/%s failed for %s\n " , failures , len (concrete_tests ), test ["name" ])
109
+ msg = f"Executing test: { test ['name' ]} \n " + \
110
+ f"abstract_test \n " + \
111
+ f"{ abstract_test } \n " + \
112
+ f"{ abstract_test .treatment_variable .name } ,{ abstract_test .treatment_variable .distribution } \n " + \
113
+ f"Number of concrete tests for test case: { str (len (concrete_tests ))} "
114
+
115
+ self .append_to_file (msg , logging .INFO )
116
+
114
117
115
118
def _execute_tests (self , concrete_tests , estimators , test , f_flag ):
116
119
failures = 0
@@ -120,6 +123,7 @@ def _execute_tests(self, concrete_tests, estimators, test, f_flag):
120
123
failures += 1
121
124
return failures
122
125
126
+
123
127
def _json_parse (self ):
124
128
"""Parse a JSON input file into inputs, outputs, metas and a test plan"""
125
129
with open (self .input_paths .json_path , encoding = "utf-8" ) as f :
@@ -129,6 +133,7 @@ def _json_parse(self):
129
133
self .data .append (df )
130
134
self .data = pd .concat (self .data )
131
135
136
+
132
137
def _populate_metas (self ):
133
138
"""
134
139
Populate data with meta-variable values and add distributions to Causal Testing Framework Variables
@@ -141,7 +146,8 @@ def _populate_metas(self):
141
146
fitter .fit ()
142
147
(dist , params ) = list (fitter .get_best (method = "sumsquare_error" ).items ())[0 ]
143
148
var .distribution = getattr (scipy .stats , dist )(** params )
144
- logger .info (var .name + f" { dist } ({ params } )" )
149
+ self .append_to_file (var .name + f" { dist } ({ params } )" , logging .INFO )
150
+
145
151
146
152
def _execute_test_case (self , causal_test_case : CausalTestCase , estimator : Estimator , f_flag : bool ) -> bool :
147
153
"""Executes a singular test case, prints the results and returns the test case result
@@ -175,9 +181,11 @@ def _execute_test_case(self, causal_test_case: CausalTestCase, estimator: Estima
175
181
)
176
182
if not test_passes :
177
183
failed = True
178
- self .append_to_file (f"FAILED- expected { causal_test_case .expected_causal_effect } , got { result_string } " , logging .WARNING )
184
+ self .append_to_file (f"FAILED- expected { causal_test_case .expected_causal_effect } , got { result_string } " ,
185
+ logging .WARNING )
179
186
return failed
180
187
188
+
181
189
def _setup_test (self , causal_test_case : CausalTestCase , estimator : Estimator ) -> tuple [CausalTestEngine , Estimator ]:
182
190
"""Create the necessary inputs for a single test case
183
191
:param causal_test_case: The concrete test case to be executed
@@ -206,23 +214,28 @@ def _setup_test(self, causal_test_case: CausalTestCase, estimator: Estimator) ->
206
214
207
215
return causal_test_engine , estimation_model
208
216
217
+
209
218
def add_modelling_assumptions (self , estimation_model : Estimator ): # pylint: disable=unused-argument
210
219
"""Optional abstract method where user functionality can be written to determine what assumptions are required
211
220
for specific test cases
212
221
:param estimation_model: estimator model instance for the current running test.
213
222
"""
214
223
return
224
+
225
+
215
226
def append_to_file (self , line : str , log_level : int = None ):
216
227
with open (self .output_path , "a" ) as f :
217
- f .write (' \n ' . join ( line ) )
228
+ f .write (line + " \n " )
218
229
if log_level :
219
230
logger .log (level = log_level , msg = line )
220
231
232
+
221
233
@staticmethod
222
234
def check_file_exists (output_path : Path , overwrite : bool ):
223
235
if not overwrite and output_path .is_file ():
224
236
raise FileExistsError (f"Chosen file output ({ output_path } ) already exists" )
225
237
238
+
226
239
@staticmethod
227
240
def get_args (test_args = None ) -> argparse .Namespace :
228
241
"""Command-line arguments
@@ -298,4 +311,4 @@ def __init__(self, inputs: list[dict], outputs: list[dict], metas: list[dict]):
298
311
299
312
def __iter__ (self ):
300
313
for var in self .inputs + self .outputs + self .metas :
301
- yield var
314
+ yield var
0 commit comments