def test_adds_all_by_default(self, method_name): """ If no further arguments are supplied, all add_XXX functions are applied. """ # Set the method name to a sentinel and check whether it has been # overwritten afterwards. sentinel = object() class C1(object): x = attr() setattr(C1, method_name, sentinel) C1 = attributes(C1) class C2(object): x = attr() setattr(C2, method_name, sentinel) C2 = attributes(C2) assert sentinel != getattr(C1, method_name) assert sentinel != getattr(C2, method_name)
def test_respects_add_arguments(self, arg_name, method_name): """ If a certain `add_XXX` is `False`, `__XXX__` is not added to the class. """ # Set the method name to a sentinel and check whether it has been # overwritten afterwards. sentinel = object() am_args = {"repr": True, "cmp": True, "hash": True, "init": True} am_args[arg_name] = False class C(object): x = attr() setattr(C, method_name, sentinel) C = attributes(**am_args)(C) assert sentinel == getattr(C, method_name)
def test_adds_all_by_default(self, method_name): """ If no further arguments are supplied, all add_XXX functions except add_hash are applied. __hash__ is set to None. """ # Set the method name to a sentinel and check whether it has been # overwritten afterwards. sentinel = object() class C(object): x = attr() setattr(C, method_name, sentinel) C = attributes(C) meth = getattr(C, method_name) assert sentinel != meth if method_name == "__hash__": assert meth is None
def test_respects_add_arguments(self, arg_name, method_name): """ If a certain `add_XXX` is `True`, XXX is not added to the class. """ # Set the method name to a sentinel and check whether it has been # overwritten afterwards. sentinel = object() am_args = { "repr": True, "cmp": True, "hash": True, "init": True } am_args[arg_name] = False class C(object): x = attr() setattr(C, method_name, sentinel) C = attributes(**am_args)(C) assert sentinel == getattr(C, method_name)