def setUp(self): self.ganga_list = GangaList() self.plain1 = [self._makeRandomTFile() for _ in range(15)] self.plain2 = [self._makeRandomTFile() for _ in range(10)] self.proxied1 = GangaList() self.proxied1.extend(self.plain1[:]) self.proxied2 = GangaList() self.proxied2.extend(self.plain2[:]) assert len(getProxyAttr(self.proxied1, '_list')) == len(self.plain1), 'Somthings wrong with construction 1' assert len(getProxyAttr(self.proxied2, '_list')) == len(self.plain2), 'Somthings wrong with construction 2'
def setUp(self): self.ganga_list = GangaList() self.plain1 = [self._makeRandomTFile() for _ in range(15)] self.plain2 = [self._makeRandomTFile() for _ in range(10)] self.proxied1 = GangaList() self.proxied1.extend(self.plain1[:]) self.proxied2 = GangaList() self.proxied2.extend(self.plain2[:]) assert len(getProxyAttr(self.proxied1, '_list')) == len( self.plain1), 'Somthings wrong with construction 1' assert len(getProxyAttr(self.proxied2, '_list')) == len( self.plain2), 'Somthings wrong with construction 2'
def makeGangaList(_list, mapfunction=None, parent=None, preparable=False): """Should be used for makeing full gangalists""" # work with a simple list always if isType(_list, list): _list = _list elif isType(_list, GangaList): _list = getProxyAttr(_list, '_list') else: _list = [_list] #logger.debug("_list: %s" % str(_list)) if mapfunction is not None: _list = map(mapfunction, _list) #logger.debug("Making a GangaList of size: %s" % str(len(_list))) result = makeGangaListByRef(_list, preparable) result._is_a_ref = False # set the parent if possible if parent is not None: result._setParent(parent) return result
def makeGangaList(_list, mapfunction = None, parent = None, preparable = False): """Should be used for makeing full gangalists""" #work with a simple list always if isType(_list,list): _list = _list elif isType(_list,GangaList): _list = getProxyAttr(_list,'_list') else: _list = [_list] if mapfunction is not None: _list = map(mapfunction,_list) result = GangaList() result.extend(_list) result._is_preparable = preparable #set the parent if possible if parent is not None: result._setParent(parent) for r in result: if isinstance(r,GangaObject) and r._getParent() is None: r._setParent(parent) return result
def makeGangaList(_list, mapfunction=None, parent=None, preparable=False): """Should be used for makeing full gangalists""" # work with a simple list always if isType(_list, list): _list = _list elif isType(_list, GangaList): _list = getProxyAttr(_list, '_list') else: _list = [_list] #logger.debug("_list: %s" % str(_list)) if mapfunction is not None: _list = map(mapfunction, _list) result = makeGangaListByRef(_list) result._is_preparable = preparable # set the parent if possible if parent is not None: result._setParent(parent) for r in result: bare_r = stripProxy(r) if isType(bare_r, GangaObject) and bare_r._getParent() is None: bare_r._setParent(parent) return result
def strip_proxy_list(self, obj_list, filter=False): if isType(obj_list, GangaList): return getProxyAttr(obj_list, '_list') result = [] for o in obj_list: result.append(self.strip_proxy(o, filter)) return result
def stripGangaList(_list): """Gets the underlying list of non-proxy objects Args: _list (list): This is the iterable list of objects which will have their Ganga proxies (if any) stripped """ result = _list if isType(_list, GangaList): result = getProxyAttr(_list, '_list') return result
def setUp(self): super(TestGangaList, self).setUp() self.plain1 = [self._makeRandomTFile() for _ in range(15)] self.plain2 = [self._makeRandomTFile() for _ in range(10)] self.proxied1 = GangaList() self.proxied1.extend(self.plain1[:]) self.proxied2 = GangaList() self.proxied2.extend(self.plain2[:]) t = TFile() real_t = stripProxy(t) new_proxy_t = addProxy(real_t) #hopefully_t = stripProxy(new_proxy_t) #assert real_t is hopefully_t assert t is new_proxy_t self.assertEqual(len(getProxyAttr(self.proxied1, '_list')), len(self.plain1), "Something's wrong with construction") self.assertEqual(len(getProxyAttr(self.proxied2, '_list')), len(self.plain2), "Something's wrong with construction")
def makeGangaList(_list, mapfunction=None, parent=None, preparable=False, extra_args=None): """Should be used for makeing full gangalists Args: _list (list): This is the iterable list object which mapfunction (function): This is a function used to construct new elements based upon the elements in _list parent (GangaObject): This is the object to assign as the parent of the new GangaList (still needed) preparable (bool): Is the GangaList preparable? extra_args (dict): When defined this contains extra args to pass to mapfunction """ # work with a simple list always if isinstance(_list, list): _list = _list elif isinstance(_list, GangaList): _list = getProxyAttr(_list, '_list') else: _list = [_list] if mapfunction is not None: if extra_args is None: _list = [mapfunction(l) for l in _list] else: new_mapfunction = partial(mapfunction, extra_args=extra_args) _list = [new_mapfunction(l) for l in _list] result = GangaList() # Subvert tests and modify the ._list here ourselves # This is potentially DANGEROUS if proxies aren't correctly stripped result._list.extend([stripProxy(l) for l in _list]) result._is_preparable = preparable result._is_a_ref = False # set the parent if possible if parent is not None: result._setParent(parent) return result
def makeGangaList(_list, mapfunction=None, parent=None, preparable=False): """Should be used for makeing full gangalists""" # work with a simple list always if isType(_list, list): _list = _list elif isType(_list, GangaList): _list = getProxyAttr(_list, '_list') else: _list = [_list] if mapfunction is not None: _list = map(mapfunction, _list) result = GangaList() result._list = [ stripProxy(e) for e in _list ] result._is_preparable = preparable result._is_a_ref = False # set the parent if possible if parent is not None: result._setParent(parent) return result
def stripGangaList(_list): """Gets the underlying list of non-proxy objects""" result = _list if isType(_list, GangaList): result = getProxyAttr(_list, '_list') return result
def strip_proxy_list(self, obj_list, filter=False): if isType(obj_list, GangaList): return getProxyAttr(obj_list, '_list') result = [self.strip_proxy(l, filter=filter) for l in obj_list] return result