Пример #1
0
 def __init__(self, *signature, **kwargs):
     short, long, positionals = self._parse_signature(signature)
     if short is None and long is None:
         raise TypeError("A short or a long has to be passed")
     if short is not None and len(short) != 2:
         raise ValueError("A short has to be two characters long")
     self.short = short
     self.long = long
     self.positionals = positionals
     set_attributes_from_kwargs(self, kwargs, {
         "action": store_last,
         "help": None
     })
Пример #2
0
    def test_set_attributes_from_kwargs(self):
        defaults = {"foo": 1, "bar": 2}

        object = TestObject()
        set_attributes_from_kwargs(object, {}, defaults)
        self.assert_equal(object.foo, 1)
        self.assert_equal(object.bar, 2)

        object = TestObject()
        with self.assert_raises(TypeError):
            set_attributes_from_kwargs(object, {"baz": 3}, defaults)

        object = TestObject()
        set_attributes_from_kwargs(object, {"foo": 3, "bar": 4}, defaults)
        self.assert_equal(object.foo, 3)
        self.assert_equal(object.bar, 4)