def test_extend(self): u1 = UserList((0, )) u2 = UserList((0, 1)) u = u1[:] u.extend(u2) self.assertEqual(u, u1 + u2) u = UserList("spam") u.extend("eggs") self.assertEqual(u, list("spameggs"))
def append(self, *others): for other in others: if not other: continue if isinstance(other, Frag) or \ type(other) == type(()) or \ type(other) == type([]): List.extend(self, other) else: List.append(self, other)
def extend(self, lights): if self.enforce_limit: _constrain_lights(len(self) + len(lights)) lts = [] for i, l in enumerate(lights): if self.enforce_limit: l.light_no = lightno(len(self) + i) else: l.light_no = vlightno(len(self) + i) lts.append(l) UserList.extend(self, lts)
def test_mutation(self): d = UserList(range(n)) it = reversed(d) it.next() it.next() self.assertEqual(len(it), n - 2) d.append(n) self.assertEqual(len(it), n - 2) # ignore append d[1:] = [] self.assertEqual(len(it), 0) self.assertEqual(list(it), []) # confirm invariant d.extend(xrange(20)) self.assertEqual(len(it), 0)
def test_mutation(self): d = UserList(range(n)) it = iter(d) it.next() it.next() self.assertEqual(len(it), n-2) d.append(n) self.assertEqual(len(it), n-1) # grow with append d[1:] = [] self.assertEqual(len(it), 0) self.assertEqual(list(it), []) d.extend(xrange(20)) self.assertEqual(len(it), 0)
def test_mutation(self): d = UserList(range(n)) it = reversed(d) it.next() it.next() self.assertEqual(len(it), n-2) d.append(n) self.assertEqual(len(it), n-2) # ignore append d[1:] = [] self.assertEqual(len(it), 0) self.assertEqual(list(it), []) # confirm invariant d.extend(xrange(20)) self.assertEqual(len(it), 0)
def test_mutation(self): d = UserList(range(n)) it = iter(d) it.next() it.next() self.assertEqual(len(it), n - 2) d.append(n) self.assertEqual(len(it), n - 1) # grow with append d[1:] = [] self.assertEqual(len(it), 0) self.assertEqual(list(it), []) d.extend(xrange(20)) self.assertEqual(len(it), 0)
def test_mutation_seqiter_reversed(self): from UserList import UserList n = 5 d = UserList(range(n)) it = reversed(d) it.next() it.next() assert len(it) == n-2 d.append(n) assert len(it) == n-2 # ignore append d[1:] = [] assert len(it) == 0 assert list(it) == [] d.extend(xrange(20)) assert len(it) == 0
def test_mutation_seqiter(self): from UserList import UserList n = 5 d = UserList(range(n)) it = iter(d) it.next() it.next() assert len(it) == n-2 d.append(n) assert len(it) == n-1 # grow with append d[1:] = [] assert len(it) == 0 assert list(it) == [] d.extend(xrange(20)) assert len(it) == 0
def get_local_parts(ctx, *attr): "Get a list of available/mounted local partitions" parts = UserList() # Get a list of objects depending on host OS if ctx.uname == 'Darwin': parts.extend( readout_attr(*readout_attr_presets['darwin_lib_mounts']) ) elif ctx.uname == 'Linux': parts.extend( [ p for p in readout_attr( *readout_attr_presets['linux_mounts'] ) if os.path.exists(p.device) ] ) else: raise Exception("Unknown OS '{0}'".format(ctx.uname)) # Fill in missing attributes, if requested explicitly return fetch_parts_attr(parts, ctx, *attr)
def simple_search(self, query, max_length=MAX_RESULT_LENGTH, **kwargs): """ Smart searchs query in books (in title and authors). Supports args: query, tag, lang, max_length. """ query_ex = dict(kwargs) query_ex['title'] = query query_ex['author'] = query # search in title and in author books = UserList(self.__book_search(max_length, **query_ex)) if len(books) < max_length: # search only in title del query_ex['author'] books_a = self.__book_search(max_length, **query_ex) books_id_set = set([b.id for b in books]) # merge results added_book_num = len(books) for book in books_a: if not book.id in books_id_set: books.append(book) added_book_num += 1 if added_book_num == max_length: break del query_ex['title'] if len(books) < MIN_LEN_RESULT: query_ex['author'] = query authors = UserList(self.__author_search(1, **query_ex)) if authors: # TODO add filtering by language and tag here authors_books = authors[0].book_set.all() books.extend(authors_books) del query_ex['author'] query_ex['query'] = query books.suggestion = self.__get_suggetions(**query_ex) return books
def extend(self, alist): for x in alist: self.__register_field(x) list.extend(self, alist)
def extend(self, other): for obj in other: validateInformation(obj) UserList.extend(self, other)
def extend(self, other): other2 = self.checkList(other) UserList.extend(self, other2)
def extend(self, other): UserList.extend(self, other) self.notify()
# Test index check(u2.index(0) == 0, "u2.index(0) == 0") check(u2.index(1) == 1, "u2.index(1) == 1") try: u2.index(2) except ValueError: pass else: raise TestFailed("expected ValueError") # Test reverse u = u2[:] u.reverse() check(u == [1, 0], "u == [1, 0]") u.reverse() check(u == u2, "u == u2") # Test sort u = UserList([1, 0]) u.sort() check(u == u2, "u == u2") # Test extend u = u1[:] u.extend(u2) check(u == u1 + u2, "u == u1 + u2")
def extend(self, other): UserList.extend(self, other) self._changed()
assert u2.index(0) == 0 assert u2.index(1) == 1 try: u2.index(2) except ValueError: pass else: assert 0, "expected ValueError" # Test reverse u = u2[:] u.reverse() assert u == [1, 0] u.reverse() assert u == u2 # Test sort u = UserList([1, 0]) u.sort() assert u == u2 # Test extend u = u1[:] u.extend(u2) assert u == u1 + u2
def extend(self, other): UserList.extend(self, other) self.unique = False
def extend(self, item): UserList.extend(self, item) self._up_to_date = False
# Check every path through every method of UserList from UserList import UserList from test_support import TestFailed # Use check instead of assert so -O doesn't render the # test useless. # XXX: could use the verify function in test_support instead def check(predicate, msg): if not predicate: raise TestFailed(msg + " failed") l0 = [] l1 = [0] l2 = [0, 1] # Test constructors u = UserList() u0 = UserList(l0) u1 = UserList(l1) u2 = UserList(l2) uu = UserList(u) uu0 = UserList(u0) uu1 = UserList(u1) uu2 = UserList(u2) v = UserList(tuple(u)) class OtherList: def __init__(self, initlist): self.__data = initlist def __len__(self): return len(self.__data) def __getitem__(self, i): return self.__data[i] v0 = UserList(OtherList(u0))