Exemple #1
0
def test_diffs_cells():
    test_cases = json.load(open('test_cases_cells.json'))
    for test_case in test_cases:
        result = diff(test_case['before'], test_case['after'])
        def gentest():
            result = diff(test_case['before'], test_case['after'])
            for (expected, actual) in zip(test_case['diff'], result):
                eq_(expected, actual)
        yield gentest
Exemple #2
0
def test_diffs_cells():
    test_cases = json.load(open('test_cases_cells.json'))
    for test_case in test_cases:
        result = diff(test_case['before'], test_case['after'])

        def gentest():
            result = diff(test_case['before'], test_case['after'])
            for (expected, actual) in zip(test_case['diff'], result):
                eq_(expected, actual)

        yield gentest
Exemple #3
0
def test_diff2():
    A = [
        {},
        ]
    B = [
        {}
        ]
    result = diff(A, B)
    expected = [
        {"state": 'unchanged', 'value':{}}
    ]
    eq_(result, expected)
Exemple #4
0
def test_diff4():
    A = [
        {u'input': [u'x = [0,2,4]\n', u'y = {5, 6, 7} \n', u'm']},
    ]
    B = [
        {u'input': [u'x = [1,3,3]\n', u'z = {1, 2, 3} \n', u'\n', u'z']}
    ]

    result = diff(A, B)
    expected = [
        {"state": 'deleted', 'value': {u'input': [u'x = [0,2,4]\n', u'y = {5, 6, 7} \n', u'm']}},
        {"state": 'added', 'value': {u'input': [u'x = [1,3,3]\n', u'z = {1, 2, 3} \n', u'\n', u'z']}},
    ]
    eq_(result, expected)
Exemple #5
0
def test_diff():
    A = "abcabba"
    B = "cbabac"
    result = diff(A, B)
    expected = [
        {"state": 'deleted', 'value': 'a'},
        {"state": 'added', 'value': 'c'},
        {"state": 'unchanged', 'value': 'b'},
        {"state": 'deleted', 'value': 'c'},
        {"state": 'unchanged', 'value': 'a'},
        {"state": 'unchanged', 'value': 'b'},
        {"state": 'deleted', 'value': 'b'},
        {"state": 'unchanged', 'value': 'a'},
        {"state": 'added', 'value': 'c'},
    ]
    eq_(result, expected)
    diff("aaaaaaaaaaaaaaaaaaaa", "bbbbbbaaaaaaaaaaabbbbbbbbbbb")
    diff("cabcdef", "abdef")
    diff("ca", "abdef")
Exemple #6
0
def test_diff1():
    A = [
        {u'input': [u'x = [1,3,4]\n', u'z = {1, 2, 3} \n', u'\n', u'm']},
        {u'input': [u'x = [1,3,3]\n', u'z = {1, 2, 3} \n', u'\n', u'z']}
    ]
    B = [
        {u'input': [u'x = [1,3,4]\n', u'z = {1, 2, 3} \n', u'\n', u'm']}
    ]
    result = diff(A, B)
    expected = [
        {"state": 'unchanged',
         'value': {u'input': [
             u'x = [1,3,4]\n',
             u'z = {1, 2, 3} \n',
             u'\n',
             u'm']}},
        {"state": 'deleted',
         'value': {u'input': [
             u'x = [1,3,3]\n',
             u'z = {1, 2, 3} \n',
             u'\n',
             u'z']}}
    ]
    eq_(result, expected)
Exemple #7
0
 def gentest():
     result = diff(test_case['before'], test_case['after'])
     for (expected, actual) in zip(test_case['diff'], result):
         eq_(expected, actual)
Exemple #8
0
 def gentest():
     result = diff(test_case['before'], test_case['after'])
     for (expected, actual) in zip(test_case['diff'], result):
         eq_(expected, actual)
Exemple #9
0
def test_empty_diff2():
    result = diff([], ['a'])
    assert len(result) == 1
Exemple #10
0
def test_empty_diff1():
    result = diff(['a'], [])
    assert len(result) == 1
Exemple #11
0
def test_empty_diff():
    result = diff([], [])
    assert len(result) == 0
Exemple #12
0
def test_modified():
    cell1 = {
        "cell_type": "code",
        "collapsed": False,
        "input": [
            "x",
            "x",
            "x",
            "x",
            "x",
            "x",
            "y"
        ],
        "language": "python",
        "metadata": {
            "slideshow": {
                "slide_type": "fragment"
            }
        },
        "outputs": [
            {
                "output_type": "stream",
                "stream": "stdout",
                "text": [
                    "Hello, world!\n",
                    "Hello, world!\n"
                ]
            }
        ],
        "prompt_number": 29
    }

    cell2 = {
        "cell_type": "code",
        "collapsed": False,
        "input": [
            "x",
            "x",
            "x",
            "x",
            "x",
            "x"
        ],
        "language": "python",
        "metadata": {
            "slideshow": {
                "slide_type": "fragment"
            }
        },
        "outputs": [
            {
                "output_type": "stream",
                "stream": "stdout",
                "text": [
                    "Hello, world!\n",
                    "Hello, world!\n"
                ]
            }
        ],
        "prompt_number": 29
    }

    import nbdiff.comparable as c

    class FakeComparator(object):
        '''Test comparator object. Will compare as modified if it is "close to"
        the specified values'''
        def __init__(self, foo, closeto=[]):
            self.foo = foo
            self.closeto = closeto

        def __eq__(self, other):
            if other.foo in self.closeto:
                return c.BooleanPlus(True, True)
            else:
                return self.foo == other.foo

    # ensure this doesn't crash at the least
    result = diff(['a', 'b', 'c'], ['b', 'c'], check_modified=False)
    assert result[0]['state'] == 'deleted'
    assert result[0]['value'] == 'a'

    # it doesn't break strings when check_modified is True
    diff(['a', 'b', 'c'], ['b', 'c'], check_modified=True)

    # ensure CellComparators do actually produce booleanpluses
    # if they are similar enough
    # TODO this should be in its own test in a separate file.
    c1 = c.CellComparator(cell1, check_modified=True)
    c2 = c.CellComparator(cell2, check_modified=True)

    assert type(c1 == c2) == c.BooleanPlus

    result = diff([c1, c2, c2, c2], [c2, c2, c2, c2], check_modified=True)
    assert result[0]['state'] == 'modified'

    c1 = FakeComparator(1, [2, 3])
    c2 = FakeComparator(2, [1, 3])
    c3 = FakeComparator(10, [])

    c4 = FakeComparator(2, [])
    c5 = FakeComparator(3, [])

    # c1 -> c4
    # c2 -> c5
    # c3 -> deleted
    result = diff([c1, c2, c3], [c4, c5], check_modified=True)

    assert result[0]['state'] == 'modified'
    assert result[1]['state'] == 'modified'
    assert result[2]['state'] == 'deleted'