Пример #1
0
def test_text_unsupported_op():
    with pytest.raises(ValueError):
        patch(
            'A\nB',
            {
                'D': [{
                    'I': [0, 2, 0, 1]
                }, {
                    'Z': 'A'
                }, {
                    'R': 'B'
                }],
                'E': ''
            },
        )
Пример #2
0
def test_text_removing_line_mismatsh():
    with pytest.raises(ValueError):
        patch(
            '\nB',
            {
                'D': [{
                    'I': [0, 2, 0, 1]
                }, {
                    'U': ''
                }, {
                    'R': 'A'
                }],
                'E': ''
            },
        )
Пример #3
0
def test_text_unchanged_line_mismatsh():
    with pytest.raises(ValueError):
        patch(
            'A\nB',
            {
                'D': [{
                    'I': [0, 2, 0, 1]
                }, {
                    'U': 'Z'
                }, {
                    'R': 'B'
                }],
                'E': ''
            },
        )
def test_patch_without_diff_method():
    a = Custom(value={'old': 0})
    b = Custom(value={'new': 1})

    diff_ = diff(a, b)
    a = patch(a, diff_, patch_method='__patch__')

    assert isinstance(a, Custom)
    assert {'new': 1} == a.value
def test_patch_with_diff_method():
    a = Custom(value=0)
    b = Custom(value=1)

    diff_ = diff(a, b, diff_method='__diff__')
    a = patch(a, diff_, patch_method='__patch__')

    assert isinstance(a, Custom)
    assert 1 == a.value
Пример #6
0
def test_patch(name):
    diff = TESTS[name]['diff']
    target = TESTS[name]['a']

    try:
        expected = TESTS[name]['patched']
    except KeyError:
        expected = TESTS[name]['b']

    assert expected == patch(target, diff)
Пример #7
0
def test_patch(name):
    target = TESTS[name]['a']

    try:
        expected = TESTS[name]['patched']
    except KeyError:
        expected = TESTS[name]['b']

    got = patch(target, TESTS[name]['diff'])

    assert not diff(expected, got, U=False)
Пример #8
0
def test_unsupported_patch_type():
    class Foo(object):
        pass

    with pytest.raises(NotImplementedError):
        patch(None, {'D': Foo()})
Пример #9
0
def test_type_mismatch():
    with pytest.raises(AttributeError):
        patch({}, {'D': [{'A': 1}]})
Пример #10
0
def test_incorrect_diff_format():
    with pytest.raises(ValueError):
        patch({}, {'garbage': 'passed'})
Пример #11
0
def test_incorrect_diff_type():
    with pytest.raises(TypeError):
        patch(None, None)