6
6
from dataclasses import dataclass
7
7
from pathlib import Path
8
8
from typing import Dict , Any , Optional , List , Union , Sequence
9
+ from tqdm import tqdm
9
10
10
11
import pandas as pd
11
12
16
17
from .testing .causal_test_case import CausalTestCase
17
18
from .testing .base_test_case import BaseTestCase
18
19
from .testing .causal_test_outcome import NoEffect , SomeEffect , Positive , Negative
19
- from .testing .causal_test_result import CausalTestResult
20
+ from .testing .causal_test_result import CausalTestResult , TestValue
20
21
from .estimation .linear_regression_estimator import LinearRegressionEstimator
21
22
from .estimation .logistic_regression_estimator import LogisticRegressionEstimator
22
23
23
24
logger = logging .getLogger (__name__ )
25
+ logger .setLevel (logging .ERROR )
24
26
25
27
26
28
@dataclass
@@ -338,8 +340,6 @@ def create_causal_test(self, test: dict, base_test: BaseTestCase) -> CausalTestC
338
340
if estimator_class is None :
339
341
raise ValueError (f"Unknown estimator: { test ['estimator' ]} " )
340
342
341
- print (test )
342
-
343
343
# Create the estimator with correct parameters
344
344
estimator = estimator_class (
345
345
base_test_case = base_test ,
@@ -366,7 +366,7 @@ def create_causal_test(self, test: dict, base_test: BaseTestCase) -> CausalTestC
366
366
estimator = estimator ,
367
367
)
368
368
369
- def run_tests (self ) -> List [CausalTestResult ]:
369
+ def run_tests (self , silent = False ) -> List [CausalTestResult ]:
370
370
"""
371
371
Run all test cases and return their results.
372
372
@@ -380,14 +380,21 @@ def run_tests(self) -> List[CausalTestResult]:
380
380
raise ValueError ("No tests loaded. Call load_tests() first." )
381
381
382
382
results = []
383
- for test_case in self .test_cases :
383
+ for test_case in tqdm ( self .test_cases ) :
384
384
try :
385
385
result = test_case .execute_test ()
386
386
results .append (result )
387
387
logger .info (f"Test completed: { test_case } " )
388
388
except Exception as e :
389
- logger .error (f"Error running test { test_case } : { str (e )} " )
390
- raise
389
+ if silent :
390
+ logger .error (f"Error running test { test_case } : { str (e )} " )
391
+ raise
392
+ result = CausalTestResult (
393
+ estimator = test_case .estimator ,
394
+ test_value = TestValue ("Error" , str (e )),
395
+ )
396
+ results .append (result )
397
+ logger .info (f"Test errored: { test_case } " )
391
398
392
399
return results
393
400
@@ -463,12 +470,19 @@ def setup_logging(verbose: bool = False) -> None:
463
470
def parse_args (args : Optional [Sequence [str ]] = None ) -> argparse .Namespace :
464
471
"""Parse command line arguments."""
465
472
parser = argparse .ArgumentParser (description = "Causal Testing Framework" )
466
- parser .add_argument ("--dag_path" , help = "Path to the DAG file (.dot)" , required = True )
467
- parser .add_argument ("--data_paths" , help = "Paths to data files (.csv)" , nargs = "+" , required = True )
468
- parser .add_argument ("--test_config" , help = "Path to test configuration file (.json)" , required = True )
469
- parser .add_argument ("--output" , help = "Path for output file (.json)" , required = True )
470
- parser .add_argument ("--verbose" , help = "Enable verbose logging" , action = "store_true" )
471
- parser .add_argument ("--ignore-cycles" , help = "Ignore cycles in DAG" , action = "store_true" )
472
- parser .add_argument ("--query" , help = "Query string to filter data (e.g. 'age > 18')" , type = str )
473
+ parser .add_argument ("-D" , "--dag_path" , help = "Path to the DAG file (.dot)" , required = True )
474
+ parser .add_argument ("-d" , "--data_paths" , help = "Paths to data files (.csv)" , nargs = "+" , required = True )
475
+ parser .add_argument ("-t" , "--test_config" , help = "Path to test configuration file (.json)" , required = True )
476
+ parser .add_argument ("-o" , "--output" , help = "Path for output file (.json)" , required = True )
477
+ parser .add_argument ("-v" , "--verbose" , help = "Enable verbose logging" , action = "store_true" , default = False )
478
+ parser .add_argument ("-i" , "--ignore-cycles" , help = "Ignore cycles in DAG" , action = "store_true" , default = False )
479
+ parser .add_argument ("-q" , "--query" , help = "Query string to filter data (e.g. 'age > 18')" , type = str )
480
+ parser .add_argument (
481
+ "-s" ,
482
+ "--silent" ,
483
+ action = "store_true" ,
484
+ help = "Do not crash on error. If set to true, errors are recorded as test results." ,
485
+ default = False ,
486
+ )
473
487
474
488
return parser .parse_args (args )
0 commit comments