示例#1
0
def test_nbdiff_app_null_file(filespath):
    fn = os.path.join(filespath, "multilevel-test-base.ipynb")

    args = nbdiffapp._build_arg_parser().parse_args([fn, EXPLICIT_MISSING_FILE])
    assert 0 == main_diff(args)

    args = nbdiffapp._build_arg_parser().parse_args([EXPLICIT_MISSING_FILE, fn])
    assert 0 == main_diff(args)
示例#2
0
def test_nbdiff_app_null_file(filespath):
    fn = os.path.join(filespath, "multilevel-test-base.ipynb")

    args = nbdiffapp._build_arg_parser().parse_args([fn, EXPLICIT_MISSING_FILE])
    assert 0 == main_diff(args)

    args = nbdiffapp._build_arg_parser().parse_args([EXPLICIT_MISSING_FILE, fn])
    assert 0 == main_diff(args)
示例#3
0
def test_nbdiff_app_config_ignores(filespath, tmpdir, reset_notebook_diff):
    tmpdir.join('nbdime_config.json').write_text(text_type(
        json.dumps({
            'Diff': {
                'Ignore': {
                    '/cells/*/metadata': ['nbdime-dummy-field']
                }
            },
        })),
                                                 encoding='utf-8')

    afn = os.path.join(filespath, "single_cell_nb.ipynb")
    bfn = os.path.join(filespath, "single_cell_nb--changed_metadata.ipynb")
    dfn = os.path.join(tmpdir.dirname, "diff_output.json")
    with tmpdir.as_cwd():
        args = nbdiffapp._build_arg_parser('nbdiff').parse_args(
            [afn, bfn, '--out', dfn])
    assert 0 == main_diff(args)

    pprint(notebook_differs)

    with io.open(dfn) as df:
        diff = json.load(df)
    pprint(diff)
    for key in ('metadata', 'language_info'):
        assert len(diff) == 1
        assert diff[0]['key'] == key
        assert diff[0]['op'] == 'patch'
        diff = diff[0]['diff']

    assert len(diff) == 1
    assert diff[0]['key'] == 'version'
    assert diff[0]['op'] == 'patch'
示例#4
0
def test_nbdiff_app_color_words(filespath):
    # Simply check that the --color-words argument is accepted, not behavior
    afn = os.path.join(filespath, "multilevel-test-base.ipynb")
    bfn = os.path.join(filespath, "multilevel-test-local.ipynb")

    args = nbdiffapp._build_arg_parser().parse_args([afn, bfn, '--color-words'])
    assert 0 == main_diff(args)
示例#5
0
def test_nbdiff_app_flags_override_config_ignores(filespath, tmpdir,
                                                  reset_notebook_diff):
    # This excercises current behavior, but should ideally (?) be different

    tmpdir.join('nbdime_config.json').write_text(text_type(
        json.dumps({
            'Diff': {
                'Ignore': {
                    '/cells/*/metadata': ['nbdime-dummy-field']
                }
            },
        })),
                                                 encoding='utf-8')

    afn = os.path.join(filespath, "single_cell_nb.ipynb")
    bfn = os.path.join(filespath, "single_cell_nb--changed_metadata.ipynb")
    dfn = os.path.join(tmpdir.dirname, "diff_output.json")
    with tmpdir.as_cwd():
        args = nbdiffapp._build_arg_parser('nbdiff').parse_args(
            [afn, bfn, '--out', dfn, '-S'])
    assert 0 == main_diff(args)

    pprint(notebook_differs)

    with io.open(dfn) as df:
        diff = json.load(df)
    pprint(diff)

    assert len(diff) == 2
    assert diff[0]['key'] == 'cells'
    assert diff[1]['key'] == 'metadata'
示例#6
0
def test_nbdiff_app_no_colors(filespath, capsys):
    # Simply check that the --color-words argument is accepted, not behavior
    # Behavior is covered elsewhere
    afn = os.path.join(filespath, "multilevel-test-base.ipynb")
    bfn = os.path.join(filespath, "multilevel-test-local.ipynb")

    args = nbdiffapp._build_arg_parser().parse_args([afn, bfn, '--no-color'])
    assert 0 == main_diff(args)
示例#7
0
def test_nbdiff_app_color_words(filespath):
    # Simply check that the --color-words argument is accepted, not behavior
    afn = os.path.join(filespath, "multilevel-test-base.ipynb")
    bfn = os.path.join(filespath, "multilevel-test-local.ipynb")

    args = nbdiffapp._build_arg_parser().parse_args(
        [afn, bfn, '--color-words'])
    assert 0 == main_diff(args)
示例#8
0
def test_nbdiff_app(filespath):
    afn = os.path.join(filespath, "multilevel-test-base.ipynb")
    bfn = os.path.join(filespath, "multilevel-test-local.ipynb")

    # When filename is omitted, will print to console instead
    # dfn = ""  # os.path.join(filespath, "multilevel-test-local-diff.json")

    args = nbdiffapp._build_arg_parser().parse_args([afn, bfn, '--log-level=WARN'])
    assert 0 == main_diff(args)
    assert args.log_level == 'WARN'
    assert nbdime.log.logger.level == logging.WARN
示例#9
0
def test_nbdiff_app(filespath):
    afn = os.path.join(filespath, "multilevel-test-base.ipynb")
    bfn = os.path.join(filespath, "multilevel-test-local.ipynb")

    # When filename is omitted, will print to console instead
    # dfn = ""  # os.path.join(filespath, "multilevel-test-local-diff.json")

    args = nbdiffapp._build_arg_parser().parse_args([afn, bfn, '--log-level=WARN'])
    assert 0 == main_diff(args)
    assert args.log_level == 'WARN'
    assert nbdime.log.logger.level == logging.WARN
示例#10
0
def test_nbdiff_app_ignore_source(filespath, tmpdir, reset_diff_targets):
    afn = os.path.join(filespath, "multilevel-test-base.ipynb")
    bfn = os.path.join(filespath, "multilevel-test-local.ipynb")
    dfn = os.path.join(tmpdir.dirname, "diff_output.json")

    args = nbdiffapp._build_arg_parser().parse_args([afn, bfn, '--out', dfn, '-S'])
    assert 0 == main_diff(args)
    with io.open(dfn) as df:
        diff = json.load(df)
    for key in ('cells', 2, 'outputs'):
        assert len(diff) == 1
        assert diff[0]['key'] == key
        assert diff[0]['op'] == 'patch'
        diff = diff[0]['diff']
示例#11
0
def test_nbdiff_app_ignore_source(filespath, tmpdir, reset_diff_targets):
    afn = os.path.join(filespath, "multilevel-test-base.ipynb")
    bfn = os.path.join(filespath, "multilevel-test-local.ipynb")
    dfn = os.path.join(tmpdir.dirname, "diff_output.json")

    args = nbdiffapp._build_arg_parser().parse_args([afn, bfn, '--out', dfn, '-S'])
    assert 0 == main_diff(args)
    with io.open(dfn) as df:
        diff = json.load(df)
    for key in ('cells', 2, 'outputs'):
        assert len(diff) == 1
        assert diff[0]['key'] == key
        assert diff[0]['op'] == 'patch'
        diff = diff[0]['diff']
示例#12
0
def test_nbdiff_app_only_details(filespath, tmpdir, reset_diff_targets):
    afn = os.path.join(filespath, "single_cell_nb.ipynb")
    bfn = os.path.join(filespath, "single_cell_nb--changed_source_output_ec.ipynb")
    dfn = os.path.join(tmpdir.dirname, "diff_output.json")

    args = nbdiffapp._build_arg_parser().parse_args([afn, bfn, '--out', dfn, '-d'])
    assert 0 == main_diff(args)
    with io.open(dfn) as df:
        diff = json.load(df)
    print(diff)
    for key in ('cells', 0):
        assert len(diff) == 1
        assert diff[0]['key'] == key
        assert diff[0]['op'] == 'patch'
        diff = diff[0]['diff']
    assert len(diff) == 1
    assert diff[0]['key'] == 'execution_count'
    assert diff[0]['op'] == 'replace'
    assert diff[0]['value'] == 2
示例#13
0
def test_nbdiff_app_ignore_details(filespath, tmpdir, reset_diff_targets):
    afn = os.path.join(filespath, "single_cell_nb.ipynb")
    bfn = os.path.join(filespath, "single_cell_nb--changed_source_output_ec.ipynb")
    dfn = os.path.join(tmpdir.dirname, "diff_output.json")

    args = nbdiffapp._build_arg_parser().parse_args([afn, bfn, '--out', dfn, '-D'])
    assert 0 == main_diff(args)
    with io.open(dfn) as df:
        diff = json.load(df)
    print(diff)
    for key in ('cells', 0):
        assert len(diff) == 1
        assert diff[0]['key'] == key
        assert diff[0]['op'] == 'patch'
        diff = diff[0]['diff']
    assert len(diff) == 2
    assert diff[0]['key'] == 'outputs'
    for subdiff in diff[0]['diff']:
        assert subdiff['op'] != 'patch'

    assert diff[1]['key'] == 'source'
示例#14
0
def test_nbdiff_app_only_details(filespath, tmpdir, reset_diff_targets):
    afn = os.path.join(filespath, "single_cell_nb.ipynb")
    bfn = os.path.join(filespath,
                       "single_cell_nb--changed_source_output_ec.ipynb")
    dfn = os.path.join(tmpdir.dirname, "diff_output.json")

    args = nbdiffapp._build_arg_parser().parse_args(
        [afn, bfn, '--out', dfn, '-d'])
    assert 0 == main_diff(args)
    with io.open(dfn) as df:
        diff = json.load(df)
    print(diff)
    for key in ('cells', 0):
        assert len(diff) == 1
        assert diff[0]['key'] == key
        assert diff[0]['op'] == 'patch'
        diff = diff[0]['diff']
    assert len(diff) == 1
    assert diff[0]['key'] == 'execution_count'
    assert diff[0]['op'] == 'replace'
    assert diff[0]['value'] == 2
示例#15
0
def test_nbdiff_app_ignore_details(filespath, tmpdir, reset_diff_targets):
    afn = os.path.join(filespath, "single_cell_nb.ipynb")
    bfn = os.path.join(filespath,
                       "single_cell_nb--changed_source_output_ec.ipynb")
    dfn = os.path.join(tmpdir.dirname, "diff_output.json")

    args = nbdiffapp._build_arg_parser().parse_args(
        [afn, bfn, '--out', dfn, '-D'])
    assert 0 == main_diff(args)
    with io.open(dfn) as df:
        diff = json.load(df)
    print(diff)
    for key in ('cells', 0):
        assert len(diff) == 1
        assert diff[0]['key'] == key
        assert diff[0]['op'] == 'patch'
        diff = diff[0]['diff']
    assert len(diff) == 2
    assert diff[0]['key'] == 'outputs'
    for subdiff in diff[0]['diff']:
        assert subdiff['op'] != 'patch'

    assert diff[1]['key'] == 'source'
示例#16
0
def test_nbdiff_app_gitrefs(git_repo2):
    args = nbdiffapp._build_arg_parser().parse_args(['local', 'remote'])
    assert 0 == main_diff(args)

    args = nbdiffapp._build_arg_parser().parse_args(['local', 'remote', 'sub/subfile.ipynb'])
    assert 0 == main_diff(args)

    args = nbdiffapp._build_arg_parser().parse_args(['local', 'remote', 'sub/subfile.ipynb', 'diff.ipynb'])
    assert 0 == main_diff(args)

    args = nbdiffapp._build_arg_parser().parse_args(['local', 'sub/subfile.ipynb', 'diff.ipynb'])
    assert 0 == main_diff(args)

    args = nbdiffapp._build_arg_parser().parse_args(['sub/subfile.ipynb'])
    assert 0 == main_diff(args)

    args = nbdiffapp._build_arg_parser().parse_args([])
    assert 0 == main_diff(args)
示例#17
0
def test_nbdiff_app_gitrefs(git_repo2):
    args = nbdiffapp._build_arg_parser().parse_args(['local', 'remote'])
    assert 0 == main_diff(args)

    args = nbdiffapp._build_arg_parser().parse_args(['local', 'remote', 'sub/subfile.ipynb'])
    assert 0 == main_diff(args)

    args = nbdiffapp._build_arg_parser().parse_args(['local', 'remote', 'sub/subfile.ipynb', 'diff.ipynb'])
    assert 0 == main_diff(args)

    args = nbdiffapp._build_arg_parser().parse_args(['local', 'sub/subfile.ipynb', 'diff.ipynb'])
    assert 0 == main_diff(args)

    args = nbdiffapp._build_arg_parser().parse_args(['sub/subfile.ipynb'])
    assert 0 == main_diff(args)

    args = nbdiffapp._build_arg_parser().parse_args([])
    assert 0 == main_diff(args)