def test_nested_selection_error(self): with pytest.raises(quiz.SelectionError) as exc: quiz.validate(Dog, _.owner[_.hobbies[_.foo]]) assert exc.value == quiz.SelectionError( Dog, 'owner', quiz.SelectionError( Human, 'hobbies', quiz.SelectionError(Hobby, 'foo', quiz.NoSuchField())))
def test_invalid_argument_type_optional(self): selection_set = _.is_housetrained(at_other_homes='foo') with pytest.raises(quiz.SelectionError) as exc: quiz.validate(Dog, selection_set) assert exc.value == quiz.SelectionError( Dog, 'is_housetrained', quiz.InvalidArgumentType('at_other_homes', 'foo'))
def test_missing_arguments(self): selection_set = _.knows_command with pytest.raises(quiz.SelectionError) as exc: quiz.validate(Dog, selection_set) assert exc.value == quiz.SelectionError( Dog, 'knows_command', quiz.MissingArgument('command'))
def test_selection_error_str(): exc = quiz.SelectionError(Dog, 'best_friend.foo', quiz.NoSuchArgument('bla')) assert str(exc).strip() == dedent('''\ SelectionError on "Dog" at path "best_friend.foo": NoSuchArgument: argument "bla" does not exist''')
def test_invalid_argument_type(self): selection_set = _.knows_command(command='foobar') with pytest.raises(quiz.SelectionError) as exc: quiz.validate(Dog, selection_set) assert exc.value == quiz.SelectionError( Dog, 'knows_command', quiz.InvalidArgumentType('command', 'foobar'))
def test_selection_set_on_non_object(self): with pytest.raises(quiz.SelectionError) as exc: quiz.validate(Dog, _.name[_.foo]) assert exc.value == quiz.SelectionError( Dog, 'name', quiz.SelectionsNotSupported() )
def test_invalid_argument(self): with pytest.raises(quiz.SelectionError) as exc: quiz.validate(Dog, _.knows_command( foo=1, command=Command.SIT)) assert exc.value == quiz.SelectionError( Dog, 'knows_command', quiz.NoSuchArgument('foo'))
def test_invalid_argument_type_optional(self): selection_set = _.is_housetrained(at_other_homes="foo") with pytest.raises(quiz.SelectionError) as exc: quiz.validate(Dog, selection_set) assert exc.value == quiz.SelectionError( Dog, "is_housetrained", quiz.InvalidArgumentType("at_other_homes", "foo"), )
def test_no_such_field(self): with pytest.raises(quiz.SelectionError) as exc: quiz.validate(Dog, _.name.foo.knows_command(command=Command.SIT)) assert exc.value == quiz.SelectionError(Dog, 'foo', quiz.NoSuchField())