Пример #1
0
    def test_does_not_allow_attribute_to_not_exist(self):
        obj = Namespace()

        with assert_raises(AttributeError) as context:
            utils.verify_attribute(obj, "number", int)

        self.assert_error_message_contains(
            context.exception,
            ["Namespace", "number", "should have"]
        )
Пример #2
0
    def test_does_not_allow_attribute_to_be_of_wrong_type(self):
        obj = Namespace()
        obj.number = "I'm not a number!"

        with assert_raises(TypeError) as context:
            utils.verify_attribute(obj, "number", int)

        self.assert_error_message_contains(
            context.exception,
            ["Namespace", "number", "should be", "instance", "int"]
        )
Пример #3
0
    def __init__(self, *args, **kwargs):
        super(Node, self).__init__()
        verify_attribute(self, "_fields", collections.Iterable)

        self.check_modifiers()

        if len(args) not in [0, len(self._fields)]:
            raise InvalidInitializationError(_invalid_arg_count_err_msg(self))

        # Setup from arguments
        for field, value in zip(self._fields, args):
            setattr(self, field[0], value)
        for key, value in kwargs.items():
            setattr(self, key, value)
Пример #4
0
    def test_verifies_valid_case(self):
        obj = Namespace()
        obj.number = 1

        # If we see an error, it's a failed test.
        utils.verify_attribute(obj, "number", int)
Пример #5
0
 def __init__(self):
     super().__init__()
     verify_attribute(self, "options", dict)