Skip to content

Commit 0be1ce5

Browse files
committed
Fix Serialization
1 parent 7d016ba commit 0be1ce5

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

cppython/utility.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import json
66
from pathlib import Path
77

8+
from pydantic import FilePath
9+
from pydantic.types import DirectoryPath
10+
811
from cppython.schema import CMakePresets, ConfigurePreset
912

1013

@@ -23,18 +26,19 @@ def write_preset(name: str, path: Path, presets: CMakePresets) -> Path:
2326
"""
2427
file = path / f"{name}.json"
2528

29+
serialized = json.loads(presets.json())
2630
with open(file, "w", encoding="utf8") as json_file:
27-
json.dump(presets.dict(), json_file, ensure_ascii=False, indent=2)
31+
json.dump(serialized, json_file, ensure_ascii=False, indent=2)
2832

2933
return file
3034

3135

32-
def write_presets(tool_path: Path, generator_output: list[tuple[str, Path]]) -> None:
36+
def write_presets(tool_path: DirectoryPath, generator_output: list[tuple[str, FilePath]]) -> None:
3337
"""
3438
Write the cppython presets
3539
"""
3640

37-
def write_generator_presets(tool_path: Path, generator_name: str, toolchain_path: Path) -> Path:
41+
def write_generator_presets(tool_path: DirectoryPath, generator_name: str, toolchain_path: FilePath) -> FilePath:
3842
"""
3943
Write a generator preset.
4044
@returns - The written json file

tests/unit/test_utility.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ def test_preset_read_write(self, tmpdir: Path):
2323

2424
assert presets == output
2525

26-
def test_presets(self, tmpdir: Path):
26+
def test_presets(self, tmpdir):
2727
"""
2828
TODO
2929
"""
3030

31-
input_toolchain = tmpdir / "input.cmake"
31+
temporary_directory = Path(tmpdir)
32+
33+
input_toolchain = temporary_directory / "input.cmake"
3234

3335
with open(input_toolchain, "w", encoding="utf8") as file:
3436
file.write("")
3537

3638
generator_output = [("test", input_toolchain)]
37-
write_presets(tmpdir, generator_output)
39+
write_presets(temporary_directory, generator_output)

0 commit comments

Comments
 (0)