def Facade(some_instance=None, exclusion_list=[], cls=None, args=tuple(), kwargs={}): """ Top-level interface to the Facade functionality. Determines what to return when passed arbitrary objects. :param mixed some_instance: Anything. :param list exclusion_list: The list of types NOT to wrap :param class cls: The class definition for the object being mocked :param tuple args: The arguments for the class definition to return the desired instance :param dict kwargs: The keywork arguments for the class definition to return the desired instance :rtype instance: Either the instance passed or an instance of the Wrapper wrapping the instance passed. """ if not USE_CALIENDO or should_exclude(some_instance, exclusion_list): if not util.is_primitive(some_instance): # Provide dummy methods to prevent errors in implementations dependent # on the Wrapper interface some_instance.wrapper__unwrap = lambda: None some_instance.wrapper__delete_last_cached = lambda: None return some_instance # Just give it back. else: if util.is_primitive(some_instance) and not cls: return some_instance return Wrapper(o=some_instance, exclusion_list=list(exclusion_list), cls=cls, args=args, kwargs=kwargs)
def Facade( some_instance=None, exclusion_list=[], cls=None, args=tuple(), kwargs={} ): """ Top-level interface to the Facade functionality. Determines what to return when passed arbitrary objects. :param mixed some_instance: Anything. :param list exclusion_list: The list of types NOT to wrap :param class cls: The class definition for the object being mocked :param tuple args: The arguments for the class definition to return the desired instance :param dict kwargs: The keywork arguments for the class definition to return the desired instance :rtype instance: Either the instance passed or an instance of the Wrapper wrapping the instance passed. """ if not USE_CALIENDO or should_exclude( some_instance, exclusion_list ): if not util.is_primitive(some_instance): # Provide dummy methods to prevent errors in implementations dependent # on the Wrapper interface some_instance.wrapper__unwrap = lambda : None some_instance.wrapper__delete_last_cached = lambda : None return some_instance # Just give it back. else: if util.is_primitive(some_instance) and not cls: return some_instance return Wrapper(o=some_instance, exclusion_list=list(exclusion_list), cls=cls, args=args, kwargs=kwargs )
def __store_any(self, o, method_name, member): """ Determines type of member and stores it accordingly :param mixed o: Any parent object :param str method_name: The name of the method or attribuet :param mixed member: Any child object """ if should_exclude( eval( "o." + method_name ), self.__exclusion_list ): self.__store__[ method_name ] = eval( "o." + method_name ) return if hasattr( member, '__call__' ): self.__store_callable( o, method_name, member ) elif inspect.isclass( member ): self.__store_class( o, method_name, member ) # Default ot lazy-loading classes here. elif not util.is_primitive( member ): self.__store_nonprimitive( o, method_name, member ) else: self.__store_other( o, method_name, member )