|
6 | 6 | import json
|
7 | 7 |
|
8 | 8 | from causal_testing.testing.estimators import LinearRegressionEstimator
|
9 |
| -from causal_testing.testing.causal_test_outcome import NoEffect |
| 9 | +from causal_testing.testing.causal_test_outcome import NoEffect, Positive |
10 | 10 | from tests.test_helpers import create_temp_dir_if_non_existent, remove_temp_dir_if_existent
|
11 | 11 | from causal_testing.json_front.json_class import JsonUtility, CausalVariables
|
12 | 12 | from causal_testing.specification.variable import Input, Output, Meta
|
@@ -127,6 +127,34 @@ def test_generate_tests_from_json(self):
|
127 | 127 | temp_out = reader.readlines()
|
128 | 128 | self.assertIn("failed", temp_out[-1])
|
129 | 129 |
|
| 130 | + def test_formula_in_json_test(self): |
| 131 | + example_test = { |
| 132 | + "tests": [ |
| 133 | + { |
| 134 | + "name": "test1", |
| 135 | + "mutations": {"test_input": "Increase"}, |
| 136 | + "estimator": "LinearRegressionEstimator", |
| 137 | + "estimate_type": "ate", |
| 138 | + "effect_modifiers": [], |
| 139 | + "expectedEffect": {"test_output": "Positive"}, |
| 140 | + "skip": False, |
| 141 | + "formula": "test_output ~ test_input" |
| 142 | + } |
| 143 | + ] |
| 144 | + } |
| 145 | + self.json_class.test_plan = example_test |
| 146 | + effects = {"Positive": Positive()} |
| 147 | + mutates = { |
| 148 | + "Increase": lambda x: self.json_class.scenario.treatment_variables[x].z3 |
| 149 | + > self.json_class.scenario.variables[x].z3 |
| 150 | + } |
| 151 | + estimators = {"LinearRegressionEstimator": LinearRegressionEstimator} |
| 152 | + |
| 153 | + self.json_class.generate_tests(effects, mutates, estimators, False) |
| 154 | + with open("temp_out.txt", 'r') as reader: |
| 155 | + temp_out = reader.readlines() |
| 156 | + self.assertIn("test_output ~ test_input", ''.join(temp_out)) |
| 157 | + |
130 | 158 | def tearDown(self) -> None:
|
131 | 159 | pass
|
132 | 160 | # remove_temp_dir_if_existent()
|
|
0 commit comments