1
+ import logging
1
2
from pathlib import Path
2
3
3
4
from abc import ABC
16
17
from causal_testing .testing .causal_test_case import CausalTestCase
17
18
from causal_testing .testing .estimators import Estimator
18
19
20
+ logger = logging .getLogger (__name__ )
21
+
19
22
20
23
class JsonUtility (ABC ):
21
24
"""
@@ -113,16 +116,16 @@ def execute_tests(self, effects: dict, mutates: dict, estimators: dict, f_flag:
113
116
)
114
117
115
118
concrete_tests , dummy = abstract_test .generate_concrete_tests (5 , 0.05 )
116
- print (abstract_test )
117
- print ([(v .name , v .distribution ) for v in abstract_test .treatment_variables ])
118
- print (len (concrete_tests ))
119
+ logger . info (abstract_test )
120
+ logger . info ([(v .name , v .distribution ) for v in abstract_test .treatment_variables ])
121
+ logger . info (len (concrete_tests ))
119
122
for concrete_test in concrete_tests :
120
123
executed_tests += 1
121
124
failed = self ._execute_test_case (concrete_test , estimators [test ['estimator' ]], f_flag )
122
125
if failed :
123
126
failures += 1
124
127
125
- print (f"{ failures } /{ executed_tests } failed" )
128
+ logger . info (f"{ failures } /{ executed_tests } failed" )
126
129
127
130
def _json_parse (self ):
128
131
"""Parse a JSON input file into inputs, outputs, metas and a test plan
@@ -147,7 +150,7 @@ def _populate_metas(self):
147
150
f .fit ()
148
151
(dist , params ) = list (f .get_best (method = "sumsquare_error" ).items ())[0 ]
149
152
var .distribution = getattr (scipy .stats , dist )(** params )
150
- print (var .name , f"{ dist } ({ params } )" )
153
+ logger . info (var .name + f"{ dist } ({ params } )" )
151
154
152
155
def _execute_test_case (self , causal_test_case : CausalTestCase , estimator : Estimator , f_flag : bool ) -> bool :
153
156
""" Executes a singular test case, prints the results and returns the test case result
@@ -174,7 +177,8 @@ def _execute_test_case(self, causal_test_case: CausalTestCase, estimator: Estima
174
177
f"got { result_string } "
175
178
if not test_passes :
176
179
failed = True
177
- print (f" FAILED - expected { causal_test_case .expected_causal_effect } , got { causal_test_result .ate } " )
180
+ logger .warning (
181
+ f" FAILED - expected { causal_test_case .expected_causal_effect } , got { causal_test_result .ate } " )
178
182
return failed
179
183
180
184
def _setup_test (self , causal_test_case : CausalTestCase , estimator : Estimator ) -> tuple [CausalTestEngine , Estimator ]:
0 commit comments