def __getattr__(self, name): method = method_or_none(self.obj, name) if not method: return getattr(self.obj, name) (readonly,unlocked,abort_exception) = action_check(method) #TODO: re-write if not readonly and hasattr(self, 'slave') and self.slave: raise Exception('This is a slave/read-only instance.') def method(*args, **kwargs): exception = None try: if not unlocked: self.lock.acquire(1) #record all calls to clock.now() self.obj._clock = RecordClock() thread_ident = thread.get_ident() action = Action(thread_ident, name, datetime.now(), args, kwargs) system = None if not readonly: self.publisher.publish_before(action) try: system = action.execute_action(self.obj) except Exception as e: logger.debug(CORE_LOG_PREFIX + 'Error: ' + str(e)) if abort_exception: logger.debug(CORE_LOG_PREFIX + 'Aborting action' + str(action)) if not abort_exception: self.publisher.publish_exception(action) exception = e #restore clock action.results = self.obj._clock.results if not readonly and not abort_exception: self.publisher.publish(action) finally: if not unlocked: self.lock.release() if exception: raise exception return system return method
def test_attribute_access(self): class Dummy(object): def __init__(self, some_property): self.some_property = some_property @property def check_property(self): return self.some_property def business_method(self, args): return 1 dummy = Dummy('property') self.assertTrue(not utils.method_or_none(dummy,'some_property')) self.assertTrue(not utils.method_or_none(dummy,'check_property')) self.assertTrue(utils.method_or_none(dummy,'business_method'))