From 2ec8baf7bd63dccd2d2bf4fe5d505dd47fb77dc5 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Mon, 17 Jun 2024 09:00:58 -0500 Subject: [PATCH] create files in a dir --- dbt_common/record.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dbt_common/record.py b/dbt_common/record.py index ac2838d5..12ea26ed 100644 --- a/dbt_common/record.py +++ b/dbt_common/record.py @@ -205,6 +205,8 @@ def __init__( self.diff: Diff self.previous_recording_path = previous_recording_path self.current_recording_path = current_recording_path + self.dir_path = os.path.join(os.path.dirname(self.current_recording_path), "recordings") + os.makedirs(self.dir_path, exist_ok=True) # Create the directory if it does not exist # TODO: better way to do this? if self.previous_recording_path is not None and self.mode == RecorderMode.REPLAY: @@ -245,7 +247,8 @@ def pop_matching_record(self, params: Any) -> Optional[Record]: return match def write(self) -> None: - with open(self.current_recording_path, "w") as file: + fp = os.path.join(self.dir_path, os.path.basename(self.current_recording_path)) + with open(fp, "w") as file: json.dump(self._to_dict(), file) def _to_dict(self) -> Dict: @@ -285,9 +288,10 @@ def expect_record(self, params: Any) -> Any: return result_tuple[0] if len(result_tuple) == 1 else result_tuple def write_diffs(self, diff_file_name) -> None: + fp = os.path.join(self.dir_path, os.path.basename(diff_file_name)) json.dump( self.diff.calculate_diff(), - open(diff_file_name, "w"), + open(fp, "w"), ) def print_diffs(self) -> None: