Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
Remove some skips that are no longer needed, fix tests that were marked xfail due to not being completed, and split some tests that had some hard-coded logical branches (`if 0:`) - fixing the previously disabled branch.
  • Loading branch information
vidartf committed Jul 7, 2023
1 parent 2413cec commit a1818cb
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 70 deletions.
1 change: 1 addition & 0 deletions nbdime/tests/test_decision_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def test_pop_patch_multilevel():

@pytest.mark.xfail()
def test_build_diffs_unsorted():
# expected to fail, since `validated` call is significant here!
b = MergeDecisionBuilder()
b.onesided((), [op_remove('a')], None)
b.onesided(('b',), [op_remove('j')], None)
Expand Down
160 changes: 93 additions & 67 deletions nbdime/tests/test_merge_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,88 +54,121 @@ def test_autoresolve_notebook_ec():
assert not any(d.conflict for d in decisions)


def test_merge_cell_sources_neighbouring_inserts():
def test_merge_cell_sources_neighbouring_inserts_mergetool():
base = strip_cell_ids(sources_to_notebook([[
"def f(x):",
"def f(x):\n",
" return x**2",
], [
"def g(y):",
"def g(y):\n",
" return y + 2",
],
]))
local = strip_cell_ids(sources_to_notebook([[
"def f(x):",
"def f(x):\n",
" return x**2",
], [
"print(f(3))",
], [
"def g(y):",
"def g(y):\n",
" return y + 2",
],
]))
remote = strip_cell_ids(sources_to_notebook([[
"def f(x):",
"def f(x):\n",
" return x**2",
], [
"print(f(7))",
], [
"def g(y):",
"def g(y):\n",
" return y + 2",
],
]))
if 1:
expected_partial = base
expected_conflicts = [{
"common_path": ("cells",),
"local_diff": [op_addrange(1, [local.cells[1]])],
"remote_diff": [op_addrange(1, [remote.cells[1]])]
}]
else:
# Strategy local_then_remote:
expected_partial = sources_to_notebook([[
"def f(x):",
" return x**2",
], [
"print(f(3))",
], [
"print(f(7))",
], [
"def g(y):",
" return y + 2",
],
])
expected_conflicts = []
expected_partial = base
expected_conflicts = [{
"common_path": ("cells",),
"local_diff": [op_addrange(1, [local.cells[1]])],
"remote_diff": [op_addrange(1, [remote.cells[1]])]
}]

merge_args = copy.deepcopy(args)
merge_args.merge_strategy = "mergetool"

_check_sources(base, local, remote, expected_partial, expected_conflicts, merge_args, ignore_cell_ids=True)


def test_merge_cell_sources_neighbouring_inserts_union():
base = strip_cell_ids(sources_to_notebook([[
"def f(x):\n",
" return x**2",
], [
"def g(y):\n",
" return y + 2",
],
]))
local = strip_cell_ids(sources_to_notebook([[
"def f(x):\n",
" return x**2",
], [
"print(f(3))",
], [
"def g(y):\n",
" return y + 2",
],
]))
remote = strip_cell_ids(sources_to_notebook([[
"def f(x):\n",
" return x**2",
], [
"print(f(7))",
], [
"def g(y):\n",
" return y + 2",
],
]))
expected_partial = sources_to_notebook([[
"def f(x):\n",
" return x**2",
], [
"print(f(3))",
], [
"print(f(7))",
], [
"def g(y):\n",
" return y + 2",
],
])
expected_conflicts = []

merge_args = copy.deepcopy(args)
merge_args.merge_strategy = "union"

_check_sources(base, local, remote, expected_partial, expected_conflicts, merge_args, ignore_cell_ids=True)


def test_merge_cell_sources_separate_inserts():
base = strip_cell_ids(sources_to_notebook([[
"def f(x):",
"def f(x):\n",
" return x**2",
], [
"def g(y):",
"def g(y):\n",
" return y + 2",
],
]))
local = strip_cell_ids(sources_to_notebook([[
"print(f(3))",
], [
"def f(x):",
"def f(x):\n",
" return x**2",
], [
"def g(y):",
"def g(y):\n",
" return y + 2",
],
]))
remote = strip_cell_ids(sources_to_notebook([[
"def f(x):",
"def f(x):\n",
" return x**2",
], [
"def g(y):",
"def g(y):\n",
" return y + 2",
], [
"print(f(7))",
Expand All @@ -144,10 +177,10 @@ def test_merge_cell_sources_separate_inserts():
expected = strip_cell_ids(sources_to_notebook([[
"print(f(3))",
], [
"def f(x):",
"def f(x):\n",
" return x**2",
], [
"def g(y):",
"def g(y):\n",
" return y + 2",
], [
"print(f(7))",
Expand Down Expand Up @@ -434,63 +467,59 @@ def test_merge_interleave_cell_add_remove():
_check_sources(base, local, remote, expected_partial, expected_conflicts, merge_args, ignore_cell_ids=True)


@pytest.mark.xfail
def test_merge_conflicts_get_diff_indices_shifted():
# Trying to induce conflicts with shifting of diff indices
source = [
"def foo(x, y):",
" z = x * y",
" return z",
"def foo(x, y):\n",
" z = x * y\n",
" return z\n",
]
local = [["same"], source+["local"], ["different"]]
base = [["same"], source+["base"], ["same"]]
remote = [["different"], source+["remote"], ["same"]]
local = [["same"], source + ["local\n"], ["different"]]
base = [["same"], source + ["base\n"], ["same"]]
remote = [["different"], source + ["remote\n"], ["same"]]
expected_partial = [["different"],
source + ["local", "remote"],
source + ["base\n"],
["different"]]
expected_conflicts = [{
"common_path": (),
"common_path": ('cells', 1, 'source'),
"local_diff": [
op_removerange(1, 1),
op_addrange(1, ["left"]),
op_addrange(3, ["local\n"]),
op_removerange(3, 1),
],
"remote_diff": [
op_removerange(1, 1),
op_addrange(1, ["right"]),
op_addrange(3, ["remote\n"]),
op_removerange(3, 1),
]
}]
_check_sources(base, local, remote, expected_partial, expected_conflicts)

merge_args = copy.deepcopy(args)
merge_args.merge_strategy = "mergetool"

_check_sources(base, local, remote, expected_partial, expected_conflicts, merge_args)

# Trying to induce conflicts with shifting of diff indices
source = [
"def foo(x, y):",
" z = x * y",
" return z",
]
local = [["same"],
source + ["long line with minor change L"],
source + ["long line with minor change left"],
["different"]]
base = [["same"],
source + ["long line with minor change"],
["same"]]
remote = [["different"],
source + ["long line with minor change R"],
source + ["long line with minor change right"],
["same"]]
expected_partial = [["different"],
source + ["long line with minor change"],
["different"]]
expected_conflicts = [{
"common_path": (),
"common_path": ('cells', 1, 'source', 3),
"local_diff": [
op_removerange(1, 1),
op_addrange(1, ["left"]),
op_addrange(27, " left"),
],
"remote_diff": [
op_removerange(1, 1),
op_addrange(1, ["right"]),
op_addrange(27, " right"),
]
}]
_check_sources(base, local, remote, expected_partial, expected_conflicts)
_check_sources(base, local, remote, expected_partial, expected_conflicts, merge_args)


@pytest.mark.xfail
Expand Down Expand Up @@ -582,7 +611,6 @@ def test_merge_input_strategy_base_source_conflict():
_check_sources(base, local, remote, expected_partial, expected_conflicts, merge_args, ignore_cell_ids=True)


@pytest.mark.skip
def test_merge_input_strategy_union_source_conflict():
# Conflicting cell inserts at same location as removing old cell
local = [["local\n", "some other\n", "lines\n", "to align\n"]]
Expand Down Expand Up @@ -703,7 +731,6 @@ def test_merge_output_strategy_base_conflict():
_check_outputs(base, local, remote, expected_partial, expected_conflicts, merge_args, True)


@pytest.mark.skip
def test_merge_output_strategy_union_conflict():
# Conflicting cell inserts at same location as removing old cell
local = [["local\nsome other\nlines\nto align\n", "output2", "output3"]]
Expand Down Expand Up @@ -779,7 +806,6 @@ def _make_notebook_with_multi_conflicts(
return base, local, remote, expected_partial


@pytest.mark.skip
def test_metadata_union_strategy_metadata():
# Conflicting cell inserts at same location as removing old cell
expected_partial_source = [["remote\n", "some other\n", "lines\n", "to align\n"]]
Expand Down
3 changes: 0 additions & 3 deletions nbdime/tests/test_merge_notebooks_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ def test_decide_merge_simple_list_insert_conflict_resolution():
assert apply_decisions(b, decisions) == []
assert not any(d.conflict for d in decisions)

@pytest.mark.skip
def test_decide_merge_simple_list_insert_conflict_resolution__union():
# local and remote adds an entry each
b = [1]
Expand Down Expand Up @@ -282,7 +281,6 @@ def test_decide_merge_list_conflicting_insertions_separate_chunks_v2():
assert not resolved[1].conflict


@pytest.mark.skip
def test_decide_merge_list_conflicting_insertions_separate_chunks__union():
# local and remote adds an equal entry plus a different entry each
# First, test when insertions DO NOT chunk together:
Expand Down Expand Up @@ -329,7 +327,6 @@ def test_decide_merge_list_conflicting_insertions_in_chunks():
assert not any(d.conflict for d in resolved)


@pytest.mark.skip
def test_decide_merge_list_conflicting_insertions_in_chunks__union():
# Next, test when insertions DO chunk together:
b = [1, 9]
Expand Down

0 comments on commit a1818cb

Please sign in to comment.