Skip to content

Commit

Permalink
apply: Add test for minimal-style deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
craigds committed Sep 2, 2022
1 parent 18b8f93 commit 0b8629b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion kart/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def apply_patch(
@click.argument("patch_file", type=click.File("r", encoding="utf-8"))
def apply(ctx, **kwargs):
"""
Applies and commits the given JSON patch (as created by `kart show -o json`)
Applies and commits the given JSON patch (as created by `kart create-patch`)
"""
repo = ctx.obj.repo
apply_patch(repo=repo, **kwargs)
Expand Down
27 changes: 26 additions & 1 deletion tests/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def test_apply_minimal_style_patch_without_base(data_archive, cli_runner, tmp_pa
assert r.exit_code == PATCH_DOES_NOT_APPLY, r.stderr


def test_apply_minimal_style_meta_patch(data_archive, cli_runner, tmp_path):
def test_apply_minimal_style_meta_patch_with_update(data_archive, cli_runner, tmp_path):
patch = points_patch(
{
"meta": {
Expand Down Expand Up @@ -324,6 +324,31 @@ def test_apply_minimal_style_meta_patch(data_archive, cli_runner, tmp_path):
assert r.exit_code == PATCH_DOES_NOT_APPLY, r.stderr


def test_apply_minimal_style_meta_patch_with_delete(data_archive, cli_runner, tmp_path):
patch = points_patch(
{
"meta": {
"metadata.xml": {
# content is ignored, so this must work
"-": None,
}
}
}
)
with data_archive("points"):
with write_patch(patch, tmp_path) as patch_path:
r = cli_runner.invoke(["apply", patch_path])
assert r.exit_code == 0, r.stderr

# Check that the change was actually applied
r = cli_runner.invoke(["show", "-o", "json", "HEAD"])
assert r.exit_code == 0
show = json.loads(r.stdout)
meta = show["kart.diff/v1+hexwkb"]["nz_pa_points_topo_150k"]["meta"]
# metadata was deleted
assert meta["metadata.xml"].keys() == {"-"}


def test_apply_minimal_style_feature_patch_with_edit(
data_archive, cli_runner, tmp_path
):
Expand Down

0 comments on commit 0b8629b

Please sign in to comment.