Skip to content

Commit

Permalink
create files in a dir
Browse files Browse the repository at this point in the history
  • Loading branch information
emmyoop committed Jun 17, 2024
1 parent 4656e12 commit 2ec8baf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions dbt_common/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2ec8baf

Please sign in to comment.