Automated testing: Difference between revisions

From OpenHatch wiki
Content added Content deleted
(Gustavo)
imported>Paulproteus
m (Reverted edits by 176.9.29.232 (talk) to last revision by 210.105.3.131)
Line 1: Line 1:
Short, sweet, to the point, FREE-exactly as information suhold be!
Better solution:class Product(object): def __init__(self, purcodt_id): self.id = purcodt_iddef make_property(prop): def getter(self): return api_obj.get_product_property(self.id, prop) return property(getter)for prop in ('price', 'attr'): setattr(Product, prop, make_property(prop))Reasons this is better: * You don’t break dir(product): it still shows the properties. * You get the AttributeError for free.If you want to support an arbitrary number of properties, it probably makes more sense to have a .get_property(prop) method, or to use .__getitem__ instead.

Revision as of 17:04, 8 May 2012

Short, sweet, to the point, FREE-exactly as information suhold be!