Skip to content

Commit 4368e67

Browse files
Refactor test to public method instead of private
1 parent 56a470b commit 4368e67

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

tests/json_front_tests/test_json_class.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,36 @@ def test_abstract_test_case_generation(self):
9393
abstract_test_case = self.json_class._create_abstract_test_case(example_test, mutates, effects)
9494
self.assertIsInstance(abstract_test_case, AbstractCausalTestCase)
9595

96-
def test_execute_concrete_test(self):
96+
def test_generate_tests_from_json(self):
97+
example_test = {
98+
"tests": [
99+
{
100+
"name": "test1",
101+
"mutations": {"test_input": "Increase"},
102+
"estimator": "LinearRegressionEstimator",
103+
"estimate_type": "ate",
104+
"effect_modifiers": [],
105+
"expectedEffect": {"test_output": "NoEffect"},
106+
"skip": False,
107+
}
108+
]
109+
}
97110
self.json_class.setup()
98-
dag_string = "digraph G { test_input -> B; B -> C; test_output -> test_input; test_output -> C}"
99-
setup_dag_file(self.dag_path, dag_string)
111+
self.json_class.test_plan = example_test
100112
effects = {"NoEffect": NoEffect()}
101113
mutates = {
102114
"Increase": lambda x: self.json_class.modelling_scenario.treatment_variables[x].z3 >
103115
self.json_class.modelling_scenario.variables[x].z3
104116
}
105-
expected_effect = dict({"test_output": "NoEffect"})
106-
example_test = {
107-
"name": "test1",
108-
"mutations": {"test_input": "Increase"},
109-
"estimator": "LinearRegressionEstimator",
110-
"estimate_type": "ate",
111-
"effect_modifiers": [],
112-
"expectedEffect": expected_effect,
113-
"skip": False,
117+
estimators = {
118+
"LinearRegressionEstimator": LinearRegressionEstimator
114119
}
115-
estimators = {"LinearRegressionEstimator": LinearRegressionEstimator}
116-
abstract_test_case = self.json_class._create_abstract_test_case(example_test, mutates, effects)
117-
concrete_tests, dummy = abstract_test_case.generate_concrete_tests(5, 0.5)
118120

119-
# This scenario should produce 5 failures
120-
failures = self.json_class._execute_tests(concrete_tests, estimators, example_test, False)
121-
self.assertEqual(failures, 5)
121+
with self.assertLogs() as captured:
122+
self.json_class.generate_tests(effects, mutates, estimators, False)
122123

124+
# Test that the final log message is that all tests have failed, which is expected behaviour for this scenario
125+
self.assertEqual(captured.records[-1].getMessage(), "105/105 failed")
123126
def tearDown(self) -> None:
124127
remove_temp_dir_if_existent()
125128

0 commit comments

Comments
 (0)