Пример #1
0
def test_pretty_print_list_multilinestrings():
    a = ["ac\ndf", "qe\nry", 2]
    b = [2, "abc\ndef", "qwe\nrty"]
    path = '/a/b'
    di = diff(a, b, path=path)

    config = TestConfig(use_color=False)
    pp.pretty_print_diff(a, di, path, config)
    text = config.out.getvalue()
    lines = text.splitlines()

    assert lines == [
        '## deleted /a/b/0-1:',
        #'-  ["ac\ndf", "qe\nry"]',
        #'-  b[0]:',
        '-  item[0]:',
        '-    ac',
        '-    df',
        #'-  b[1]:',
        '-  item[1]:',
        '-    qe',
        '-    ry',
        '',
        '## inserted before /a/b/3:',
        #'+  ["abc\ndef", "qwe\nrty"]',
        #'+  b[3+0]:',
        '+  item[0]:',
        '+    abc',
        '+    def',
        #'+  b[3+1]:',
        '+  item[1]:',
        '+    qwe',
        '+    rty',
        '',
    ]
Пример #2
0
def test_pretty_print_list_multilinestrings(nocolor):
    a = ["ac\ndf", "qe\nry", 2]
    b = [2, "abc\ndef", "qwe\nrty"]
    path = '/a/b'
    di = diff(a, b, path=path)

    io = StringIO()
    pp.pretty_print_diff(a, di, path, io)
    text = io.getvalue()
    lines = text.splitlines()

    assert lines == [
        '## deleted /a/b/0-1:',
        #'-  ["ac\ndf", "qe\nry"]',
        #'-  b[0]:',
        '-  item[0]:',
        '-    ac',
        '-    df',
        #'-  b[1]:',
        '-  item[1]:',
        '-    qe',
        '-    ry',
        '',
        '## inserted before /a/b/3:',
        #'+  ["abc\ndef", "qwe\nrty"]',
        #'+  b[3+0]:',
        '+  item[0]:',
        '+    abc',
        '+    def',
        #'+  b[3+1]:',
        '+  item[1]:',
        '+    qwe',
        '+    rty',
        '',
    ]
Пример #3
0
def test_present_string_diff_b64():
    a = b64text(1024)
    b =  b64text(800)
    path = 'a/b'
    di = diff(a, b, path=path)
    lines = pp.present_diff(a, di, path=path)
    assert lines[1:] == ['<base64 data changed>']
Пример #4
0
def test_present_string_diff_b64():
    a = b64text(1024)
    b =  b64text(800)
    path = 'a/b'
    di = diff(a, b, path=path)
    lines = pp.present_diff(a, di, path=path)
    trim_header = int(not pp.with_indent)
    indent = '  ' * pp.with_indent
    assert lines[trim_header:] == [indent + '<base64 data changed>']
Пример #5
0
def test_present_string_diff():
    a = '\n'.join(['line 1', 'line 2', 'line 3', ''])
    b = '\n'.join(['line 1', 'line 3', 'line 4', ''])
    path = 'a/b'
    di = diff(a, b, path=path)
    with mock.patch('nbdime.prettyprint.which', lambda cmd: None):
        lines = pp.present_diff(a, di, path=path)
    text = '\n'.join(lines)
    assert ('< line 2' in text) or ('-line 2' in text)
    assert ('> line 4' in text) or ('+line 4' in text)
Пример #6
0
def test_present_dict_diff():
    a = {'a': 1}
    b = {'a': 2}
    di = diff(a, b, path='x/y')
    lines = pp.present_diff(a, di, path='x/y')
    assert lines == [
        'replace at x/y/a:',
        '- 1',
        ' +2',
    ]
Пример #7
0
def test_present_dict_diff():
    a = {'a': 1}
    b = {'a': 2}
    di = diff(a, b, path='x/y')
    lines = pp.present_diff(a, di, path='x/y')
    indent = '  ' if pp.with_indent else ''
    assert lines == [ indent + line for line in [
        'replace at x/y/a:',
        '- 1',
        '+ 2',
    ]]
Пример #8
0
def test_present_list_diff():
    a = [1]
    b = [2]
    path = 'a/b'
    di = diff(a, b, path=path)
    lines = pp.present_diff(a, di, path=path)
    assert lines == [
        'insert before a/b/0:',
        '+ [2]',
        'delete a/b/0:',
        '- [1]',
    ]
Пример #9
0
def test_present_list_diff():
    a = [1]
    b = [2]
    path = 'a/b'
    di = diff(a, b, path=path)
    lines = pp.present_diff(a, di, path=path)
    indent = '  ' if pp.with_indent else ''
    assert lines == [ indent + line for line in [
        'insert before a/b/0:',
        '+ [2]',
        'delete a/b/0:',
        '- [1]',
    ]]
Пример #10
0
def test_pretty_print_string_diff(nocolor):
    a = '\n'.join(['line 1', 'line 2', 'line 3', ''])
    b = '\n'.join(['line 1', 'line 3', 'line 4', ''])
    path = '/a/b'
    di = diff(a, b, path=path)

    with mock.patch('nbdime.prettyprint.which', lambda cmd: None):
        io = StringIO()
        pp.pretty_print_diff(a, di, path, io)
        text = io.getvalue()
        lines = text.splitlines()

    text = '\n'.join(lines)
    assert ('< line 2' in text) or ((pp.REMOVE + 'line 2' + pp.RESET) in text)
    assert ('> line 4' in text) or ((pp.ADD + 'line 4' + pp.RESET) in text)
Пример #11
0
def test_pretty_print_string_diff(nocolor):
    a = '\n'.join(['line 1', 'line 2', 'line 3', ''])
    b = '\n'.join(['line 1', 'line 3', 'line 4', ''])
    path = '/a/b'
    di = diff(a, b, path=path)

    with mock.patch('nbdime.prettyprint.which', lambda cmd: None):
        io = StringIO()
        pp.pretty_print_diff(a, di, path, io)
        text = io.getvalue()
        lines = text.splitlines()

    text = '\n'.join(lines)
    assert ('< line 2' in text) or ((pp.REMOVE + 'line 2' + pp.RESET) in text)
    assert ('> line 4' in text) or ((pp.ADD + 'line 4' + pp.RESET) in text)
def test_pretty_print_string_diff():
    a = '\n'.join(['line 1', 'line 2', 'line 3', ''])
    b = '\n'.join(['line 1', 'line 3', 'line 4', ''])
    path = '/a/b'
    di = diff(a, b, path=path)

    with mock.patch('nbdime.prettyprint.which', lambda cmd: None):
        config = TestConfig(use_color=False)
        pp.pretty_print_diff(a, di, path, config)
        text = config.out.getvalue()
        lines = text.splitlines()

    text = '\n'.join(lines)
    assert ('< line 2' in text) or ((config.REMOVE + 'line 2' + config.RESET) in text)
    assert ('> line 4' in text) or ((config.ADD + 'line 4' + config.RESET) in text)
Пример #13
0
def test_pretty_print_dict_diff():
    a = {'a': 1}
    b = {'a': 2}
    di = diff(a, b, path='x/y')

    config = TestConfig(use_color=False)
    pp.pretty_print_diff(a, di, 'x/y', config)
    text = config.out.getvalue()
    lines = text.splitlines()

    assert lines == [
        '## replaced x/y/a:',
        '-  1',
        '+  2',
        '',
    ]
Пример #14
0
def test_pretty_print_dict_diff(nocolor):
    a = {'a': 1}
    b = {'a': 2}
    di = diff(a, b, path='x/y')

    io = StringIO()
    pp.pretty_print_diff(a, di, 'x/y', io)
    text = io.getvalue()
    lines = text.splitlines()

    assert lines == [
        '## replaced x/y/a:',
        '-  1',
        '+  2',
        '',
    ]
Пример #15
0
def test_pretty_print_dict_diff(nocolor):
    a = {'a': 1}
    b = {'a': 2}
    di = diff(a, b, path='x/y')

    io = StringIO()
    pp.pretty_print_diff(a, di, 'x/y', io)
    text = io.getvalue()
    lines = text.splitlines()

    assert lines == [
        '## replaced x/y/a:',
        '-  1',
        '+  2',
        '',
    ]
Пример #16
0
def test_pretty_print_list_diff(nocolor):
    a = [1]
    b = [2]
    path = '/a/b'
    di = diff(a, b, path=path)

    io = StringIO()
    pp.pretty_print_diff(a, di, path, io)
    text = io.getvalue()
    lines = text.splitlines()

    assert lines == [
        '## inserted before /a/b/0:',
        '+  [2]',
        '',
        '## deleted /a/b/0:',
        '-  [1]',
        '',
    ]
Пример #17
0
def test_pretty_print_list_diff(nocolor):
    a = [1]
    b = [2]
    path = '/a/b'
    di = diff(a, b, path=path)

    io = StringIO()
    pp.pretty_print_diff(a, di, path, io)
    text = io.getvalue()
    lines = text.splitlines()

    assert lines == [
        '## inserted before /a/b/0:',
        '+  [2]',
        '',
        '## deleted /a/b/0:',
        '-  [1]',
        '',
    ]
Пример #18
0
def test_pretty_print_list_diff():
    a = [1]
    b = [2]
    path = '/a/b'
    di = diff(a, b, path=path)

    config = TestConfig(use_color=False)
    pp.pretty_print_diff(a, di, path, config)
    text = config.out.getvalue()
    lines = text.splitlines()

    assert lines == [
        '## inserted before /a/b/0:',
        '+  [2]',
        '',
        '## deleted /a/b/0:',
        '-  [1]',
        '',
    ]
Пример #19
0
def test_pretty_print_string_diff_b64():
    a = b64text(1024)
    b = b64text(800)
    path = '/a/b'
    di = diff(a, b, path=path)

    config = TestConfig(use_color=False)
    pp.pretty_print_diff(a, di, path, config)
    text = config.out.getvalue()
    lines = text.splitlines()

    ha = pp.hash_string(a)
    hb = pp.hash_string(b)

    assert lines == [
        '## modified /a/b:',
        '-  %s...<snip base64, md5=%s...>' % (a[:8], ha[:16]),
        '+  %s...<snip base64, md5=%s...>' % (b[:8], hb[:16]),
        '',
    ]
Пример #20
0
def test_pretty_print_string_diff_b64(nocolor):
    a = b64text(1024)
    b = b64text( 800)
    path = '/a/b'
    di = diff(a, b, path=path)

    io = StringIO()
    pp.pretty_print_diff(a, di, path, io)
    text = io.getvalue()
    lines = text.splitlines()

    ha = pp.hash_string(a)
    hb = pp.hash_string(b)

    assert lines == [
        '## modified /a/b:',
        '-  %s...<snip base64, md5=%s...>' % (a[:8], ha[:16]),
        '+  %s...<snip base64, md5=%s...>' % (b[:8], hb[:16]),
        '',
    ]
Пример #21
0
def test_pretty_print_string_diff_b64(nocolor):
    a = b64text(1024)
    b = b64text(800)
    path = '/a/b'
    di = diff(a, b, path=path)

    io = StringIO()
    pp.pretty_print_diff(a, di, path, io)
    text = io.getvalue()
    lines = text.splitlines()

    ha = pp.hash_string(a)
    hb = pp.hash_string(b)

    assert lines == [
        '## modified /a/b:',
        '-  %s...<snip base64, md5=%s...>' % (a[:8], ha[:16]),
        '+  %s...<snip base64, md5=%s...>' % (b[:8], hb[:16]),
        '',
    ]