Skip to content

Commit 9bcbd93

Browse files
restructure test-case execution
1 parent bf87ec3 commit 9bcbd93

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

causal_testing/json_front/json_class.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,14 @@ def _create_abstract_test_case(self, test, mutates, effects):
104104
)
105105
return abstract_test
106106

107-
def execute_tests(self, effects: dict, mutates: dict, estimators: dict, f_flag: bool):
107+
def generate_tests(self, effects: dict, mutates: dict, estimators: dict, f_flag: bool):
108108
"""Runs and evaluates each test case specified in the JSON input
109109
110110
:param effects: Dictionary mapping effect class instances to string representations.
111111
:param mutates: Dictionary mapping mutation functions to string representations.
112112
:param estimators: Dictionary mapping estimator classes to string representations.
113113
:param f_flag: Failure flag that if True the script will stop executing when a test fails.
114114
"""
115-
executed_tests = 0
116115
failures = 0
117116
for test in self.test_plan["tests"]:
118117
if "skip" in test and test["skip"]:
@@ -127,13 +126,17 @@ def execute_tests(self, effects: dict, mutates: dict, estimators: dict, f_flag:
127126
logger.info(abstract_test)
128127
logger.info([(v.name, v.distribution) for v in abstract_test.treatment_variables])
129128
logger.info("Number of concrete tests for test case: %s", str(len(concrete_tests)))
130-
for concrete_test in concrete_tests:
131-
executed_tests += 1
132-
failed = self._execute_test_case(concrete_test, estimators[test["estimator"]], f_flag)
133-
if failed:
134-
failures += 1
129+
failures = self._execute_tests(concrete_tests, estimators, test, f_flag)
135130

136-
logger.info("{%d}/{%d} failed", failures, executed_tests)
131+
logger.info("{%d}/{%d} failed", failures, str(len(concrete_tests)))
132+
133+
def _execute_tests(self, concrete_tests, estimators, test, f_flag):
134+
failures = 0
135+
for concrete_test in concrete_tests:
136+
failed = self._execute_test_case(concrete_test, estimators[test["estimator"]], f_flag)
137+
if failed:
138+
failures += 1
139+
return failures
137140

138141
def _json_parse(self):
139142

examples/poisson/run_causal_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,4 @@ def add_modelling_assumptions(self, estimation_model: Estimator):
167167
json_utility.set_variables(inputs, outputs, metas)
168168
json_utility.setup() # Sets up all the necessary parts of the json_class needed to execute tests
169169

170-
json_utility.execute_tests(effects, mutates, estimators, args.f)
170+
json_utility.generate_tests(effects, mutates, estimators, args.f)

0 commit comments

Comments
 (0)