示例#1
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
示例#2
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
示例#3
0
def test_nbmerge_app_conflict(tempfiles, capsys):
    bfn = os.path.join(tempfiles, "inline-conflict--1.ipynb")
    lfn = os.path.join(tempfiles, "inline-conflict--2.ipynb")
    rfn = os.path.join(tempfiles, "inline-conflict--3.ipynb")
    ofn = os.path.join(tempfiles, "inline-conflict-out.ipynb")

    assert 1 == nbmergeapp.main([bfn, lfn, rfn])
    nb_stdout, err = capsys.readouterr()

    assert 1 == 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_conflict(tempfiles, capsys, reset_log):
    bfn = os.path.join(tempfiles, "inline-conflict--1.ipynb")
    lfn = os.path.join(tempfiles, "inline-conflict--2.ipynb")
    rfn = os.path.join(tempfiles, "inline-conflict--3.ipynb")
    ofn = os.path.join(tempfiles, "inline-conflict-out.ipynb")

    assert 1 == nbmergeapp.main([bfn, lfn, rfn])
    nb_stdout, err = capsys.readouterr()

    assert 1 == 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
示例#5
0
def test_nbmerge_app_decisions(tempfiles, capsys, reset_log):
    bfn = os.path.join(tempfiles, "inline-conflict--1.ipynb")
    lfn = os.path.join(tempfiles, "inline-conflict--2.ipynb")
    rfn = os.path.join(tempfiles, "inline-conflict--3.ipynb")
    ofn = os.path.join(tempfiles, "inline-conflict-out.ipynb")

    assert 1 == nbmergeapp.main([bfn, lfn, rfn, '--decisions', '--out', ofn])
    out, err = capsys.readouterr()
    # decisions are logged to stderr:
    assert 'conflicted decisions' in err

    # Don't write output if decisions are requested
    assert out == ''
    assert not os.path.exists(ofn)
示例#6
0
def test_nbmerge_app_decisions(tempfiles, capsys, reset_log):
    p = tempfiles
    bfn = os.path.join(p, "inline-conflict--1.ipynb")
    lfn = os.path.join(p, "inline-conflict--2.ipynb")
    rfn = os.path.join(p, "inline-conflict--3.ipynb")
    ofn = os.path.join(p, "inline-conflict-out.ipynb")

    assert 1 == nbmergeapp.main([bfn, lfn, rfn, '--decisions', '-o', ofn])
    out, err = capsys.readouterr()
    # decisions are logged to stderr:
    assert 'conflicted decisions' in err

    # Don't write output if decisions are requested
    assert out == ''
    assert not os.path.exists(ofn)
示例#7
0
def test_nbmerge_app_decisions(tempfiles, capsys, caplog, reset_log):
    bfn = os.path.join(tempfiles, "inline-conflict--1.ipynb")
    lfn = os.path.join(tempfiles, "inline-conflict--2.ipynb")
    rfn = os.path.join(tempfiles, "inline-conflict--3.ipynb")
    ofn = os.path.join(tempfiles, "inline-conflict-out.ipynb")

    assert 1 == nbmergeapp.main([bfn, lfn, rfn, '--decisions', '--out', ofn])

    # ensure decisions are logged with warning:
    assert len(caplog.records) == 2
    assert caplog.records[0].levelno == logging.WARNING
    assert caplog.records[1].levelno == logging.WARNING
    assert 'conflicted decisions' in caplog.text

    # Don't write output if decisions are requested
    out = capsys.readouterr()[0]
    assert out == ''
    assert not os.path.exists(ofn)
示例#8
0
def test_nbmerge_app_decisions(tempfiles, capsys, caplog, reset_log):
    bfn = os.path.join(tempfiles, "inline-conflict--1.ipynb")
    lfn = os.path.join(tempfiles, "inline-conflict--2.ipynb")
    rfn = os.path.join(tempfiles, "inline-conflict--3.ipynb")
    ofn = os.path.join(tempfiles, "inline-conflict-out.ipynb")

    assert 1 == nbmergeapp.main([bfn, lfn, rfn, '--decisions', '--out', ofn])

    # ensure decisions are logged with warning:
    assert len(caplog.records) == 2
    assert caplog.records[0].levelno == logging.WARNING
    assert caplog.records[1].levelno == logging.WARNING
    assert 'conflicted decisions' in caplog.text

    # Don't write output if decisions are requested
    out = capsys.readouterr()[0]
    assert out == ''
    assert not os.path.exists(ofn)