From f19baf09120ebc18ac126f10ade7a3a6bd052a49 Mon Sep 17 00:00:00 2001 From: Augusto Herrmann Date: Thu, 22 Aug 2024 16:52:57 -0300 Subject: [PATCH] Factor out file read into its own method --- src/parsers.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/parsers.py b/src/parsers.py index 345e2e0..327a58c 100644 --- a/src/parsers.py +++ b/src/parsers.py @@ -63,13 +63,17 @@ class YAMLParser: def __init__(self, filepath: str): self.filepath = filepath + def read(self) -> dict: + """Reads the contents of the YAML file.""" + with open(self.filepath, "r", encoding="utf-8") as file: + dag_config_dict = yaml.safe_load(file) + return dag_config_dict + def parse(self) -> DAGConfig: """Processes the config file in order to instantiate the DAG in Airflow. """ - with open(self.filepath, "r") as file: - dag_config_dict = yaml.safe_load(file) - + dag_config_dict = self.read() dag = self._try_get(dag_config_dict, "dag") dag_id = self._try_get(dag, "id") description = self._try_get(dag, "description")