Skip to content

Commit 6d9f053

Browse files
tidy mutates
1 parent 9bcbd93 commit 6d9f053

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

causal_testing/json_front/json_class.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ def generate_tests(self, effects: dict, mutates: dict, estimators: dict, f_flag:
116116
for test in self.test_plan["tests"]:
117117
if "skip" in test and test["skip"]:
118118
continue
119-
119+
mutation = [mutates[v](k) for k, v in test["mutations"].items()]
120120
abstract_test = self._create_abstract_test_case(
121-
test, [mutates[v](k) for k, v in test["mutations"].items()], effects
121+
test, mutation, effects
122122
)
123123

124124
concrete_tests, dummy = abstract_test.generate_concrete_tests(5, 0.05)

tests/json_front_tests/test_json_class.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import csv
55
import json
66

7+
from causal_testing.testing.estimators import LinearRegressionEstimator
78
from causal_testing.testing.causal_test_outcome import NoEffect
89
from tests.test_helpers import create_temp_dir_if_non_existent, remove_temp_dir_if_existent
910
from causal_testing.json_front.json_class import JsonUtility
@@ -12,6 +13,7 @@
1213
from causal_testing.specification.causal_specification import CausalSpecification
1314
from causal_testing.generation.abstract_causal_test_case import AbstractCausalTestCase
1415

16+
1517
class TestJsonClass(unittest.TestCase):
1618
"""Test the CausalTestEngine workflow using observational data.
1719
@@ -29,7 +31,7 @@ def setUp(self) -> None:
2931
self.data_path = temp_dir_path / data_file_name
3032
setup_files(self.json_path, self.data_path, self.dag_path)
3133
self.json_class = JsonUtility("logs.log")
32-
self.example_distribution = scipy.stats.uniform(0, 10)
34+
self.example_distribution = scipy.stats.uniform(1, 10)
3335
self.input_dict_list = [{"name": "test_input", "type": float, "distribution": self.example_distribution}]
3436
self.output_dict_list = [{"name": "test_output", "type": float}]
3537
self.meta_dict_list = [{"name": "test_meta", "type": float, "populate": populate_example}]
@@ -80,17 +82,39 @@ def test_abstract_test_case_generation(self):
8082
mutates = None
8183
expected_effect = dict({"test_input": "NoEffect"})
8284
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,
9092
}
9193
abstract_test_case = self.json_class._create_abstract_test_case(example_test, mutates, effects)
9294
self.assertIsInstance(abstract_test_case, AbstractCausalTestCase)
9395

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+
94118
def tearDown(self) -> None:
95119
remove_temp_dir_if_existent()
96120

0 commit comments

Comments
 (0)