Skip to content

Commit

Permalink
fix: don't serialize twice into same file (#98)
Browse files Browse the repository at this point in the history

Co-authored-by: Konstantin <[email protected]>
  • Loading branch information
hf-kklein and Konstantin authored Nov 7, 2024
1 parent a2c763d commit a1c879f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/ebd_toolchain/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def _dump_svg(svg_path: Path, ebd_graph: EbdGraph, converter: DotToSvgConverter)

def _dump_json(json_path: Path, ebd_table: EbdTable | EbdTableMetaData) -> None:
with open(json_path, "w+", encoding="utf-8") as json_file:
json.dump(cattrs.unstructure(ebd_table), json_file, ensure_ascii=False, indent=2, sort_keys=True)
if isinstance(ebd_table, EbdTableMetaData):
json.dump(
cattrs.unstructure(EbdTable(metadata=ebd_table, rows=[])),
Expand Down
6 changes: 6 additions & 0 deletions unittests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
tests the main script
"""

import json
from pathlib import Path
from typing import Literal

Expand Down Expand Up @@ -37,3 +38,8 @@ def test_main(
# in the repo root
_main(input_path, tmp_path, export_types)
# we don't assert on the results but instead just check that it doesn't crash
json_files = list(tmp_path.glob("*.json"))
for json_file in json_files:
assert json_file.exists()
with open(json_file, "r", encoding="utf-8") as f:
_ = json.load(f) # must be valid json

0 comments on commit a1c879f

Please sign in to comment.