4
4
import csv
5
5
import json
6
6
7
+ from causal_testing .testing .estimators import LinearRegressionEstimator
7
8
from causal_testing .testing .causal_test_outcome import NoEffect
8
9
from tests .test_helpers import create_temp_dir_if_non_existent , remove_temp_dir_if_existent
9
10
from causal_testing .json_front .json_class import JsonUtility
12
13
from causal_testing .specification .causal_specification import CausalSpecification
13
14
from causal_testing .generation .abstract_causal_test_case import AbstractCausalTestCase
14
15
16
+
15
17
class TestJsonClass (unittest .TestCase ):
16
18
"""Test the CausalTestEngine workflow using observational data.
17
19
@@ -29,7 +31,7 @@ def setUp(self) -> None:
29
31
self .data_path = temp_dir_path / data_file_name
30
32
setup_files (self .json_path , self .data_path , self .dag_path )
31
33
self .json_class = JsonUtility ("logs.log" )
32
- self .example_distribution = scipy .stats .uniform (0 , 10 )
34
+ self .example_distribution = scipy .stats .uniform (1 , 10 )
33
35
self .input_dict_list = [{"name" : "test_input" , "type" : float , "distribution" : self .example_distribution }]
34
36
self .output_dict_list = [{"name" : "test_output" , "type" : float }]
35
37
self .meta_dict_list = [{"name" : "test_meta" , "type" : float , "populate" : populate_example }]
@@ -80,17 +82,39 @@ def test_abstract_test_case_generation(self):
80
82
mutates = None
81
83
expected_effect = dict ({"test_input" : "NoEffect" })
82
84
example_test = {
83
- "name" : "test1" ,
84
- "mutations" : {},
85
- "estimator" : None ,
86
- "estimate_type" : None ,
87
- "effect_modifiers" : [],
88
- "expectedEffect" : expected_effect ,
89
- "skip" : False ,
85
+ "name" : "test1" ,
86
+ "mutations" : {},
87
+ "estimator" : None ,
88
+ "estimate_type" : None ,
89
+ "effect_modifiers" : [],
90
+ "expectedEffect" : expected_effect ,
91
+ "skip" : False ,
90
92
}
91
93
abstract_test_case = self .json_class ._create_abstract_test_case (example_test , mutates , effects )
92
94
self .assertIsInstance (abstract_test_case , AbstractCausalTestCase )
93
95
96
+ def test_execute_concrete_test (self ):
97
+ self .json_class .setup ()
98
+ effects = {"NoEffect" : NoEffect ()}
99
+ mutates = {
100
+ "Increase" : lambda x : self .json_class .modelling_scenario .treatment_variables [x ].z3 >
101
+ self .json_class .modelling_scenario .variables [x ].z3
102
+ }
103
+ expected_effect = dict ({"test_input" : "NoEffect" })
104
+ example_test = {
105
+ "name" : "test1" ,
106
+ "mutations" : {"test_input" : "Increase" },
107
+ "estimator" : "LinearRegressionEstimator" ,
108
+ "estimate_type" : "ate" ,
109
+ "effect_modifiers" : [],
110
+ "expectedEffect" : expected_effect ,
111
+ "skip" : False ,
112
+ }
113
+ estimators = {"LinearRegressionEstimator" : LinearRegressionEstimator }
114
+ abstract_test_case = self .json_class ._create_abstract_test_case (example_test , [mutates [v ](k ) for k , v in example_test ["mutations" ].items ()], effects )
115
+ concrete_tests = abstract_test_case .generate_concrete_tests (1 , 0.5 )
116
+ self .json_class ._execute_tests (concrete_tests , estimators , example_test , False )
117
+
94
118
def tearDown (self ) -> None :
95
119
remove_temp_dir_if_existent ()
96
120
0 commit comments