Skip to content

Commit 122f68d

Browse files
move args into static method
1 parent 1ca522d commit 122f68d

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

causal_testing/json_front/json_class.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import argparse
12
import logging
23
from pathlib import Path
34

@@ -214,7 +215,21 @@ def add_modelling_assumptions(self, estimation_model: Estimator):
214215
return
215216

216217
@staticmethod
217-
def setup_logger(log_path: Path):
218-
logger = logging.getLogger(__name__)
219-
fh = logging.FileHandler(log_path + "json_frontend.log")
220-
logger.addHandler(fh)
218+
def setup_logger(log_path: str):
219+
setup_log = logging.getLogger(__name__)
220+
fh = logging.FileHandler(Path(log_path) / "json_frontend.log")
221+
setup_log.addHandler(fh)
222+
223+
@staticmethod
224+
def get_args() -> argparse.Namespace:
225+
""" Command-line arguments
226+
227+
:return: parsed command line arguments
228+
"""
229+
parser = argparse.ArgumentParser(
230+
description="A script for parsing json config files for the Causal Testing Framework")
231+
parser.add_argument(
232+
"-f", help="if included, the script will stop if a test fails", action="store_true")
233+
parser.add_argument(
234+
"--log_path", help="Specify a directory to change the location of the log file", default=".")
235+
return parser.parse_args()

examples/poisson/run_causal_tests.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import argparse
1+
22
import numpy as np
33
import pandas as pd
44
import scipy
@@ -98,20 +98,6 @@ def populate_num_shapes_unit(data):
9898
data['num_shapes_unit'] = data['num_shapes_abs'] / area
9999

100100

101-
def get_args() -> argparse.Namespace:
102-
""" Command-line arguments
103-
104-
:return: parsed command line arguments
105-
"""
106-
parser = argparse.ArgumentParser(
107-
description="A script for parsing json config files for the Causal Testing Framework")
108-
parser.add_argument(
109-
"-f", help="if included, the script will stop if a test fails", action="store_true")
110-
parser.add_argument(
111-
"--log_path", help="Specify a directory to change the location of the log file", default="./")
112-
return parser.parse_args()
113-
114-
115101
def logger_setup():
116102
logger = logging.getLogger(__name__)
117103
fh = logging.FileHandler()
@@ -194,7 +180,7 @@ def add_modelling_assumptions(self, estimation_model: Estimator):
194180

195181

196182
if __name__ == "__main__":
197-
args = get_args()
183+
args = MyJsonUtility.get_args()
198184

199185
json_utility = MyJsonUtility(args.log_path) # Create an instance of the extended JsonUtility class
200186
json_utility.set_path(json_path, dag_path, data_path) # Set the path to the data.csv, dag.dot and causal_tests.json file

0 commit comments

Comments
 (0)