def get_tests(): tests = {} tests.update(standard.get_tests()) tests.update(specific.get_tests()) # structures tests.update({ 'brackets': { 'a': { '[': ']', '{': '}', '(': ')', '<': '>' }, 'b': { '[': '[', '{': '{', '(': '(', '<': '<' }, 'diff': { 'D': { '(': { 'N': '(', 'O': ')' }, '<': { 'N': '<', 'O': '>' }, '[': { 'N': '[', 'O': ']' }, '{': { 'N': '{', 'O': '}' }, }, }, }, 'comments': { 'diff': { 'D': { 'k': { 'N': 'V', 'O': 'v', 'C': 'C-NO' } }, 'C': 'C-D' }, }, 'comment_vs_type_hint': { 'diff': { 'D': [ { 'I': [0, 2, 0, 2] }, { 'R': 'two' }, { 'A': '2' }, { 'U': 'lines' }, ], 'E': '', 'H': 'Comment should win', }, 'formatter_opts': { 'type_hints': True }, # type hint should be ignored }, 'comment_is_empty_string': { # empty comments should be preserved 'diff': { 'C': '', 'N': 'new', 'O': 'old' }, }, 'comment_with_HTML_tags': { 'diff': { 'U': 'same', 'C': '<h1>comment</h1>' }, }, 'escaped_symbols': { 'a': { '\n': '\r\n' }, 'b': { '\n': '\n' }, 'diff': { 'D': { '\n': { 'N': '\n', 'O': '\r\n' } } }, }, 'quote_symbols': { 'a': { '`backticks`': '``', '"double"': '""', "'single'": "''" }, 'b': { '`backticks`': '`', '"double"': '"', "'single'": "'" }, 'diff': { 'D': { '"double"': { 'N': '"', 'O': '""' }, '`backticks`': { 'N': '`', 'O': '``' }, "'single'": { 'N': "'", 'O': "''" }, }, }, 'formatter_opts': { 'sort_keys': True }, }, 'type_hints_disabled': { 'a': 'two\nlines', 'b': '2\nlines', 'diff': { 'D': [{ 'I': [0, 2, 0, 2] }, { 'R': 'two' }, { 'A': '2' }, { 'U': 'lines' }], 'E': '' }, 'diff_opts': { 'text_diff_ctx': 2 }, 'formatter_opts': { 'type_hints': False }, }, 'wrapping_text': { 'a': 0, 'b': 1, 'diff': { 'N': 1, 'O': 0 }, 'format_func_opts': { 'header': 'Header\n', 'footer': 'Footer\n', }, }, 'redefined_depth': { 'a': 0, 'b': 1, 'diff': { 'N': 1, 'O': 0 }, 'format_func_opts': { 'depth': 3 }, }, 'absent_yielder': { 'diff': { 'D': [], 'E': None }, 'formatter_raises': NotImplementedError, }, }) for test in tests.values(): test.setdefault('formatter_opts', {}).setdefault('sort_keys', True) return tests
def get_tests(): tests = {} tests.update(standard.get_tests()) tests.update(specific.get_tests()) # structures tests.update({ 'brackets': { 'a': { '[': ']', '{': '}', '(': ')', '<': '>' }, 'b': { '[': '[', '{': '{', '(': '(', '<': '<' }, 'diff': { 'D': { '(': { 'N': '(', 'O': ')' }, '<': { 'N': '<', 'O': '>' }, '[': { 'N': '[', 'O': ']' }, '{': { 'N': '{', 'O': '}' }, }, }, }, 'escaped_symbols': { 'a': { '\n': '\r\n' }, 'b': { '\n': '\n' }, 'diff': { 'D': { '\n': { 'N': '\n', 'O': '\r\n' } } }, }, 'quote_symbols': { 'a': { '`backticks`': '``', '"double"': '""', "'single'": "''" }, 'b': { '`backticks`': '`', '"double"': '"', "'single'": "'" }, 'diff': { 'D': { '"double"': { 'N': '"', 'O': '""' }, '`backticks`': { 'N': '`', 'O': '``' }, "'single'": { 'N': "'", 'O': "''" }, }, }, 'formatter_opts': { 'sort_keys': True }, }, 'wrappings_defined': { 'a': 0, 'b': 1, 'diff': { 'N': 1, 'O': 0 }, 'formatter_opts': { 'header': 'Header\n', 'footer': 'Footer\n', }, }, 'wrappings_undefined': { 'a': 0, 'b': 1, 'diff': { 'N': 1, 'O': 0 }, 'formatter_opts': { 'header': None, 'footer': None, }, }, 'redefined_depth': { 'a': 0, 'b': 1, 'diff': { 'N': 1, 'O': 0 }, 'format_func_opts': { 'depth': 3 }, }, 'absent_emitter': { 'diff': { 'D': [], 'E': None }, 'formatter_raises': NotImplementedError, }, }) for test in tests.values(): test.setdefault('formatter_opts', {}).setdefault('sort_keys', True) return tests
import pytest from nested_diff import diff from tests.data import standard, specific TESTS = {} TESTS.update(standard.get_tests()) TESTS.update(specific.get_tests()) @pytest.mark.parametrize('name', sorted(TESTS.keys())) def test_diff(name): a = TESTS[name]['a'] b = TESTS[name]['b'] expected = TESTS[name]['diff'] opts = TESTS[name].get('diff_opts', {}) got = diff(a, b, **opts) assert expected == got def test_local_objects(): def local_function_cant_be_pickled(): pass a = [local_function_cant_be_pickled] b = [] with pytest.raises(Exception): # Can't pickle local object diff(a, b)