• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python nbdime.merge_notebooks函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_inline_merge_cells_replacement_unsimilar

def test_inline_merge_cells_replacement_unsimilar():
    base = sources_to_notebook([['unmodified'], ['base']], cell_type='markdown')
    local = sources_to_notebook([['unmodified'], ['local\n', 'friendly faces\n', '3.14']], cell_type='markdown')
    remote = sources_to_notebook([['unmodified'], ['remote\n', 'foo bar baz\n']], cell_type='markdown')
    expected = sources_to_notebook([
        ['unmodified'],
        [_cell_marker_format(("<"*7) + ' local')],
        ['local\n', 'friendly faces\n', '3.14'],
        [_cell_marker_format("="*7)],
        ['remote\n', 'foo bar baz\n'],
        [_cell_marker_format((">"*7) + ' remote')],
    ], cell_type='markdown')
    merged, decisions = merge_notebooks(base, local, remote)
    assert merged == expected
开发者ID:vidartf,项目名称:nbdime,代码行数:14,代码来源:test_merge_notebooks_inline.py


示例17: test_only_outputs

def test_only_outputs(db, reset_diff_targets):
    base = db["mixed-conflicts--1"]
    local = db["mixed-conflicts--2"]
    remote = db["mixed-conflicts--3"]
    set_notebook_diff_targets(False, True, False, False)

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

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

    assert len(decisions) > 0
    for d in decisions:
        path = d['common_path']
        # Still have some decisions on cell root, so avoid with len == 2 check
        assert len(path) == 2 or path[2] == 'outputs'
开发者ID:vidartf,项目名称:nbdime,代码行数:16,代码来源:test_merge_notebooks.py


示例18: _check

def _check(base, local, remote, expected_partial, expected_lco, expected_rco):
    base = src2nb(base)
    local = src2nb(local)
    remote = src2nb(remote)
    expected_partial = src2nb(expected_partial)

    args = None
    partial, lco, rco = merge_notebooks(base, local, remote, args)

    sources = [cell["source"] for cell in partial["cells"]]
    expected_sources = [cell["source"] for cell in expected_partial["cells"]]
    assert sources == expected_sources

    assert partial == expected_partial
    assert lco == expected_lco
    assert rco == expected_rco
开发者ID:gahjelle,项目名称:nbdime,代码行数:16,代码来源:test_merge_notebooks.py


示例19: test_inline_merge_cells_replacement_similar

def test_inline_merge_cells_replacement_similar():
    base = sources_to_notebook([['unmodified'], ['base']], cell_type='markdown')
    local = sources_to_notebook([['unmodified'], ['local']], cell_type='markdown')
    remote = sources_to_notebook([['unmodified'], ['remote']], cell_type='markdown')
    expected = sources_to_notebook([
        ['unmodified'],
        [
            ("<"*7) + ' local\n',
            'local\n',
            ("="*7) + '\n',
            'remote\n',
            (">"*7) + ' remote'
        ]
    ], cell_type='markdown')
    merged, decisions = merge_notebooks(base, local, remote)
    assert merged == expected
开发者ID:vidartf,项目名称:nbdime,代码行数:16,代码来源:test_merge_notebooks_inline.py


示例20: post

    def post(self):
        base_nb = self.get_notebook_argument("base")
        local_nb = self.get_notebook_argument("local")
        remote_nb = self.get_notebook_argument("remote")

        try:
            merged, lco, rco = nbdime.merge_notebooks(base_nb, local_nb, remote_nb)
        except Exception as e:
            raise web.HTTPError(400, "Error while attempting to merge documents.")

        data = {
            "base": base_nb,
            "local_conflicts": lco,
            "remote_conflicts": rco,
            }
        self.finish(data)
开发者ID:ijstokes,项目名称:nbdime,代码行数:16,代码来源:nbdimeserver.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python nbformat.from_dict函数代码示例发布时间:2022-05-27
下一篇:
Python preprocessors.ExecutePreprocessor类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap