Skip to content

Commit

Permalink
Implement --diff-format for json-lines output diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
craigds committed Nov 5, 2024
1 parent f3eed1a commit 9c1010e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
11 changes: 10 additions & 1 deletion kart/json_diff_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,16 @@ def write_ds_diff(self, ds_path, ds_diff, diff_format=DiffFormat.FULL):
)

self.write_meta_deltas(ds_path, ds_diff)
self.write_filtered_dataset_deltas(ds_path, ds_diff)
if diff_format == DiffFormat.FULL.value:
self.write_filtered_dataset_deltas(ds_path, ds_diff)
elif diff_format == DiffFormat.NO_DATA_CHANGES.value:
self.dump(
{
"type": "dataChanges",
"dataset": ds_path,
"value": ds_diff["data_changes"],
}
)

def write_meta_deltas(self, ds_path, ds_diff):
if "meta" not in ds_diff:
Expand Down
26 changes: 26 additions & 0 deletions tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2204,3 +2204,29 @@ def test_diff_format_no_data_changes_json(cli_runner, data_archive):
assert output["kart.diff/v1+hexwkb"] == {
"nz_pa_points_topo_150k": {"data_changes": True}
}


def test_diff_json_lines_with_no_data_changes(cli_runner, data_archive, monkeypatch):
# Check that the json output contains a boolean for data_changes (feature/tile changes)
with data_archive("points.tgz"):
r = cli_runner.invoke(
[
"diff",
"--diff-format=no-data-changes",
"-o",
"json-lines",
"HEAD^...HEAD",
]
)
assert r.exit_code == 0, r.stderr
output = r.stdout.splitlines()
assert len(output) == 4
jsons = [json.loads(line) for line in output]
types = [j["type"] for j in jsons]
# note no "feature" items here
assert types == ["version", "datasetInfo", "metaInfo", "dataChanges"]
assert jsons[-1] == {
"type": "dataChanges",
"dataset": "nz_pa_points_topo_150k",
"value": True,
}

0 comments on commit 9c1010e

Please sign in to comment.