Example #1
0
 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())))
Example #2
0
 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'))
Example #3
0
    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'))
Example #4
0
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''')
Example #5
0
    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'))
Example #6
0
 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()
     )
Example #7
0
 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'))
Example #8
0
 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"),
     )
Example #9
0
 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())