Skip to content

Commit

Permalink
feat(json): serialize None as null, close #622
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The JSONSnapshotExtension now serializes Python's None as "null" rather than "None".
  • Loading branch information
Noah Negin-Ulster committed Dec 30, 2022
1 parent f9c6aba commit c330680
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/syrupy/extensions/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _filter(
elif matcher:
data = matcher(data=data, path=path)

if isinstance(data, (int, float, str)):
if isinstance(data, (int, float, str)) or data is None:
return data

filtered_dct: Dict[Any, Any]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"empty_dict": {},
"empty_list": [],
"none": "None"
"none": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"datetime": "2021-01-31T23:59:00.000000",
"float": 4.2,
"int": -1,
"null": "None",
"null": null,
"str": "foo"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"a": "Some ttext.",
"key": null,
"multi\nline\nkey": "Some morre text."
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"None"
null
1 change: 1 addition & 0 deletions tests/syrupy/extensions/json/test_json_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def test_set(snapshot_json, actual):
"multi\nline\nkey": "Some morre text.",
frozenset({"1", "2"}): ["1", 2],
ExampleTuple(a=1, b=2, c=3, d=4): {"e": False},
"key": None,
},
{},
{"key": ["line1\nline2"]},
Expand Down

1 comment on commit c330680

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: c330680 Previous: 02abef5 Ratio
benchmarks/test_1000x.py::test_1000x_reads 0.7565940890112609 iter/sec (stddev: 0.05404360420624151) 0.8381195242511715 iter/sec (stddev: 0.04240394140227035) 1.11
benchmarks/test_1000x.py::test_1000x_writes 0.7551367850943955 iter/sec (stddev: 0.06249030230473292) 0.8626650008455868 iter/sec (stddev: 0.05153168408309042) 1.14
benchmarks/test_standard.py::test_standard 0.720072681359854 iter/sec (stddev: 0.06677892596066112) 0.7465173870618954 iter/sec (stddev: 0.1502009356924296) 1.04

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.