Пример #1
0
def test_nbmerge_app_null_base(filespath):
    afn = os.path.join(filespath, "multilevel-test-base.ipynb")
    bfn = os.path.join(filespath, "multilevel-test-local.ipynb")

    # Two identical files added (null base)
    args = nbmergeapp._build_arg_parser().parse_args(
        [EXPLICIT_MISSING_FILE, afn, afn])
    assert 0 == main_merge(args)

    # Two conflicting files added (null base)
    args = nbmergeapp._build_arg_parser().parse_args(
        [EXPLICIT_MISSING_FILE, afn, bfn])
    assert 1 == main_merge(args)
Пример #2
0
def test_nbmerge_app_null_base(filespath, reset_log):
    afn = os.path.join(filespath, "multilevel-test-base.ipynb")
    bfn = os.path.join(filespath, "multilevel-test-local.ipynb")

    # Two identical files added (null base)
    args = nbmergeapp._build_arg_parser().parse_args([
        EXPLICIT_MISSING_FILE, afn, afn])
    assert 0 == main_merge(args)

    # Two conflicting files added (null base)
    args = nbmergeapp._build_arg_parser().parse_args([
        EXPLICIT_MISSING_FILE, afn, bfn])
    assert 1 == main_merge(args)
Пример #3
0
def test_nbmerge_app(tempfiles, capsys):
    bfn = os.path.join(tempfiles, "multilevel-test-base.ipynb")
    lfn = os.path.join(tempfiles, "multilevel-test-local.ipynb")
    rfn = os.path.join(tempfiles, "multilevel-test-remote.ipynb")
    ofn = os.path.join(tempfiles, "output.ipynb")

    args = nbmergeapp._build_arg_parser().parse_args(
        [bfn, lfn, rfn, '--log-level=DEBUG'])
    assert args.log_level == 'DEBUG'
    assert nbdime.log.logger.level == logging.DEBUG

    assert 0 == main_merge(args)

    nb_stdout, err = capsys.readouterr()

    assert 0 == nbmergeapp.main([bfn, lfn, rfn, '--out', ofn])
    out, err = capsys.readouterr()
    # no stdout when sending output to file
    assert out == ''

    assert os.path.exists(ofn)

    with io.open(ofn, 'r', encoding='utf8') as f:
        nb_file = f.read()

    assert nb_stdout == nb_file
Пример #4
0
def test_nbmerge_app(tempfiles, capsys):
    p = tempfiles
    bfn = os.path.join(p, "multilevel-test-base.ipynb")
    lfn = os.path.join(p, "multilevel-test-local.ipynb")
    rfn = os.path.join(p, "multilevel-test-remote.ipynb")
    ofn = os.path.join(p, "output.ipynb")

    args = nbmergeapp._build_arg_parser().parse_args([bfn, lfn, rfn, '--log-level=DEBUG'])
    assert args.log_level == 'DEBUG'
    assert nbdime.log.logger.level == logging.DEBUG

    assert 0 == main_merge(args)

    nb_stdout, err = capsys.readouterr()

    assert 0 == nbmergeapp.main([bfn, lfn, rfn, '-o', ofn])
    out, err = capsys.readouterr()
    # no stdout when sending output to file
    assert out == ''

    assert os.path.exists(ofn)

    with io.open(ofn, 'r', encoding='utf8') as f:
        nb_file = f.read()

    assert nb_stdout == nb_file
Пример #5
0
def test_nbmerge_app_null_side(filespath):
    afn = os.path.join(filespath, "multilevel-test-base.ipynb")
    bfn = os.path.join(filespath, "multilevel-test-local.ipynb")

    # Local deleted, remote modified
    args = nbmergeapp._build_arg_parser().parse_args(
        [afn, EXPLICIT_MISSING_FILE, bfn])
    assert 1 == main_merge(args)

    # Remote deleted, local modified
    args = nbmergeapp._build_arg_parser().parse_args(
        [afn, bfn, EXPLICIT_MISSING_FILE])
    assert 1 == main_merge(args)

    # Both deleted
    args = nbmergeapp._build_arg_parser().parse_args(
        [afn, EXPLICIT_MISSING_FILE, EXPLICIT_MISSING_FILE])
    assert 0 == main_merge(args)
Пример #6
0
def test_nbmerge_app_no_colors(filespath):
    # Simply check that the --color-words argument is accepted, not behavior
    bfn = os.path.join(filespath, "multilevel-test-base.ipynb")
    lfn = os.path.join(filespath, "multilevel-test-local.ipynb")
    rfn = os.path.join(filespath, "multilevel-test-remote.ipynb")

    args = nbmergeapp._build_arg_parser().parse_args(
        [bfn, lfn, rfn, '--no-color'])
    assert 0 == main_merge(args)
Пример #7
0
def test_nbmerge_app_null_side(filespath, reset_log):
    afn = os.path.join(filespath, "multilevel-test-base.ipynb")
    bfn = os.path.join(filespath, "multilevel-test-local.ipynb")

    # Local deleted, remote modified
    args = nbmergeapp._build_arg_parser().parse_args([
        afn, EXPLICIT_MISSING_FILE, bfn])
    assert 1 == main_merge(args)

    # Remote deleted, local modified
    args = nbmergeapp._build_arg_parser().parse_args([
        afn, bfn, EXPLICIT_MISSING_FILE])
    assert 1 == main_merge(args)

    # Both deleted
    args = nbmergeapp._build_arg_parser().parse_args([
        afn, EXPLICIT_MISSING_FILE, EXPLICIT_MISSING_FILE])
    assert 0 == main_merge(args)
Пример #8
0
import pytest
import copy
from six import string_types
import nbformat

from nbdime.diff_format import op_patch, op_addrange, op_removerange, op_replace
from .utils import sources_to_notebook, outputs_to_notebook, have_git
from nbdime.nbmergeapp import _build_arg_parser
from nbdime import merge_notebooks, apply_decisions
from nbdime.diffing.notebooks import diff_notebooks, set_notebook_diff_targets
from nbdime.merging.notebooks import decide_merge_with_diff, Strategies

# FIXME: Extend tests to more merge situations!

# Setup default args for merge app
builder = _build_arg_parser()
args = builder.parse_args(["", "", ""])


def test_merge_matching_notebooks(matching_nb_triplets, reset_log):
    "Test merge on pairs of notebooks with the same basename in the test suite."
    base, local, remote = matching_nb_triplets
    merged, decisions = merge_notebooks(base, local, remote)
    # We can't really automate a generic merge test,
    # at least passing through code here...


def test_autoresolve_notebook_ec():
    # We need a source here otherwise the cells are not aligned
    source = "def foo(x, y):\n    return x**y"
Пример #9
0
# FIXME: Extend tests to more merge situations!


# Tests here assume default autoresolve behaviour at time of writing,
# this is likely to change and it's ok to update the tests to reflect
# new behaviour as needed!


base = {"foo": 1}
local = {"foo": 2}
remote = {"foo": 3}
conflicted_decisions = decide_merge(base, local, remote)

# Setup default args for merge app
builder = _build_arg_parser()


def test_autoresolve_dict_fail():
    """Check that "fail" strategy results in proper exception raised."""
    strategies = Strategies({"/foo": "fail"})
    with pytest.raises(RuntimeError):
        autoresolve(base, conflicted_decisions, strategies)

    base2 = {"foo": {"bar": 1}}
    local2 = {"foo": {"bar": 2}}
    remote2 = {"foo": {"bar": 3}}
    strategies = Strategies({"/foo/bar": "fail"})
    decisions = decide_merge(base2, local2, remote2)
    with pytest.raises(RuntimeError):
        autoresolve(base2, decisions, strategies)