Skip to content

Commit 9c923b5

Browse files
refactor clashing name changes
1 parent 413d3b0 commit 9c923b5

File tree

4 files changed

+44
-43
lines changed

4 files changed

+44
-43
lines changed

causal_testing/json_front/json_class.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _create_abstract_test_case(self, test, mutates, effects):
9292
treatment_variable=treatment_var,
9393
expected_causal_effect={
9494
self.scenario.variables[variable]: effects[effect]
95-
for variable, effect in test["expectedEffect"].items()
95+
for variable, effect in test["expected_effect"].items()
9696
},
9797
effect_modifiers={self.scenario.variables[v] for v in test["effect_modifiers"]}
9898
if "effect_modifiers" in test
@@ -120,23 +120,23 @@ def run_json_tests(self, effects: dict, estimators: dict, f_flag: bool = False,
120120
if test["estimate_type"] == "coefficient":
121121
base_test_case = BaseTestCase(
122122
treatment_variable=next(self.scenario.variables[v] for v in test["mutations"]),
123-
outcome_variable=next(self.scenario.variables[v] for v in test["expectedEffect"]),
123+
outcome_variable=next(self.scenario.variables[v] for v in test["expected_effect"]),
124124
effect=test.get("effect", "direct"),
125125
)
126-
assert len(test["expectedEffect"]) == 1, "Can only have one expected effect."
126+
assert len(test["expected_effect"]) == 1, "Can only have one expected effect."
127127
concrete_tests = [
128128
CausalTestCase(
129129
base_test_case=base_test_case,
130130
expected_causal_effect=next(
131-
effects[effect] for variable, effect in test["expectedEffect"].items()
131+
effects[effect] for variable, effect in test["expected_effect"].items()
132132
),
133133
estimate_type="coefficient",
134134
effect_modifier_configuration={
135135
self.scenario.variables[v] for v in test.get("effect_modifiers", [])
136136
},
137137
)
138138
]
139-
failures = self._execute_tests(concrete_tests, estimators, test, f_flag)
139+
failures = self._execute_tests(concrete_tests, test, f_flag)
140140
msg = (
141141
f"Executing test: {test['name']} \n"
142142
+ f" {concrete_tests[0]} \n"
@@ -145,7 +145,8 @@ def run_json_tests(self, effects: dict, estimators: dict, f_flag: bool = False,
145145
else:
146146
abstract_test = self._create_abstract_test_case(test, mutates, effects)
147147
concrete_tests, dummy = abstract_test.generate_concrete_tests(5, 0.05)
148-
failures = self._execute_tests(concrete_tests, estimators, test, f_flag)
148+
failures = self._execute_tests(concrete_tests, test, f_flag)
149+
149150
msg = (
150151
f"Executing test: {test['name']} \n"
151152
+ " abstract_test \n"
@@ -155,35 +156,35 @@ def run_json_tests(self, effects: dict, estimators: dict, f_flag: bool = False,
155156
+ f" {failures}/{len(concrete_tests)} failed for {test['name']}"
156157
)
157158
self._append_to_file(msg, logging.INFO)
158-
else:
159-
outcome_variable = next(
160-
iter(test["expected_effect"])
161-
) # Take first key from dictionary of expected effect
162-
base_test_case = BaseTestCase(
163-
treatment_variable=self.variables["inputs"][test["treatment_variable"]],
164-
outcome_variable=self.variables["outputs"][outcome_variable],
165-
)
166-
167-
causal_test_case = CausalTestCase(
168-
base_test_case=base_test_case,
169-
expected_causal_effect=effects[test["expected_effect"][outcome_variable]],
170-
control_value=test["control_value"],
171-
treatment_value=test["treatment_value"],
172-
estimate_type=test["estimate_type"],
173-
)
174-
if self._execute_test_case(causal_test_case=causal_test_case, test=test, f_flag=f_flag):
175-
result = "failed"
176-
else:
177-
result = "passed"
159+
else:
160+
outcome_variable = next(
161+
iter(test["expected_effect"])
162+
) # Take first key from dictionary of expected effect
163+
base_test_case = BaseTestCase(
164+
treatment_variable=self.variables["inputs"][test["treatment_variable"]],
165+
outcome_variable=self.variables["outputs"][outcome_variable],
166+
)
178167

179-
msg = (
180-
f"Executing concrete test: {test['name']} \n"
181-
+ f"treatment variable: {test['treatment_variable']} \n"
182-
+ f"outcome_variable = {outcome_variable} \n"
183-
+ f"control value = {test['control_value']}, treatment value = {test['treatment_value']} \n"
184-
+ f"result - {result}"
185-
)
186-
self._append_to_file(msg, logging.INFO)
168+
causal_test_case = CausalTestCase(
169+
base_test_case=base_test_case,
170+
expected_causal_effect=effects[test["expected_effect"][outcome_variable]],
171+
control_value=test["control_value"],
172+
treatment_value=test["treatment_value"],
173+
estimate_type=test["estimate_type"],
174+
)
175+
if self._execute_test_case(causal_test_case=causal_test_case, test=test, f_flag=f_flag):
176+
result = "failed"
177+
else:
178+
result = "passed"
179+
180+
msg = (
181+
f"Executing concrete test: {test['name']} \n"
182+
+ f"treatment variable: {test['treatment_variable']} \n"
183+
+ f"outcome_variable = {outcome_variable} \n"
184+
+ f"control value = {test['control_value']}, treatment value = {test['treatment_value']} \n"
185+
+ f"result - {result}"
186+
)
187+
self._append_to_file(msg, logging.INFO)
187188

188189
def _create_abstract_test_case(self, test, mutates, effects):
189190
assert len(test["mutations"]) == 1

causal_testing/specification/metamorphic_relation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def to_json_stub(self, skip=True) -> dict:
141141
"estimate_type": "coefficient",
142142
"effect": "direct",
143143
"mutations": [self.treatment_var],
144-
"expectedEffect": {self.output_var: "SomeEffect"},
144+
"expected_effect": {self.output_var: "SomeEffect"},
145145
"skip": skip,
146146
}
147147

@@ -173,7 +173,7 @@ def to_json_stub(self, skip=True) -> dict:
173173
"estimate_type": "coefficient",
174174
"effect": "direct",
175175
"mutations": [self.treatment_var],
176-
"expectedEffect": {self.output_var: "NoEffect"},
176+
"expected_effect": {self.output_var: "NoEffect"},
177177
"skip": skip,
178178
}
179179

tests/json_front_tests/test_json_class.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def test_generate_coefficient_tests_from_json(self):
111111
"estimator": "LinearRegressionEstimator",
112112
"estimate_type": "coefficient",
113113
"effect_modifiers": [],
114-
"expectedEffect": {"test_output": "NoEffect"},
114+
"expected_effect": {"test_output": "NoEffect"},
115115
"skip": False,
116116
}
117117
]
@@ -120,7 +120,7 @@ def test_generate_coefficient_tests_from_json(self):
120120
effects = {"NoEffect": NoEffect()}
121121
estimators = {"LinearRegressionEstimator": LinearRegressionEstimator}
122122

123-
self.json_class.generate_tests(effects, {}, estimators, False)
123+
self.json_class.run_json_tests(effects=effects, mutates={}, estimators=estimators, f_flag=False)
124124

125125
# Test that the final log message prints that failed tests are printed, which is expected behaviour for this scenario
126126
with open("temp_out.txt", "r") as reader:
@@ -149,7 +149,7 @@ def test_run_json_tests_from_json(self):
149149
}
150150
estimators = {"LinearRegressionEstimator": LinearRegressionEstimator}
151151

152-
self.json_class.run_json_tests(effects, estimators, False, mutates)
152+
self.json_class.run_json_tests(effects=effects, estimators=estimators, f_flag=False, mutates=mutates)
153153

154154
# Test that the final log message prints that failed tests are printed, which is expected behaviour for this scenario
155155
with open("temp_out.txt", "r") as reader:
@@ -165,7 +165,7 @@ def test_generate_tests_from_json_no_dist(self):
165165
"estimator": "LinearRegressionEstimator",
166166
"estimate_type": "ate",
167167
"effect_modifiers": [],
168-
"expectedEffect": {"test_output": "NoEffect"},
168+
"expected_effect": {"test_output": "NoEffect"},
169169
"skip": False,
170170
}
171171
]
@@ -178,7 +178,7 @@ def test_generate_tests_from_json_no_dist(self):
178178
}
179179
estimators = {"LinearRegressionEstimator": LinearRegressionEstimator}
180180

181-
self.json_class.generate_tests(effects, mutates, estimators, False)
181+
self.json_class.run_json_tests(effects=effects, mutates=mutates, estimators=estimators, f_flag=False)
182182

183183
# Test that the final log message prints that failed tests are printed, which is expected behaviour for this scenario
184184
with open("temp_out.txt", "r") as reader:

tests/specification_tests/test_metamorphic_relations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def test_should_not_cause_json_stub(self):
115115
"effect": "direct",
116116
"estimate_type": "coefficient",
117117
"estimator": "LinearRegressionEstimator",
118-
"expectedEffect": {"Z": "NoEffect"},
118+
"expected_effect": {"Z": "NoEffect"},
119119
"mutations": ["X1"],
120120
"name": "X1 _||_ Z",
121121
"skip": True,
@@ -138,7 +138,7 @@ def test_should_cause_json_stub(self):
138138
"effect": "direct",
139139
"estimate_type": "coefficient",
140140
"estimator": "LinearRegressionEstimator",
141-
"expectedEffect": {"Z": "SomeEffect"},
141+
"expected_effect": {"Z": "SomeEffect"},
142142
"mutations": ["X1"],
143143
"name": "X1 --> Z",
144144
"skip": True,

0 commit comments

Comments
 (0)