@@ -32,11 +32,15 @@ def setUp(self) -> None:
32
32
self .data_path = [str (test_data_dir_path / data_file_name )]
33
33
self .json_class = JsonUtility ("temp_out.txt" , True )
34
34
self .example_distribution = scipy .stats .uniform (1 , 10 )
35
- self .input_dict_list = [{"name" : "test_input" , "datatype" : float , "distribution" : self .example_distribution }]
35
+ self .input_dict_list = [
36
+ {"name" : "test_input" , "datatype" : float , "distribution" : self .example_distribution },
37
+ {"name" : "test_input_no_dist" , "datatype" : float },
38
+ ]
36
39
self .output_dict_list = [{"name" : "test_output" , "datatype" : float }]
37
40
self .meta_dict_list = [{"name" : "test_meta" , "datatype" : float , "populate" : populate_example }]
38
- variables = CausalVariables (inputs = self .input_dict_list , outputs = self .output_dict_list ,
39
- metas = self .meta_dict_list )
41
+ variables = CausalVariables (
42
+ inputs = self .input_dict_list , outputs = self .output_dict_list , metas = self .meta_dict_list
43
+ )
40
44
self .scenario = Scenario (variables = variables , constraints = None )
41
45
self .json_class .set_paths (self .json_path , self .dag_path , self .data_path )
42
46
self .json_class .setup (self .scenario )
@@ -48,19 +52,19 @@ def test_setting_paths(self):
48
52
49
53
def test_set_inputs (self ):
50
54
ctf_input = [Input ("test_input" , float , self .example_distribution )]
51
- self .assertEqual (ctf_input [0 ].name , self .json_class .scenario .variables [' test_input' ].name )
52
- self .assertEqual (ctf_input [0 ].datatype , self .json_class .scenario .variables [' test_input' ].datatype )
53
- self .assertEqual (ctf_input [0 ].distribution , self .json_class .scenario .variables [' test_input' ].distribution )
55
+ self .assertEqual (ctf_input [0 ].name , self .json_class .scenario .variables [" test_input" ].name )
56
+ self .assertEqual (ctf_input [0 ].datatype , self .json_class .scenario .variables [" test_input" ].datatype )
57
+ self .assertEqual (ctf_input [0 ].distribution , self .json_class .scenario .variables [" test_input" ].distribution )
54
58
55
59
def test_set_outputs (self ):
56
60
ctf_output = [Output ("test_output" , float )]
57
- self .assertEqual (ctf_output [0 ].name , self .json_class .scenario .variables [' test_output' ].name )
58
- self .assertEqual (ctf_output [0 ].datatype , self .json_class .scenario .variables [' test_output' ].datatype )
61
+ self .assertEqual (ctf_output [0 ].name , self .json_class .scenario .variables [" test_output" ].name )
62
+ self .assertEqual (ctf_output [0 ].datatype , self .json_class .scenario .variables [" test_output" ].datatype )
59
63
60
64
def test_set_metas (self ):
61
65
ctf_meta = [Meta ("test_meta" , float , populate_example )]
62
- self .assertEqual (ctf_meta [0 ].name , self .json_class .scenario .variables [' test_meta' ].name )
63
- self .assertEqual (ctf_meta [0 ].datatype , self .json_class .scenario .variables [' test_meta' ].datatype )
66
+ self .assertEqual (ctf_meta [0 ].name , self .json_class .scenario .variables [" test_meta" ].name )
67
+ self .assertEqual (ctf_meta [0 ].datatype , self .json_class .scenario .variables [" test_meta" ].datatype )
64
68
65
69
def test_argparse (self ):
66
70
args = self .json_class .get_args (["--data_path=data.csv" , "--dag_path=dag.dot" , "--json_path=tests.json" ])
@@ -92,7 +96,7 @@ def test_f_flag(self):
92
96
effects = {"NoEffect" : NoEffect ()}
93
97
mutates = {
94
98
"Increase" : lambda x : self .json_class .scenario .treatment_variables [x ].z3
95
- > self .json_class .scenario .variables [x ].z3
99
+ > self .json_class .scenario .variables [x ].z3
96
100
}
97
101
estimators = {"LinearRegressionEstimator" : LinearRegressionEstimator }
98
102
with self .assertRaises (StatisticsError ):
@@ -116,14 +120,44 @@ def test_generate_tests_from_json(self):
116
120
effects = {"NoEffect" : NoEffect ()}
117
121
mutates = {
118
122
"Increase" : lambda x : self .json_class .scenario .treatment_variables [x ].z3
119
- > self .json_class .scenario .variables [x ].z3
123
+ > self .json_class .scenario .variables [x ].z3
120
124
}
121
125
estimators = {"LinearRegressionEstimator" : LinearRegressionEstimator }
122
126
123
127
self .json_class .generate_tests (effects , mutates , estimators , False )
124
128
125
129
# Test that the final log message prints that failed tests are printed, which is expected behaviour for this scenario
126
- with open ("temp_out.txt" , 'r' ) as reader :
130
+ with open ("temp_out.txt" , "r" ) as reader :
131
+ temp_out = reader .readlines ()
132
+ self .assertIn ("failed" , temp_out [- 1 ])
133
+
134
+
135
+ def test_generate_tests_from_json_no_dist (self ):
136
+ example_test = {
137
+ "tests" : [
138
+ {
139
+ "name" : "test1" ,
140
+ "mutations" : {"test_input_no_dist" : "Increase" },
141
+ "estimator" : "LinearRegressionEstimator" ,
142
+ "estimate_type" : "ate" ,
143
+ "effect_modifiers" : [],
144
+ "expectedEffect" : {"test_output" : "NoEffect" },
145
+ "skip" : False ,
146
+ }
147
+ ]
148
+ }
149
+ self .json_class .test_plan = example_test
150
+ effects = {"NoEffect" : NoEffect ()}
151
+ mutates = {
152
+ "Increase" : lambda x : self .json_class .scenario .treatment_variables [x ].z3
153
+ > self .json_class .scenario .variables [x ].z3
154
+ }
155
+ estimators = {"LinearRegressionEstimator" : LinearRegressionEstimator }
156
+
157
+ self .json_class .generate_tests (effects , mutates , estimators , False )
158
+
159
+ # Test that the final log message prints that failed tests are printed, which is expected behaviour for this scenario
160
+ with open ("temp_out.txt" , "r" ) as reader :
127
161
temp_out = reader .readlines ()
128
162
self .assertIn ("failed" , temp_out [- 1 ])
129
163
0 commit comments