From 778483837c69c1c387a92b11f841f0bed908ebe5 Mon Sep 17 00:00:00 2001 From: Rob Hallam <0504004h@student.gla.ac.uk> Date: Sun, 18 Aug 2024 17:37:28 +0100 Subject: [PATCH] refactor: pull out _read_json_from_file() facilitates test mocking --- pipeline/feature_extractors.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pipeline/feature_extractors.py b/pipeline/feature_extractors.py index b71b28b..fbcffb6 100644 --- a/pipeline/feature_extractors.py +++ b/pipeline/feature_extractors.py @@ -356,6 +356,14 @@ class JSONFeatureExtractor(FeatureExtractor): def _source_from_dict(self, d): return Source(d["source"], d["path"], d["provider"]) + def _read_json_from_file(self, file): + """Read a JSON file and return the contents + + Method exists to allow for mocking in tests + """ + with open(file, "r") as f: + return json.load(f) + def run(self): # only pipeline JSON format for now