def test_mapping_with_mappings(): input_ = { 'foo': { 'bar': 'error-a', 'baz': 'error-b', }, 'bar': { 'baz': 'error-c', 'foo': 'error-d', } } expected = [ "'foo':", " - 'bar': 'error-a'", " - 'baz': 'error-b'", "'bar':", " - 'baz': 'error-c'", " - 'foo': 'error-d'", ] actual = list(map( operator.methodcaller('replace', "u'", "'"), format_errors(input_), )) assert set(actual) == set(expected)
def test_string(): messages = list(map( operator.methodcaller('replace', "u'", "'"), format_errors("error"), )) assert messages == ["'error'"]
def test_mapping_with_mappings(): input_ = { 'foo': { 'bar': 'error-a', 'baz': 'error-b', }, 'bar': { 'baz': 'error-c', 'foo': 'error-d', } } expected = [ "'foo':", " - 'bar': 'error-a'", " - 'baz': 'error-b'", "'bar':", " - 'baz': 'error-c'", " - 'foo': 'error-d'", ] actual = list( map( operator.methodcaller('replace', "u'", "'"), format_errors(input_), )) assert set(actual) == set(expected)
def test_string(): messages = list( map( operator.methodcaller('replace', "u'", "'"), format_errors("error"), )) assert messages == ["'error'"]
def test_short_iterable(): input_ = ["error-a", "error-b"] expected = [ "0. 'error-a'", "1. 'error-b'", ] actual = list(format_errors(input_)) assert set(actual) == set(expected)
def test_short_iterable(): input_ = ["error-a", "error-b"] expected = [ "0. 'error-a'", "1. 'error-b'", ] actual = list(map( operator.methodcaller('replace', "u'", "'"), format_errors(input_), )) assert set(actual) == set(expected)
def test_mapping_with_string_values(): input_ = { 'foo': 'bar', 'bar': 'baz', } expected = [ "'foo': 'bar'", "'bar': 'baz'", ] actual = list(format_errors(input_)) assert set(actual) == set(expected)
def test_short_iterable(): input_ = ["error-a", "error-b"] expected = [ "0. 'error-a'", "1. 'error-b'", ] actual = list( map( operator.methodcaller('replace', "u'", "'"), format_errors(input_), )) assert set(actual) == set(expected)
def test_iterable_of_mappings(): input_ = [ {'foo': 'bar'}, {'bar': ['baz', 'foo']}, ] expected = [ "0. 'foo': 'bar'", "1. 'bar':", " 0. 'baz'", " 1. 'foo'", ] actual = list(format_errors(input_)) assert set(actual) == set(expected)
def test_mapping_with_string_values(): input_ = { 'foo': 'bar', 'bar': 'baz', } expected = [ "'foo': 'bar'", "'bar': 'baz'", ] actual = list(map( operator.methodcaller('replace', "u'", "'"), format_errors(input_), )) assert set(actual) == set(expected)
def test_mapping_with_string_values(): input_ = { 'foo': 'bar', 'bar': 'baz', } expected = [ "'foo': 'bar'", "'bar': 'baz'", ] actual = list( map( operator.methodcaller('replace', "u'", "'"), format_errors(input_), )) assert set(actual) == set(expected)
def test_mapping_with_iterables(): input_ = { 'foo': ['bar', 'baz'], 'bar': ['baz', 'foo'], } expected = [ "'foo':", " 0. 'bar'", " 1. 'baz'", "'bar':", " 0. 'baz'", " 1. 'foo'", ] actual = list(format_errors(input_)) assert set(actual) == set(expected)
def test_iterable_of_mappings(): input_ = [ {'foo': 'bar'}, {'bar': ['baz', 'foo']}, ] expected = [ "0. 'foo': 'bar'", "1. 'bar':", " 0. 'baz'", " 1. 'foo'", ] actual = list(map( operator.methodcaller('replace', "u'", "'"), format_errors(input_), )) assert set(actual) == set(expected)
def test_mapping_with_iterables(): input_ = { 'foo': ['bar', 'baz'], 'bar': ['baz', 'foo'], } expected = [ "'foo':", " 0. 'bar'", " 1. 'baz'", "'bar':", " 0. 'baz'", " 1. 'foo'", ] actual = list(map( operator.methodcaller('replace', "u'", "'"), format_errors(input_), )) assert set(actual) == set(expected)
def test_mapping_with_iterables(): input_ = { 'foo': ['bar', 'baz'], 'bar': ['baz', 'foo'], } expected = [ "'foo':", " 0. 'bar'", " 1. 'baz'", "'bar':", " 0. 'baz'", " 1. 'foo'", ] actual = list( map( operator.methodcaller('replace', "u'", "'"), format_errors(input_), )) assert set(actual) == set(expected)
def test_mapping_with_mappings(): input_ = { 'foo': { 'bar': 'error-a', 'baz': 'error-b', }, 'bar': { 'baz': 'error-c', 'foo': 'error-d', } } expected = [ "'foo':", " - 'bar': 'error-a'", " - 'baz': 'error-b'", "'bar':", " - 'baz': 'error-c'", " - 'foo': 'error-d'", ] actual = list(format_errors(input_)) assert set(actual) == set(expected)
def test_iterable_of_mappings(): input_ = [ { 'foo': 'bar' }, { 'bar': ['baz', 'foo'] }, ] expected = [ "0. 'foo': 'bar'", "1. 'bar':", " 0. 'baz'", " 1. 'foo'", ] actual = list( map( operator.methodcaller('replace', "u'", "'"), format_errors(input_), )) assert set(actual) == set(expected)
def test_string(): messages = list(format_errors("error")) assert messages == ["'error'"]