Skip to content

Commit becf6b3

Browse files
setup tempfiles
1 parent 291fd26 commit becf6b3

File tree

1 file changed

+40
-34
lines changed

1 file changed

+40
-34
lines changed

tests/json_front_tests/test_json_class.py

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import unittest
22
from pathlib import Path
3-
import os
4-
import json
53
import scipy
64
import csv
5+
import json
6+
77
from tests.test_helpers import create_temp_dir_if_non_existent, remove_temp_dir_if_existent
88
from causal_testing.json_front.json_class import JsonUtility
99
from causal_testing.specification.variable import Input, Output, Meta
@@ -26,9 +26,7 @@ def setUp(self) -> None:
2626
self.json_path = temp_dir_path / json_file_name
2727
self.dag_path = temp_dir_path / dag_file_name
2828
self.data_path = temp_dir_path / data_file_name
29-
self.setup_data_file()
30-
self.setup_json_file()
31-
self.setup_dag_file()
29+
setup_files(self.json_path, self.data_path, self.dag_path)
3230
self.json_class = JsonUtility("logs.log")
3331
self.example_distribution = scipy.stats.uniform(0, 10)
3432
self.input_dict_list = [{"name": "test_input", "type": float, "distribution": self.example_distribution}]
@@ -73,42 +71,50 @@ def test_setup_modelling_scenario(self):
7371

7472
def test_setup_causal_specification(self):
7573
self.json_class.setup()
76-
7774
self.assertIsInstance(self.json_class.causal_specification, CausalSpecification)
7875

7976
def test_concrete_tests_generated(self):
80-
self.setup_json_file()
81-
self.setup_data_file()
82-
self.setup_dag_file()
77+
pass
8378

8479
def tearDown(self) -> None:
8580
remove_temp_dir_if_existent()
8681

87-
def setup_json_file(self):
88-
json_test = {
89-
"tests": [
90-
{"name": "test1", "mutations": {}, "estimator": None, "estimate_type": None, "effect_modifiers": [],
91-
"expectedEffect": {}, "skip": False}]
92-
}
93-
json_object = json.dumps(json_test)
94-
with open(self.json_path, "w") as f:
95-
f.write(json_object)
96-
f.close()
97-
98-
def setup_data_file(self):
99-
header = ['test_input', 'test_output']
100-
data = [1, 2]
101-
with open(self.data_path, "w") as f:
102-
writer = csv.writer(f)
103-
writer.writerow(header)
104-
writer.writerow(data)
105-
106-
def setup_dag_file(self):
107-
dag_dot = (
108-
"digraph G {A->B}"
109-
)
110-
with open(self.dag_path, "w") as f:
111-
f.write(dag_dot)
11282

11383
def populate_example(*args, **kwargs):
11484
pass
85+
86+
87+
def setup_json_file(json_path):
88+
json_test = {
89+
"tests": [
90+
{"name": "test1", "mutations": {}, "estimator": None, "estimate_type": None, "effect_modifiers": [],
91+
"expectedEffect": {}, "skip": False}]
92+
}
93+
json_object = json.dumps(json_test)
94+
with open(json_path, "w") as f:
95+
f.write(json_object)
96+
f.close()
97+
98+
99+
def setup_data_file(data_path):
100+
header = ['test_input', 'test_output']
101+
data = [1, 2]
102+
with open(data_path, "w") as f:
103+
writer = csv.writer(f)
104+
writer.writerow(header)
105+
writer.writerow(data)
106+
107+
108+
def setup_dag_file(dag_path):
109+
dag_dot = (
110+
"digraph G {A->B}"
111+
)
112+
with open(dag_path, "w") as f:
113+
f.write(dag_dot)
114+
f.close()
115+
116+
117+
def setup_files(json_path, data_path, dag_path):
118+
setup_data_file(data_path)
119+
setup_json_file(json_path)
120+
setup_dag_file(dag_path)

0 commit comments

Comments
 (0)