looper Package

looper Package

A test case generation framework

class looper.BaseTestCase(test_cases)[source]

The base test case

check(**kwargs)[source]

Stub check method. Raises an Exception

execute(**kwargs)[source]

Stub execute method. Raises an Exception

run()[source]

Run the execute method on each item in the iterable applying the params as kwargs. Run the check method applying the result from the execute method as kwargs

SimpleHTTP Module

A test case generation framework

class looper.SimpleHTTP.Check[source]

A simple HTTP response check

check(req_url, req_method, req_headers, req_body, resp_code, resp_headers, resp_body)[source]
class looper.SimpleHTTP.Test[source]

A simple HTTP test runner

execute(url, method='GET', headers={}, body=None)[source]
class looper.SimpleHTTP.TestCase(test_cases)[source]

Bases: looper.SimpleHTTP.Test, looper.SimpleHTTP.Check, looper.BaseTestCase

A simple HTTP test case framework

blackmambaHTTP Module

class looper.blackmambaHTTP.Check[source]

Simple BlackMamba HTTP response handler

check(request, response)[source]
class looper.blackmambaHTTP.HTTPRequest(url, method='GET', headers={}, body=None)[source]

Internal convenience class to generate an HTTP Request

headers = {}
request_line = '%s %s HTTP/1.1\r\n'
class looper.blackmambaHTTP.Test[source]

BlackMamba HTTP test runner

execute(url, method='GET', headers={}, body=None)[source]
class looper.blackmambaHTTP.TestCase(test_cases)[source]

Bases: looper.blackmambaHTTP.Test, looper.blackmambaHTTP.Check, looper.BaseTestCase, object

blackmamba HTTP test case wrapper

requestGenerator()[source]
run()[source]

iterutil Module

Itertools extension for generating large and complex datasets using generators.

Infinite iterators:
count([n]) --> n, n+1, n+2, ...
cycle(p) --> p0, p1, ... plast, p0, p1, ...
repeat(elem [,n]) --> elem, elem, elem, ... endlessly or up to n times
repeat_f(f, n=None, args=[], kwargs={}) -> f(*args,**kwargs), f(*args,**kwargs), ... endlessly or up to n times

Iterators terminating on the shortest input sequence:
chain(p, q, ...) --> p0, p1, ... plast, q0, q1, ... 
compress(data, selectors) --> (d[0] if s[0]), (d[1] if s[1]), ...
dropwhile(pred, seq) --> seq[n], seq[n+1], starting when pred fails
groupby(iterable[, keyfunc]) --> sub-iterators grouped by value of keyfunc(v)
ifilter(pred, seq) --> elements of seq where pred(elem) is True
ifilterfalse(pred, seq) --> elements of seq where pred(elem) is False
islice(seq, [start,] stop [, step]) --> elements from
       seq[start:stop:step]
imap(fun, p, q, ...) --> fun(p[0], q[0]), fun(p[1], q[1]), ...
kwimap(fun, p, foo=q) -> fun(p[0], foo=q[0]), fun(p[0], foo=q[0]), ...
starmap(fun, seq) --> fun(*seq[0]), fun(*seq[1]), ...
tee(it, n=2) --> (it1, it2 , ... itn) splits one iterator into n
takewhile(pred, seq) --> seq[0], seq[1], until pred fails
izip(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... 
izip_longest(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... 
concat(p,q,...) --> (p[0]+q[0]), (p[1]+q[1]), ... 
dict_zip(foo=p,bar=q) {"foo": p[0], "bar": q[0]}, {"foo": p[1], "bar": q[1]}, ... 

Combinatoric generators:
product(p, q, ... [repeat=1]) --> cartesian product
dict_product(foo=p,bar=q) --> cartesian product: {"foo": p[x], "bar": q[y]}
permutations(p[, r])
combinations(p, r)
combinations_with_replacement(p, r)

Utility generators:
readfiles(file_a,file_b,...) --> reads file_a line by line, then file_a line by line...
class looper.iterutil.chain

Bases: object

chain(*iterables) –> chain object

Return a chain object whose .next() method returns elements from the first iterable until it is exhausted, then elements from the next iterable, until all of the iterables are exhausted.

static from_iterable()

chain.from_iterable(iterable) –> chain object

Alternate chain() contructor taking a single iterable argument that evaluates lazily.

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.combinations

Bases: object

combinations(iterable, r) –> combinations object

Return successive r-length combinations of elements in the iterable.

combinations(range(4), 3) –> (0,1,2), (0,1,3), (0,2,3), (1,2,3)

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.combinations_with_replacement

Bases: object

combinations_with_replacement(iterable, r) –> combinations_with_replacement object

Return successive r-length combinations of elements in the iterable allowing individual elements to have successive repeats. combinations_with_replacement(‘ABC’, 2) –> AA AB AC BB BC CC

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.compress

Bases: object

compress(data, selectors) –> iterator over selected data

Return data elements corresponding to true selector elements. Forms a shorter iterator from selected data elements using the selectors to choose the data elements.

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.count

Bases: object

count(start=0, step=1) –> count object

Return a count object whose .next() method returns consecutive values. Equivalent to:

def count(firstval=0, step=1): x = firstval while 1:

yield x x += step
next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.cycle

Bases: object

cycle(iterable) –> cycle object

Return elements from the iterable until it is exhausted. Then repeat the sequence indefinitely.

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.dropwhile

Bases: object

dropwhile(predicate, iterable) –> dropwhile object

Drop items from the iterable while predicate(item) is true. Afterwards, return every element until the iterable is exhausted.

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.groupby

Bases: object

groupby(iterable[, keyfunc]) -> create an iterator which returns (key, sub-iterator) grouped by each value of key(value).

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.ifilter

Bases: object

ifilter(function or None, sequence) –> ifilter object

Return those items of sequence for which function(item) is true. If function is None, return the items that are true.

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.ifilterfalse

Bases: object

ifilterfalse(function or None, sequence) –> ifilterfalse object

Return those items of sequence for which function(item) is false. If function is None, return the items that are false.

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.imap

Bases: object

imap(func, *iterables) –> imap object

Make an iterator that computes the function using arguments from each of the iterables. Like map() except that it returns an iterator instead of a list and that it stops when the shortest iterable is exhausted instead of filling in None for shorter iterables.

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.islice

Bases: object

islice(iterable, [start,] stop [, step]) –> islice object

Return an iterator whose next() method returns selected values from an iterable. If start is specified, will skip all preceding elements; otherwise, start defaults to zero. Step defaults to one. If specified as another value, step determines how many values are skipped between successive calls. Works like a slice() on a list but returns an iterator.

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.izip

Bases: object

izip(iter1 [,iter2 [...]]) –> izip object

Return a izip object whose .next() method returns a tuple where the i-th element comes from the i-th iterable argument. The .next() method continues until the shortest iterable in the argument sequence is exhausted and then it raises StopIteration. Works like the zip() function but consumes less memory by returning an iterator instead of a list.

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.izip_longest

Bases: object

izip_longest(iter1 [,iter2 [...]], [fillvalue=None]) –> izip_longest object

Return an izip_longest object whose .next() method returns a tuple where the i-th element comes from the i-th iterable argument. The .next() method continues until the longest iterable in the argument sequence is exhausted and then it raises StopIteration. When the shorter iterables are exhausted, the fillvalue is substituted in their place. The fillvalue defaults to None or can be specified by a keyword argument.

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.permutations

Bases: object

permutations(iterable[, r]) –> permutations object

Return successive r-length permutations of elements in the iterable.

permutations(range(3), 2) –> (0,1), (0,2), (1,0), (1,2), (2,0), (2,1)

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.product

Bases: object

product(*iterables) –> product object

Cartesian product of input iterables. Equivalent to nested for-loops.

For example, product(A, B) returns the same as: ((x,y) for x in A for y in B). The leftmost iterators are in the outermost for-loop, so the output tuples cycle in a manner similar to an odometer (with the rightmost element changing on every iteration).

To compute the product of an iterable with itself, specify the number of repetitions with the optional repeat keyword argument. For example, product(A, repeat=4) means the same as product(A, A, A, A).

product(‘ab’, range(3)) –> (‘a’,0) (‘a’,1) (‘a’,2) (‘b’,0) (‘b’,1) (‘b’,2) product((0,1), (0,1), (0,1)) –> (0,0,0) (0,0,1) (0,1,0) (0,1,1) (1,0,0) ...

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.starmap

Bases: object

starmap(function, sequence) –> starmap object

Return an iterator whose values are returned from the function evaluated with a argument tuple taken from the given sequence.

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.repeat

Bases: object

repeat(object [,times]) -> create an iterator which returns the object for the specified number of times. If not specified, returns the object endlessly.

next

x.next() -> the next value, or raise StopIteration

class looper.iterutil.takewhile

Bases: object

takewhile(predicate, iterable) –> takewhile object

Return successive entries from an iterable as long as the predicate evaluates to true for each entry.

next

x.next() -> the next value, or raise StopIteration

looper.iterutil.concat(*args)[source]
Parameters:*args

lists to be concatinated

Return type:iterable

return a generator which concatinate all of the elements at each ordinal

Example:

A = ['1','2']
B = ['a','b']
r = util.concat(A,B)

print [x for x in r]

#OUTPUT
['1a', '2b']
looper.iterutil.readfiles(*filenames)[source]
Parameters:*args

files to be read.

Return type:iterable

Create a generator to return each line of the specified files in order

Example:

files = readfiles("/path/to/file1","/path/to/file2")
for line in files:
    print line

#prints file1, then file2
looper.iterutil.dict_product(__d=None, **kwargs)[source]
Parameters:
  • Kn – each k is used as the index in the resulting dicts
  • Vn (iterable) – each v is expected to be iterable
Return type:

dict generator

A version of itertools.product for dictionaries

this generates a Cartesian Product of the values supplied as keyword arguments, expecting each value to be in iterable

Example:

A = {"a":[1,2],"b":['x','y']}
r_1 = util.hash_product(A)
r_2 = util.hash_product(a=[1,2], b=['x','y'])
# r_1 == r_2

pprint([x for x in r_1])

#OUTPUT    
[{'a': 1, 'b': 'x'},
 {'a': 1, 'b': 'y'},
 {'a': 2, 'b': 'x'},
 {'a': 2, 'b': 'y'}]
looper.iterutil.dict_zip(**kwargs)[source]
Parameters:
  • Kn – each k is used as the index in the resulting dicts
  • Vn (iterable) – each v is expected to be iterable
Return type:

dict generator

A version of itertools.izip for dictionaries

this generates a new ordinal for each ordinal of the supplied keyword argument

Example:

A = {"a":[1,2],"b":['x','y']}
r = util.hash_product(a=[1,2], b=['x','y'])

pprint([x for x in r])

#OUTPUT    
[{'a': 1, 'b': 'x'},
 {'a': 2, 'b': 'y'}]
looper.iterutil.kwimap(f, *args, **kwargs)[source]

like imap, but pass kwargs as well.

Example:

def test(*args,**kwargs):
    return "args: %s, kwargs: %s" % (repr(args),repr(kwargs))
    
generator = iterutil.kwimap(test,
    [1,2,3],
    [4,5,6],
    foo=['a','b','c'],
    bar=['x','y','z'])

for result in generator:
    print result

#OUTPUT

args: (1, 4), kwargs: {'foo': 'a', 'bar': 'x'}
args: (2, 5), kwargs: {'foo': 'b', 'bar': 'y'}
args: (3, 6), kwargs: {'foo': 'c', 'bar': 'z'}
looper.iterutil.repeat_f(f, n=None, args=[], kwargs={})[source]

repeatedly calls function f, up to n times with arguments *args and **kwargs Like map, but repetitive

Example:

import string,random

rand_string = lambda c,n: ''.join(random.choice(c) for x in range(n))
r = repeat_f(rand_string,args=[string.uppercase,32])
for x in r:
    print x

#OUTPUT    
NUQGMQEGKUMOKELVWUXIEPCPDWXCVOIN
ZLBQPKDLOSGMEVTBWTLYOSIOIVIWONKR
CSQKLSJTWRXNHJVPBQIAJWUYKURVTGWE
ZYEDVFKMTXTRXDOYJUWKOXDZJPLEHUYW
RHNIOVLVNTPTAHSZLXCVQAPJESGNJQTA
UZAXQBXXVZOCOFATSFVUSACLDOXBNTCJ
PDWRURNHFYFQCFDUEDWMYAIQDMRPYQPT
IVFAINVWSOCADGIGGDEOHXWNGKDISYSY
LWUOYSPQHMMLTUQUCSDBGKKUDRQKQFFW
IMPMQNAYSONYKZYIKCIINWHVEOYGRGSG
LTVJTDLYNBCVECPCAYCAKXTWQRSWMNGQ
LBVJCKCAOOUNYNFLGUUAHKFDNEGBSOPS
GNYNJIWLUVESIFARNZCWZWKQUYIRLCFT
OTVNJFKURUPMDXOJRNKWNLKMIPKUSZOC
EUXOURTZYYCJSHSAOCIYKVXXHQKBAKKM
NYCGNDFLKFWPADZYEARDUHPCSHMZJCDB
...

Table Of Contents

Previous topic

Welcome to looper’s documentation!

This Page