@@ -99,7 +99,7 @@ def test_f_flag(self):
99
99
effects = {"NoEffect" : NoEffect ()}
100
100
mutates = {
101
101
"Increase" : lambda x : self .json_class .scenario .treatment_variables [x ].z3
102
- > self .json_class .scenario .variables [x ].z3
102
+ > self .json_class .scenario .variables [x ].z3
103
103
}
104
104
estimators = {"LinearRegressionEstimator" : LinearRegressionEstimator }
105
105
with self .assertRaises (StatisticsError ):
@@ -149,7 +149,7 @@ def test_run_json_tests_from_json(self):
149
149
effects = {"NoEffect" : NoEffect ()}
150
150
mutates = {
151
151
"Increase" : lambda x : self .json_class .scenario .treatment_variables [x ].z3
152
- > self .json_class .scenario .variables [x ].z3
152
+ > self .json_class .scenario .variables [x ].z3
153
153
}
154
154
estimators = {"LinearRegressionEstimator" : LinearRegressionEstimator }
155
155
@@ -176,7 +176,7 @@ def test_generate_tests_from_json_no_dist(self):
176
176
effects = {"NoEffect" : NoEffect ()}
177
177
mutates = {
178
178
"Increase" : lambda x : self .json_class .scenario .treatment_variables [x ].z3
179
- > self .json_class .scenario .variables [x ].z3
179
+ > self .json_class .scenario .variables [x ].z3
180
180
}
181
181
estimators = {"LinearRegressionEstimator" : LinearRegressionEstimator }
182
182
@@ -206,7 +206,7 @@ def test_formula_in_json_test(self):
206
206
effects = {"Positive" : Positive ()}
207
207
mutates = {
208
208
"Increase" : lambda x : self .json_class .scenario .treatment_variables [x ].z3
209
- > self .json_class .scenario .variables [x ].z3
209
+ > self .json_class .scenario .variables [x ].z3
210
210
}
211
211
estimators = {"LinearRegressionEstimator" : LinearRegressionEstimator }
212
212
@@ -259,7 +259,7 @@ def test_concrete_generate_params(self):
259
259
effects = {"NoEffect" : NoEffect ()}
260
260
mutates = {
261
261
"Increase" : lambda x : self .json_class .scenario .treatment_variables [x ].z3
262
- > self .json_class .scenario .variables [x ].z3
262
+ > self .json_class .scenario .variables [x ].z3
263
263
}
264
264
estimators = {"LinearRegressionEstimator" : LinearRegressionEstimator }
265
265
@@ -272,49 +272,91 @@ def test_concrete_generate_params(self):
272
272
self .assertIn ("failed" , temp_out [- 1 ])
273
273
274
274
def test_no_data_provided (self ):
275
+ json_class = JsonUtility ("temp_out.txt" , True )
276
+ json_class .set_paths (self .json_path , self .dag_path )
277
+
278
+ with self .assertRaises (ValueError ):
279
+ json_class .setup (self .scenario )
280
+
281
+ def test_estimator_formula_type_check (self ):
275
282
example_test = {
276
283
"tests" : [
277
284
{
278
285
"name" : "test1" ,
279
286
"mutations" : {"test_input" : "Increase" },
280
- "estimator" : "LinearRegressionEstimator " ,
287
+ "estimator" : "CausalForestEstimator " ,
281
288
"estimate_type" : "ate" ,
282
289
"effect_modifiers" : [],
283
- "expected_effect" : {"test_output" : "NoEffect " },
290
+ "expected_effect" : {"test_output" : "Positive " },
284
291
"skip" : False ,
292
+ "formula" : "test_output ~ test_input" ,
285
293
}
286
294
]
287
295
}
288
- json_class = JsonUtility ("temp_out.txt" , True )
289
- json_class .set_paths (self .json_path , self .dag_path )
296
+ self .json_class .test_plan = example_test
290
297
291
- with self .assertRaises (ValueError ):
292
- json_class .setup ( self . scenario )
298
+ with self .assertRaises (TypeError ):
299
+ self . json_class .run_json_tests ( effects = effects , mutates = mutates , estimators = estimators , f_flag = False )
293
300
294
- def test_estimator_formula_type_check (self ):
301
+ effects = {"Positive" : Positive ()}
302
+ mutates = {
303
+ "Increase" : lambda x : self .json_class .scenario .treatment_variables [x ].z3
304
+ > self .json_class .scenario .variables [x ].z3
305
+ }
306
+ estimators = {"CausalForestEstimator" : CausalForestEstimator }
307
+
308
+ def test_constructive_back_door_not_met (self ):
295
309
example_test = {
296
310
"tests" : [
297
311
{
298
312
"name" : "test1" ,
299
- "mutations" : {"test_input " : "Increase" },
300
- "estimator" : "CausalForestEstimator " ,
313
+ "mutations" : {"X " : "Increase" },
314
+ "estimator" : "LinearRegressionEstimator " ,
301
315
"estimate_type" : "ate" ,
302
316
"effect_modifiers" : [],
303
- "expected_effect" : {"test_output " : "Positive " },
317
+ "expected_effect" : {"Y " : "NoEffect " },
304
318
"skip" : False ,
305
- "formula" : "test_output ~ test_input " ,
319
+ "formula" : "Y ~ X " ,
306
320
}
307
321
]
308
322
}
309
- self .json_class .test_plan = example_test
310
- effects = {"Positive" : Positive ()}
323
+ inputs = [
324
+ Input ("X" , int ),
325
+ Input ("Z" , int )
326
+ ]
327
+ outputs = [
328
+ Output ("Y" , int )
329
+ ]
330
+ variables = inputs + outputs
331
+ modelling_scenario = Scenario (variables )
332
+ modelling_scenario .setup_treatment_variables ()
333
+ json_utility = JsonUtility ("temp_out.txt" , True )
334
+ test_data_dir_path = Path ("tests/resources/data" )
335
+ dag_path = str (test_data_dir_path / "dag_not_descendent.dot" )
336
+ data_path = [str (test_data_dir_path / "not_descendent.csv" )]
337
+
338
+ input_dict_list = [
339
+ {"name" : "X" , "datatype" : float },
340
+ {"name" : "Z" , "datatype" : float },
341
+ ]
342
+ output_dict_list = [{"name" : "Y" , "datatype" : float }]
343
+ variables = CausalVariables (
344
+ inputs = input_dict_list , outputs = output_dict_list , metas = None
345
+ )
346
+
347
+ effects = {"NoEffect" : NoEffect ()}
311
348
mutates = {
312
- "Increase" : lambda x : self . json_class .scenario .treatment_variables [x ].z3
313
- > self . json_class .scenario .variables [x ].z3
349
+ "Increase" : lambda x : json_utility .scenario .treatment_variables [x ].z3
350
+ > json_utility .scenario .variables [x ].z3
314
351
}
315
- estimators = {"CausalForestEstimator" : CausalForestEstimator }
316
- with self .assertRaises (TypeError ):
317
- self .json_class .run_json_tests (effects = effects , mutates = mutates , estimators = estimators , f_flag = False )
352
+ estimators = {"LinearRegressionEstimator" : LinearRegressionEstimator }
353
+
354
+ scenario = Scenario (variables = variables , constraints = None )
355
+ json_utility .set_paths (self .json_path , dag_path , data_path )
356
+ json_utility .setup (scenario )
357
+ json_utility .test_plan = example_test
358
+ with self .assertRaises (ValueError ):
359
+ json_utility .run_json_tests (effects = effects , mutates = mutates , estimators = estimators , f_flag = False )
318
360
319
361
def tearDown (self ) -> None :
320
362
remove_temp_dir_if_existent ()
0 commit comments