7
7
from causal_testing .testing .estimators import LinearRegressionEstimator
8
8
from causal_testing .testing .causal_test_outcome import NoEffect
9
9
from tests .test_helpers import create_temp_dir_if_non_existent , remove_temp_dir_if_existent
10
- from causal_testing .json_front .json_class import JsonUtility
10
+ from causal_testing .json_front .json_class import JsonUtility , CausalVariables
11
11
from causal_testing .specification .variable import Input , Output , Meta
12
12
from causal_testing .specification .scenario import Scenario
13
13
from causal_testing .specification .causal_specification import CausalSpecification
@@ -24,7 +24,7 @@ class TestJsonClass(unittest.TestCase):
24
24
def setUp (self ) -> None :
25
25
json_file_name = "tests.json"
26
26
dag_file_name = "dag.dot"
27
- data_file_name = "data .csv"
27
+ data_file_name = "data_with_meta .csv"
28
28
test_data_dir_path = Path ("tests/resources/data" )
29
29
self .json_path = str (test_data_dir_path / json_file_name )
30
30
self .dag_path = str (test_data_dir_path / dag_file_name )
@@ -34,8 +34,11 @@ def setUp(self) -> None:
34
34
self .input_dict_list = [{"name" : "test_input" , "datatype" : float , "distribution" : self .example_distribution }]
35
35
self .output_dict_list = [{"name" : "test_output" , "datatype" : float }]
36
36
self .meta_dict_list = [{"name" : "test_meta" , "datatype" : float , "populate" : populate_example }]
37
- self .json_class .set_variables (self .input_dict_list , self .output_dict_list , None )
37
+ variables = CausalVariables (inputs = self .input_dict_list , outputs = self .output_dict_list ,
38
+ metas = self .meta_dict_list )
39
+ self .scenario = Scenario (variables = variables , constraints = None )
38
40
self .json_class .set_paths (self .json_path , self .dag_path , self .data_path )
41
+ self .json_class .setup (self .scenario )
39
42
40
43
def test_setting_paths (self ):
41
44
self .assertEqual (self .json_class .paths .json_path , Path (self .json_path ))
@@ -44,33 +47,30 @@ def test_setting_paths(self):
44
47
45
48
def test_set_inputs (self ):
46
49
ctf_input = [Input ("test_input" , float , self .example_distribution )]
47
- self .assertEqual (ctf_input [0 ].name , self .json_class .variables . inputs [ 0 ].name )
48
- self .assertEqual (ctf_input [0 ].datatype , self .json_class .variables . inputs [ 0 ].datatype )
49
- self .assertEqual (ctf_input [0 ].distribution , self .json_class .variables . inputs [ 0 ].distribution )
50
+ self .assertEqual (ctf_input [0 ].name , self .json_class .scenario . variables [ 'test_input' ].name )
51
+ self .assertEqual (ctf_input [0 ].datatype , self .json_class .scenario . variables [ 'test_input' ].datatype )
52
+ self .assertEqual (ctf_input [0 ].distribution , self .json_class .scenario . variables [ 'test_input' ].distribution )
50
53
51
54
def test_set_outputs (self ):
52
55
ctf_output = [Output ("test_output" , float )]
53
- self .assertEqual (ctf_output [0 ].name , self .json_class .variables . outputs [ 0 ].name )
54
- self .assertEqual (ctf_output [0 ].datatype , self .json_class .variables . outputs [ 0 ].datatype )
56
+ self .assertEqual (ctf_output [0 ].name , self .json_class .scenario . variables [ 'test_output' ].name )
57
+ self .assertEqual (ctf_output [0 ].datatype , self .json_class .scenario . variables [ 'test_output' ].datatype )
55
58
56
59
def test_set_metas (self ):
57
- self .json_class .set_variables (self .input_dict_list , self .output_dict_list , self .meta_dict_list )
58
60
ctf_meta = [Meta ("test_meta" , float , populate_example )]
59
- self .assertEqual (ctf_meta [0 ].name , self .json_class .variables . metas [ 0 ].name )
60
- self .assertEqual (ctf_meta [0 ].datatype , self .json_class .variables . metas [ 0 ].datatype )
61
+ self .assertEqual (ctf_meta [0 ].name , self .json_class .scenario . variables [ 'test_meta' ].name )
62
+ self .assertEqual (ctf_meta [0 ].datatype , self .json_class .scenario . variables [ 'test_meta' ].datatype )
61
63
62
64
def test_argparse (self ):
63
65
args = self .json_class .get_args (["--data_path=data.csv" , "--dag_path=dag.dot" , "--json_path=tests.json" ])
64
66
self .assertEqual (args .data_path , ["data.csv" ])
65
67
self .assertEqual (args .dag_path , "dag.dot" )
66
68
self .assertEqual (args .json_path , "tests.json" )
67
69
68
- def test_setup_modelling_scenario (self ):
69
- self .json_class .setup ()
70
- self .assertIsInstance (self .json_class .modelling_scenario , Scenario )
70
+ def test_setup_scenario (self ):
71
+ self .assertIsInstance (self .json_class .scenario , Scenario )
71
72
72
73
def test_setup_causal_specification (self ):
73
- self .json_class .setup ()
74
74
self .assertIsInstance (self .json_class .causal_specification , CausalSpecification )
75
75
76
76
def test_generate_tests_from_json (self ):
@@ -87,12 +87,11 @@ def test_generate_tests_from_json(self):
87
87
}
88
88
]
89
89
}
90
- self .json_class .setup ()
91
90
self .json_class .test_plan = example_test
92
91
effects = {"NoEffect" : NoEffect ()}
93
92
mutates = {
94
- "Increase" : lambda x : self .json_class .modelling_scenario .treatment_variables [x ].z3
95
- > self .json_class .modelling_scenario .variables [x ].z3
93
+ "Increase" : lambda x : self .json_class .scenario .treatment_variables [x ].z3
94
+ > self .json_class .scenario .variables [x ].z3
96
95
}
97
96
estimators = {"LinearRegressionEstimator" : LinearRegressionEstimator }
98
97
0 commit comments