def test_literal(): """ test with Literal """ schema = Schema([Literal({"a": 1}), Literal({"b": 1})]) schema([{"a": 1}]) schema([{"b": 1}]) schema([{"a": 1}, {"b": 1}]) try: schema([{"c": 1}]) except Invalid as e: assert_equal(str(e), "{'c': 1} not match for {'b': 1} @ data[0]") else: assert False, "Did not raise Invalid" schema = Schema(Literal({"a": 1})) try: schema({"b": 1}) except MultipleInvalid as e: assert_equal(str(e), "{'b': 1} not match for {'a': 1}") assert_equal(len(e.errors), 1) assert_equal(type(e.errors[0]), LiteralInvalid) else: assert False, "Did not raise Invalid"
def test_literal(): """ test with Literal """ schema = Schema([Literal({"a": 1}), Literal({"b": 1})]) schema([{"a": 1}]) schema([{"b": 1}]) schema([{"a": 1}, {"b": 1}]) try: schema([{"c": 1}]) except Invalid as e: assert str(e) == "{'c': 1} not match for {'b': 1} @ data[0]" else: assert False, "Did not raise Invalid" schema = Schema(Literal({"a": 1})) try: schema({"b": 1}) except MultipleInvalid as e: assert str(e) == "{'b': 1} not match for {'a': 1}" assert len(e.errors) == 1 assert type(e.errors[0]) == LiteralInvalid else: assert False, "Did not raise Invalid"