当前位置: 首页>>代码示例>>Python>>正文


Python nbdime.merge_notebooks函数代码示例

本文整理汇总了Python中nbdime.merge_notebooks函数的典型用法代码示例。如果您正苦于以下问题:Python merge_notebooks函数的具体用法?Python merge_notebooks怎么用?Python merge_notebooks使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了merge_notebooks函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_inline_merge_source_empty

def test_inline_merge_source_empty():
    base = new_notebook()
    local = new_notebook()
    remote = new_notebook()
    expected = new_notebook()
    merged, decisions = merge_notebooks(base, local, remote)
    assert merged == expected
开发者ID:vidartf,项目名称:nbdime,代码行数:7,代码来源:test_merge_notebooks_inline.py

示例2: test_metadata_union_strategy_not_applied_immutable_on_dict

def test_metadata_union_strategy_not_applied_immutable_on_dict():
    # Conflicting cell inserts at same location as removing old cell
    expected_partial_source = [["remote\n", "some other\n", "lines\n", "to align\n"]]
    expected_partial_metadata = [{'myval': 5}]
    expected_partial_outputs = [["local\nsome other\nlines\nto align\n", "output2", "output3"]]
    base, local, remote, expected_partial = _make_notebook_with_multi_conflicts(
        expected_partial_source, expected_partial_metadata, expected_partial_outputs
    )
    base.cells[0].metadata['myval'] = 5
    local.cells[0].metadata['myval'] = 22
    remote.cells[0].metadata['myval'] = 13

    expected_conflicts = [{
        'action': 'base',
        'common_path': ('cells', 0, 'metadata'),
        'conflict': True,
        'local_diff': [{'key': 'myval', 'op': 'replace', 'value': 22}],
        'remote_diff': [{'key': 'myval', 'op': 'replace', 'value': 13}]
    }]
    merge_args = copy.deepcopy(args)
    merge_args.merge_strategy = "union"
    merge_args.input_strategy = "use-remote"
    merge_args.output_strategy = "use-local"

    partial, decisions = merge_notebooks(base, local, remote, merge_args)

    _check(partial, expected_partial, decisions, expected_conflicts)
开发者ID:vidartf,项目名称:nbdime,代码行数:27,代码来源:test_merge_notebooks.py

示例3: test_autoresolve_notebook_ec

def test_autoresolve_notebook_ec():
    args = None
    # We need a source here otherwise the cells are not aligned
    source = "def foo(x, y):\n    return x**y"

    base = nbformat.v4.new_notebook()
    base["cells"].append(nbformat.v4.new_code_cell())
    base["cells"][0]["source"] = source
    base["cells"][0]["execution_count"] = 1

    local = copy.deepcopy(base)
    remote = copy.deepcopy(base)
    expected = copy.deepcopy(base)
    local["cells"][0]["execution_count"] = 2
    remote["cells"][0]["execution_count"] = 3
    expected["cells"][0]["execution_count"] = None

    merged, local_conflicts, remote_conflicts = merge_notebooks(base, local, remote, args)

    if 0:
        print()
        print(merged)
        print(local_conflicts)
        print(remote_conflicts)
        print()

    assert merged == expected
    assert local_conflicts == []
    assert remote_conflicts == []
开发者ID:gahjelle,项目名称:nbdime,代码行数:29,代码来源:test_merge_notebooks.py

示例4: test_inline_merge_source_cell_deletions

def test_inline_merge_source_cell_deletions():
    "Cell deletions on both sides, onesided and agreed."
    base = code_nb([
        "first source",
        "other text",
        "yet more content",
        "and a final line",
        ])
    local = code_nb([
        #"first source",
        "other text",
        #"yet more content",
        #"and a final line",
        ])
    remote = code_nb([
        "first source",
        #"other text",
        "yet more content",
        #"and a final line",
        ])
    empty = code_nb([])
    expected = code_nb([])
    for a in [base, local, remote, empty]:
        for b in [base, local, remote, empty]:
            merged, decisions = merge_notebooks(base, a, b)
            if a is b:
                assert merged == a
            elif a is base:
                assert merged == b
            elif b is base:
                assert merged == a
            else:
                # All other combinations will delete all cells
                assert merged == empty
开发者ID:vidartf,项目名称:nbdime,代码行数:34,代码来源:test_merge_notebooks_inline.py

示例5: test_inline_merge_notebook_version

def test_inline_merge_notebook_version():
    "Minor version gets bumped to max."
    base = new_notebook(nbformat=4, nbformat_minor=0)
    local = new_notebook(nbformat=4, nbformat_minor=1)
    remote = new_notebook(nbformat=4, nbformat_minor=2)
    expected = new_notebook(nbformat=4, nbformat_minor=2)
    merged, decisions = merge_notebooks(base, local, remote)
    assert expected == merged
开发者ID:vidartf,项目名称:nbdime,代码行数:8,代码来源:test_merge_notebooks_inline.py

示例6: test_inline_merge_dummy_notebooks

def test_inline_merge_dummy_notebooks():
    "Just the basic empty notebook passes through."
    base = new_notebook()
    local = new_notebook()
    remote = new_notebook()
    expected = new_notebook()
    merged, decisions = merge_notebooks(base, local, remote)
    assert expected == merged
开发者ID:vidartf,项目名称:nbdime,代码行数:8,代码来源:test_merge_notebooks_inline.py

示例7: test_inline_merge_empty_notebooks

def test_inline_merge_empty_notebooks():
    "Missing fields all around passes through."
    base = {}
    local = {}
    remote = {}
    expected = {}
    merged, decisions = merge_notebooks(base, local, remote)
    assert expected == merged
开发者ID:vidartf,项目名称:nbdime,代码行数:8,代码来源:test_merge_notebooks_inline.py

示例8: test_inline_merge_source_onesided_only

def test_inline_merge_source_onesided_only():
    "A mix of changes on one side (delete, patch, remove)."
    base = code_nb([
        "first source",
        "other text",
        "yet more content",
        ])
    changed = code_nb([
        #"first source", # deleted
        "other text v2",
        "a different cell inserted",
        "yet more content",
        ])
    merged, decisions = merge_notebooks(base, changed, base)
    assert merged == changed
    merged, decisions = merge_notebooks(base, base, changed)
    assert merged == changed
开发者ID:vidartf,项目名称:nbdime,代码行数:17,代码来源:test_merge_notebooks_inline.py

示例9: test_inline_merge_attachments

def test_inline_merge_attachments():
    # FIXME: Use output creation utils Vidar wrote in another test file
    base = new_notebook()
    local = new_notebook()
    remote = new_notebook()
    expected = new_notebook()
    merged, decisions = merge_notebooks(base, local, remote)
    assert merged == expected
开发者ID:vidartf,项目名称:nbdime,代码行数:8,代码来源:test_merge_notebooks_inline.py

示例10: test_autoresolve_inline_source_conflict

def test_autoresolve_inline_source_conflict(db):
    nbb = db["inline-conflict--1"]
    nbl = db["inline-conflict--2"]
    nbr = db["inline-conflict--3"]

    args = builder.parse_args(["", "", ""])
    args.merge_strategy = 'inline'
    merged, decisions = merge_notebooks(nbb, nbl, nbr, args)

    # Has conflicts
    assert any(d.conflict for d in decisions)

    source = merged.cells[0].source

    git_expected = """\
x = 1
<<<<<<< local
y = 3
print(x * y)
=======
q = 3.1
print(x + q)
>>>>>>> remote
"""

    builtin_expected_course = """\
<<<<<<< local
x = 1
y = 3
z = 4
print(x * y / z)
=======
x = 1
q = 3.1
print(x + q)
>>>>>>> remote
"""
    # ||||||| base
    # x = 1
    # y = 3
    # print(x * y)

    builtin_expected_finegrained = """\
x = 1
<<<<<<< local
y = 3
z = 4
print(x * y / z)
=======
q = 3.1
print(x + q)
>>>>>>> remote
"""

    expected = builtin_expected_finegrained

    assert source == expected
开发者ID:willingc,项目名称:nbdime,代码行数:57,代码来源:test_autoresolve.py

示例11: test_inline_merge_source_add_to_line

def test_inline_merge_source_add_to_line():
    "More elaborate test of cell deletions on both sides, onesided and agreed."
    # Note: Merge rendering of conflicted sources here will depend on git/diff/builtin params and availability
    base = code_nb([
        "first source",
        "other text",
        "this cell will be deleted and patched\nhere we add",
        "yet more content",
        "and a final line",
        ])
    local = code_nb([
        "1st source",  # onesided change
        "other text",
        #"this cell will be deleted and patched",
        "some more content",  # twosided equal change
        "And a Final line",  # twosided conflicted change
        ])
    remote = code_nb([
        "first source",
        "other text?",  # onesided change
        "this cell will be deleted and patched\nhere we add text to a line",
        "some more content",   # equal
        "and The final Line",  # conflicted
        ])
    expected = code_nb([
        "1st source",
        "other text?",
        #'<<<<<<< local <CELL DELETED>\n\n=======\nthis cell will be deleted and modified\n>>>>>>> remote'
        '<<<<<<< LOCAL CELL DELETED >>>>>>>\nthis cell will be deleted and patched\nhere we add text to a line',
        "some more content",  # equal
        '<<<<<<< local\nAnd a Final line\n=======\nand The final Line\n>>>>>>> remote'
        ])
    merged, decisions = merge_notebooks(base, local, remote)
    assert merged == expected
    expected = code_nb([
        "1st source",
        "other text?",
        #'<<<<<<< local\nthis cell will be deleted and modified\n=======\n>>>>>>> remote <CELL DELETED>'
        '<<<<<<< REMOTE CELL DELETED >>>>>>>\nthis cell will be deleted and patched\nhere we add text to a line',
        "some more content",
        '<<<<<<< local\nand The final Line\n=======\nAnd a Final line\n>>>>>>> remote'
        ])
    merged, decisions = merge_notebooks(base, remote, local)
    assert merged == expected
开发者ID:vidartf,项目名称:nbdime,代码行数:44,代码来源:test_merge_notebooks_inline.py

示例12: _check_outputs

def _check_outputs(base, local, remote, expected_partial, expected_conflicts, merge_args=None):
    base = outputs_to_notebook(base)
    local = outputs_to_notebook(local)
    remote = outputs_to_notebook(remote)
    expected_partial = outputs_to_notebook(expected_partial)
    merge_args = merge_args or args

    partial, decisions = merge_notebooks(base, local, remote, merge_args)

    _check(partial, expected_partial, decisions, expected_conflicts)
开发者ID:vidartf,项目名称:nbdime,代码行数:10,代码来源:test_merge_notebooks.py

示例13: _check_sources

def _check_sources(base, local, remote, expected_partial, expected_conflicts, merge_args=None):
    base = src2nb(base)
    local = src2nb(local)
    remote = src2nb(remote)
    expected_partial = src2nb(expected_partial)
    merge_args = merge_args or args

    partial, decisions = merge_notebooks(base, local, remote, merge_args)

    _check(partial, expected_partial, decisions, expected_conflicts)
开发者ID:vidartf,项目名称:nbdime,代码行数:10,代码来源:test_merge_notebooks.py

示例14: test_inline_merge_source_patch_delete_conflicts_both_ends

def test_inline_merge_source_patch_delete_conflicts_both_ends():
    "More elaborate test of cell deletions on both sides, onesided and agreed."
    # Note: Merge rendering of conflicted sources here will depend on git/diff/builtin params and availability
    base = code_nb([
        "first source will be modified",
        "other text",
        "this cell will be untouched",
        "yet more content",
        "and final line will be changed",
        ])
    local = code_nb([
        "first source will be modified on one side",
        "other text",
        "this cell will be untouched",
        "yet more content",
        #"and final line will be deleted locally",
        ])
    remote = code_nb([
        #"first source will be deleted remotely",
        "other text",
        "this cell will be untouched",
        "yet more content",
        "and final line will be changed on one side",
        ])
    expected = code_nb([
        '<<<<<<< REMOTE CELL DELETED >>>>>>>\nfirst source will be modified on one side',
        "other text",
        "this cell will be untouched",
        "yet more content",
        '<<<<<<< LOCAL CELL DELETED >>>>>>>\nand final line will be changed on one side',
        ])
    merged, decisions = merge_notebooks(base, local, remote)
    assert merged == expected
    expected = code_nb([
        '<<<<<<< LOCAL CELL DELETED >>>>>>>\nfirst source will be modified on one side',
        "other text",
        "this cell will be untouched",
        "yet more content",
        '<<<<<<< REMOTE CELL DELETED >>>>>>>\nand final line will be changed on one side',
        ])
    merged, decisions = merge_notebooks(base, remote, local)
    assert merged == expected
开发者ID:vidartf,项目名称:nbdime,代码行数:42,代码来源:test_merge_notebooks_inline.py

示例15: test_inline_merge_source_all_equal

def test_inline_merge_source_all_equal():
    base = code_nb([
        "first source",
        "other text",
        "yet more content",
    ])
    local = base
    remote = base
    expected = base
    merged, decisions = merge_notebooks(base, local, remote)
    assert merged == expected
开发者ID:vidartf,项目名称:nbdime,代码行数:11,代码来源:test_merge_notebooks_inline.py


注:本文中的nbdime.merge_notebooks函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。