From 3bad598d2192de039a5b6a12ca2735db3d4bbc4f Mon Sep 17 00:00:00 2001 From: m-goggins <53578688+m-goggins@users.noreply.github.com> Date: Tue, 13 Jun 2023 08:14:44 -0700 Subject: [PATCH] fix test to close invalid json file (#657) --- phdi/linkage/link.py | 15 +++++++++------ tests/not_valid_json_test.json | 1 - 2 files changed, 9 insertions(+), 7 deletions(-) delete mode 100644 tests/not_valid_json_test.json diff --git a/phdi/linkage/link.py b/phdi/linkage/link.py index c966cb88d0..e77f5b009a 100644 --- a/phdi/linkage/link.py +++ b/phdi/linkage/link.py @@ -949,12 +949,15 @@ def read_linkage_config(config_file: pathlib.Path) -> List[dict]: various parts of linkage pass function. """ try: - algo_config = json.load(open(config_file)) - # Need to convert function keys back to column indices, since - # JSON serializes dict keys as strings - for rl_pass in algo_config.get("algorithm"): - rl_pass["funcs"] = {int(col): f for (col, f) in rl_pass["funcs"].items()} - return algo_config.get("algorithm", []) + with open(config_file) as f: + algo_config = json.load(f) + # Need to convert function keys back to column indices, since + # JSON serializes dict keys as strings + for rl_pass in algo_config.get("algorithm"): + rl_pass["funcs"] = { + int(col): f for (col, f) in rl_pass["funcs"].items() + } + return algo_config.get("algorithm", []) except FileNotFoundError: raise FileNotFoundError(f"No file exists at path {config_file}.") except json.decoder.JSONDecodeError as e: diff --git a/tests/not_valid_json_test.json b/tests/not_valid_json_test.json deleted file mode 100644 index bb73d201e6..0000000000 --- a/tests/not_valid_json_test.json +++ /dev/null @@ -1 +0,0 @@ -this is a random string that is not in json format