def test_text_unsupported_op(): with pytest.raises(ValueError): patch( 'A\nB', { 'D': [{ 'I': [0, 2, 0, 1] }, { 'Z': 'A' }, { 'R': 'B' }], 'E': '' }, )
def test_text_removing_line_mismatsh(): with pytest.raises(ValueError): patch( '\nB', { 'D': [{ 'I': [0, 2, 0, 1] }, { 'U': '' }, { 'R': 'A' }], 'E': '' }, )
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
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)
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)
def test_unsupported_patch_type(): class Foo(object): pass with pytest.raises(NotImplementedError): patch(None, {'D': Foo()})
def test_type_mismatch(): with pytest.raises(AttributeError): patch({}, {'D': [{'A': 1}]})
def test_incorrect_diff_format(): with pytest.raises(ValueError): patch({}, {'garbage': 'passed'})
def test_incorrect_diff_type(): with pytest.raises(TypeError): patch(None, None)