<s> import unittest <EOL> from test import test_support <EOL> from itertools import * <EOL> from weakref import proxy <EOL> import sys <EOL> import operator <EOL> import random <EOL> def onearg ( x ) : <EOL> '<STR_LIT>' <EOL> return <NUM_LIT:2> * x <EOL> def errfunc ( * args ) : <EOL> '<STR_LIT>' <EOL> raise ValueError <EOL> def gen3 ( ) : <EOL> '<STR_LIT>' <EOL> for i in ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) : <EOL> yield i <EOL> def isEven ( x ) : <EOL> '<STR_LIT>' <EOL> return x % <NUM_LIT:2> == <NUM_LIT:0> <EOL> def isOdd ( x ) : <EOL> '<STR_LIT>' <EOL> return x % <NUM_LIT:2> == <NUM_LIT:1> <EOL> class StopNow : <EOL> '<STR_LIT>' <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> raise StopIteration <EOL> def take ( n , seq ) : <EOL> '<STR_LIT>' <EOL> return list ( islice ( seq , n ) ) <EOL> class TestBasicOps ( unittest . TestCase ) : <EOL> def test_chain ( self ) : <EOL> self . assertEqual ( list ( chain ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( chain ( '<STR_LIT:abc>' ) ) , list ( '<STR_LIT:abc>' ) ) <EOL> self . assertEqual ( list ( chain ( '<STR_LIT>' ) ) , [ ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:4> , chain ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertRaises ( TypeError , chain , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> def test_count ( self ) : <EOL> self . assertEqual ( zip ( '<STR_LIT:abc>' , count ( ) ) , [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] ) <EOL> self . assertEqual ( zip ( '<STR_LIT:abc>' , count ( <NUM_LIT:3> ) ) , [ ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:b>' , <NUM_LIT:4> ) , ( '<STR_LIT:c>' , <NUM_LIT:5> ) ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:2> , zip ( '<STR_LIT:abc>' , count ( <NUM_LIT:3> ) ) ) , [ ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:b>' , <NUM_LIT:4> ) ] ) <EOL> self . assertRaises ( TypeError , count , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> self . assertRaises ( TypeError , count , '<STR_LIT:a>' ) <EOL> c = count ( sys . maxint - <NUM_LIT:2> ) <EOL> c . next ( ) ; c . next ( ) ; c . next ( ) ; c . next ( ) ; c . next ( ) <EOL> c = count ( <NUM_LIT:3> ) <EOL> self . assertEqual ( repr ( c ) , '<STR_LIT>' ) <EOL> c . next ( ) <EOL> self . assertEqual ( repr ( c ) , '<STR_LIT>' ) <EOL> def test_cycle ( self ) : <EOL> self . assertEqual ( take ( <NUM_LIT:10> , cycle ( '<STR_LIT:abc>' ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( cycle ( '<STR_LIT>' ) ) , [ ] ) <EOL> self . assertRaises ( TypeError , cycle ) <EOL> self . assertRaises ( TypeError , cycle , <NUM_LIT:5> ) <EOL> self . assertEqual ( list ( islice ( cycle ( gen3 ( ) ) , <NUM_LIT:10> ) ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> ] ) <EOL> def test_groupby ( self ) : <EOL> self . assertEqual ( [ ] , list ( groupby ( [ ] ) ) ) <EOL> self . assertEqual ( [ ] , list ( groupby ( [ ] , key = id ) ) ) <EOL> self . assertRaises ( TypeError , list , groupby ( '<STR_LIT:abc>' , [ ] ) ) <EOL> self . assertRaises ( TypeError , groupby , None ) <EOL> self . assertRaises ( TypeError , groupby , '<STR_LIT:abc>' , lambda x : x , <NUM_LIT:10> ) <EOL> s = [ ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:20> ) , ( <NUM_LIT:0> , <NUM_LIT:11> , <NUM_LIT> ) , ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT> ) , ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) , <EOL> ( <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT> ) , ( <NUM_LIT:3> , <NUM_LIT:16> , <NUM_LIT> ) , ( <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT> ) ] <EOL> dup = [ ] <EOL> for k , g in groupby ( s , lambda r : r [ <NUM_LIT:0> ] ) : <EOL> for elem in g : <EOL> self . assertEqual ( k , elem [ <NUM_LIT:0> ] ) <EOL> dup . append ( elem ) <EOL> self . assertEqual ( s , dup ) <EOL> dup = [ ] <EOL> for k , g in groupby ( s , lambda r : r [ <NUM_LIT:0> ] ) : <EOL> for ik , ig in groupby ( g , lambda r : r [ <NUM_LIT:2> ] ) : <EOL> for elem in ig : <EOL> self . assertEqual ( k , elem [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( ik , elem [ <NUM_LIT:2> ] ) <EOL> dup . append ( elem ) <EOL> self . assertEqual ( s , dup ) <EOL> keys = [ k for k , g in groupby ( s , lambda r : r [ <NUM_LIT:0> ] ) ] <EOL> expectedkeys = set ( [ r [ <NUM_LIT:0> ] for r in s ] ) <EOL> self . assertEqual ( set ( keys ) , expectedkeys ) <EOL> self . assertEqual ( len ( keys ) , len ( expectedkeys ) ) <EOL> s = '<STR_LIT>' <EOL> r = [ k for k , g in groupby ( sorted ( s ) ) ] <EOL> self . assertEqual ( r , [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:r>' ] ) <EOL> r = [ k for k , g in groupby ( sorted ( s ) ) if list ( islice ( g , <NUM_LIT:1> , <NUM_LIT:2> ) ) ] <EOL> self . assertEqual ( r , [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:r>' ] ) <EOL> r = [ ( len ( list ( g ) ) , k ) for k , g in groupby ( sorted ( s ) ) ] <EOL> self . assertEqual ( r , [ ( <NUM_LIT:5> , '<STR_LIT:a>' ) , ( <NUM_LIT:2> , '<STR_LIT:b>' ) , ( <NUM_LIT:1> , '<STR_LIT:c>' ) , ( <NUM_LIT:1> , '<STR_LIT:d>' ) , ( <NUM_LIT:2> , '<STR_LIT:r>' ) ] ) <EOL> r = sorted ( [ ( len ( list ( g ) ) , k ) for k , g in groupby ( sorted ( s ) ) ] , reverse = True ) [ : <NUM_LIT:3> ] <EOL> self . assertEqual ( r , [ ( <NUM_LIT:5> , '<STR_LIT:a>' ) , ( <NUM_LIT:2> , '<STR_LIT:r>' ) , ( <NUM_LIT:2> , '<STR_LIT:b>' ) ] ) <EOL> class ExpectedError ( Exception ) : <EOL> pass <EOL> def delayed_raise ( n = <NUM_LIT:0> ) : <EOL> for i in range ( n ) : <EOL> yield '<STR_LIT>' <EOL> raise ExpectedError <EOL> def gulp ( iterable , keyp = None , func = list ) : <EOL> return [ func ( g ) for k , g in groupby ( iterable , keyp ) ] <EOL> self . assertRaises ( ExpectedError , gulp , delayed_raise ( <NUM_LIT:0> ) ) <EOL> class DummyCmp : <EOL> def __cmp__ ( self , dst ) : <EOL> raise ExpectedError <EOL> s = [ DummyCmp ( ) , DummyCmp ( ) , None ] <EOL> def keyfunc ( obj ) : <EOL> if keyfunc . skip > <NUM_LIT:0> : <EOL> keyfunc . skip -= <NUM_LIT:1> <EOL> return obj <EOL> else : <EOL> raise ExpectedError <EOL> keyfunc . skip = <NUM_LIT:0> <EOL> self . assertRaises ( ExpectedError , gulp , [ None ] , keyfunc ) <EOL> keyfunc . skip = <NUM_LIT:1> <EOL> self . assertRaises ( ExpectedError , gulp , [ None , None ] , keyfunc ) <EOL> def test_ifilter ( self ) : <EOL> self . assertEqual ( list ( ifilter ( isEven , range ( <NUM_LIT:6> ) ) ) , [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:4> ] ) <EOL> self . assertEqual ( list ( ifilter ( None , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> ] ) ) , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:4> , ifilter ( isEven , count ( ) ) ) , [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ] ) <EOL> self . assertRaises ( TypeError , ifilter ) <EOL> self . assertRaises ( TypeError , ifilter , lambda x : x ) <EOL> self . assertRaises ( TypeError , ifilter , lambda x : x , range ( <NUM_LIT:6> ) , <NUM_LIT:7> ) <EOL> self . assertRaises ( TypeError , ifilter , isEven , <NUM_LIT:3> ) <EOL> self . assertRaises ( TypeError , ifilter ( range ( <NUM_LIT:6> ) , range ( <NUM_LIT:6> ) ) . next ) <EOL> def test_ifilterfalse ( self ) : <EOL> self . assertEqual ( list ( ifilterfalse ( isEven , range ( <NUM_LIT:6> ) ) ) , [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> ] ) <EOL> self . assertEqual ( list ( ifilterfalse ( None , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> ] ) ) , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:4> , ifilterfalse ( isEven , count ( ) ) ) , [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:7> ] ) <EOL> self . assertRaises ( TypeError , ifilterfalse ) <EOL> self . assertRaises ( TypeError , ifilterfalse , lambda x : x ) <EOL> self . assertRaises ( TypeError , ifilterfalse , lambda x : x , range ( <NUM_LIT:6> ) , <NUM_LIT:7> ) <EOL> self . assertRaises ( TypeError , ifilterfalse , isEven , <NUM_LIT:3> ) <EOL> self . assertRaises ( TypeError , ifilterfalse ( range ( <NUM_LIT:6> ) , range ( <NUM_LIT:6> ) ) . next ) <EOL> def test_izip ( self ) : <EOL> ans = [ ( x , y ) for x , y in izip ( '<STR_LIT:abc>' , count ( ) ) ] <EOL> self . assertEqual ( ans , [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] ) <EOL> self . assertEqual ( list ( izip ( '<STR_LIT:abc>' , range ( <NUM_LIT:6> ) ) ) , zip ( '<STR_LIT:abc>' , range ( <NUM_LIT:6> ) ) ) <EOL> self . assertEqual ( list ( izip ( '<STR_LIT>' , range ( <NUM_LIT:3> ) ) ) , zip ( '<STR_LIT>' , range ( <NUM_LIT:3> ) ) ) <EOL> self . assertEqual ( take ( <NUM_LIT:3> , izip ( '<STR_LIT>' , count ( ) ) ) , zip ( '<STR_LIT>' , range ( <NUM_LIT:3> ) ) ) <EOL> self . assertEqual ( list ( izip ( '<STR_LIT>' ) ) , zip ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( izip ( ) ) , zip ( ) ) <EOL> self . assertRaises ( TypeError , izip , <NUM_LIT:3> ) <EOL> self . assertRaises ( TypeError , izip , range ( <NUM_LIT:3> ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( [ tuple ( list ( pair ) ) for pair in izip ( '<STR_LIT:abc>' , '<STR_LIT>' ) ] , <EOL> zip ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( [ pair for pair in izip ( '<STR_LIT:abc>' , '<STR_LIT>' ) ] , <EOL> zip ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) <EOL> ids = map ( id , list ( izip ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( len ( dict . fromkeys ( ids ) ) , len ( ids ) ) <EOL> def test_repeat ( self ) : <EOL> self . assertEqual ( zip ( xrange ( <NUM_LIT:3> ) , repeat ( '<STR_LIT:a>' ) ) , <EOL> [ ( <NUM_LIT:0> , '<STR_LIT:a>' ) , ( <NUM_LIT:1> , '<STR_LIT:a>' ) , ( <NUM_LIT:2> , '<STR_LIT:a>' ) ] ) <EOL> self . assertEqual ( list ( repeat ( '<STR_LIT:a>' , <NUM_LIT:3> ) ) , [ '<STR_LIT:a>' , '<STR_LIT:a>' , '<STR_LIT:a>' ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:3> , repeat ( '<STR_LIT:a>' ) ) , [ '<STR_LIT:a>' , '<STR_LIT:a>' , '<STR_LIT:a>' ] ) <EOL> self . assertEqual ( list ( repeat ( '<STR_LIT:a>' , <NUM_LIT:0> ) ) , [ ] ) <EOL> self . assertEqual ( list ( repeat ( '<STR_LIT:a>' , - <NUM_LIT:3> ) ) , [ ] ) <EOL> self . assertRaises ( TypeError , repeat ) <EOL> self . assertRaises ( TypeError , repeat , None , <NUM_LIT:3> , <NUM_LIT:4> ) <EOL> self . assertRaises ( TypeError , repeat , None , '<STR_LIT:a>' ) <EOL> r = repeat ( <NUM_LIT:1> + <NUM_LIT> ) <EOL> self . assertEqual ( repr ( r ) , '<STR_LIT>' ) <EOL> r = repeat ( <NUM_LIT:1> + <NUM_LIT> , <NUM_LIT:5> ) <EOL> self . assertEqual ( repr ( r ) , '<STR_LIT>' ) <EOL> list ( r ) <EOL> self . assertEqual ( repr ( r ) , '<STR_LIT>' ) <EOL> def test_imap ( self ) : <EOL> self . assertEqual ( list ( imap ( operator . pow , range ( <NUM_LIT:3> ) , range ( <NUM_LIT:1> , <NUM_LIT:7> ) ) ) , <EOL> [ <NUM_LIT:0> ** <NUM_LIT:1> , <NUM_LIT:1> ** <NUM_LIT:2> , <NUM_LIT:2> ** <NUM_LIT:3> ] ) <EOL> self . assertEqual ( list ( imap ( None , '<STR_LIT:abc>' , range ( <NUM_LIT:5> ) ) ) , <EOL> [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] ) <EOL> self . assertEqual ( list ( imap ( None , '<STR_LIT:abc>' , count ( ) ) ) , <EOL> [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:2> , imap ( None , '<STR_LIT:abc>' , count ( ) ) ) , <EOL> [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) ] ) <EOL> self . assertEqual ( list ( imap ( operator . pow , [ ] ) ) , [ ] ) <EOL> self . assertRaises ( TypeError , imap ) <EOL> self . assertRaises ( TypeError , imap , operator . neg ) <EOL> self . assertRaises ( TypeError , imap ( <NUM_LIT:10> , range ( <NUM_LIT:5> ) ) . next ) <EOL> self . assertRaises ( ValueError , imap ( errfunc , [ <NUM_LIT:4> ] , [ <NUM_LIT:5> ] ) . next ) <EOL> self . assertRaises ( TypeError , imap ( onearg , [ <NUM_LIT:4> ] , [ <NUM_LIT:5> ] ) . next ) <EOL> def test_starmap ( self ) : <EOL> self . assertEqual ( list ( starmap ( operator . pow , zip ( range ( <NUM_LIT:3> ) , range ( <NUM_LIT:1> , <NUM_LIT:7> ) ) ) ) , <EOL> [ <NUM_LIT:0> ** <NUM_LIT:1> , <NUM_LIT:1> ** <NUM_LIT:2> , <NUM_LIT:2> ** <NUM_LIT:3> ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:3> , starmap ( operator . pow , izip ( count ( ) , count ( <NUM_LIT:1> ) ) ) ) , <EOL> [ <NUM_LIT:0> ** <NUM_LIT:1> , <NUM_LIT:1> ** <NUM_LIT:2> , <NUM_LIT:2> ** <NUM_LIT:3> ] ) <EOL> self . assertEqual ( list ( starmap ( operator . pow , [ ] ) ) , [ ] ) <EOL> self . assertRaises ( TypeError , list , starmap ( operator . pow , [ [ <NUM_LIT:4> , <NUM_LIT:5> ] ] ) ) <EOL> self . assertRaises ( TypeError , starmap ) <EOL> self . assertRaises ( TypeError , starmap , operator . pow , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] , '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , starmap ( <NUM_LIT:10> , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] ) . next ) <EOL> self . assertRaises ( ValueError , starmap ( errfunc , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] ) . next ) <EOL> self . assertRaises ( TypeError , starmap ( onearg , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] ) . next ) <EOL> def test_islice ( self ) : <EOL> for args in [ <EOL> ( <NUM_LIT:10> , <NUM_LIT:20> , <NUM_LIT:3> ) , <EOL> ( <NUM_LIT:10> , <NUM_LIT:3> , <NUM_LIT:20> ) , <EOL> ( <NUM_LIT:10> , <NUM_LIT:20> ) , <EOL> ( <NUM_LIT:10> , <NUM_LIT:3> ) , <EOL> ( <NUM_LIT:20> , ) <EOL> ] : <EOL> self . assertEqual ( list ( islice ( xrange ( <NUM_LIT:100> ) , * args ) ) , range ( * args ) ) <EOL> for args , tgtargs in [ <EOL> ( ( <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT:3> ) , ( ( <NUM_LIT:10> , <NUM_LIT:100> , <NUM_LIT:3> ) ) ) , <EOL> ( ( <NUM_LIT:10> , <NUM_LIT> ) , ( ( <NUM_LIT:10> , <NUM_LIT:100> ) ) ) , <EOL> ( ( <NUM_LIT> , ) , ( <NUM_LIT:100> , ) ) <EOL> ] : <EOL> self . assertEqual ( list ( islice ( xrange ( <NUM_LIT:100> ) , * args ) ) , range ( * tgtargs ) ) <EOL> self . assertEqual ( list ( islice ( xrange ( <NUM_LIT:10> ) , None ) ) , range ( <NUM_LIT:10> ) ) <EOL> self . assertEqual ( list ( islice ( xrange ( <NUM_LIT:10> ) , None , None ) ) , range ( <NUM_LIT:10> ) ) <EOL> self . assertEqual ( list ( islice ( xrange ( <NUM_LIT:10> ) , None , None , None ) ) , range ( <NUM_LIT:10> ) ) <EOL> self . assertEqual ( list ( islice ( xrange ( <NUM_LIT:10> ) , <NUM_LIT:2> , None ) ) , range ( <NUM_LIT:2> , <NUM_LIT:10> ) ) <EOL> self . assertEqual ( list ( islice ( xrange ( <NUM_LIT:10> ) , <NUM_LIT:1> , None , <NUM_LIT:2> ) ) , range ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:2> ) ) <EOL> it = iter ( range ( <NUM_LIT:10> ) ) <EOL> self . assertEqual ( list ( islice ( it , <NUM_LIT:3> ) ) , range ( <NUM_LIT:3> ) ) <EOL> self . assertEqual ( list ( it ) , range ( <NUM_LIT:3> , <NUM_LIT:10> ) ) <EOL> self . assertRaises ( TypeError , islice , xrange ( <NUM_LIT:10> ) ) <EOL> self . assertRaises ( TypeError , islice , xrange ( <NUM_LIT:10> ) , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ) <EOL> self . assertRaises ( ValueError , islice , xrange ( <NUM_LIT:10> ) , - <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT:1> ) <EOL> self . assertRaises ( ValueError , islice , xrange ( <NUM_LIT:10> ) , <NUM_LIT:1> , - <NUM_LIT:5> , - <NUM_LIT:1> ) <EOL> self . assertRaises ( ValueError , islice , xrange ( <NUM_LIT:10> ) , <NUM_LIT:1> , <NUM_LIT:10> , - <NUM_LIT:1> ) <EOL> self . assertRaises ( ValueError , islice , xrange ( <NUM_LIT:10> ) , <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:0> ) <EOL> self . assertRaises ( ValueError , islice , xrange ( <NUM_LIT:10> ) , '<STR_LIT:a>' ) <EOL> self . assertRaises ( ValueError , islice , xrange ( <NUM_LIT:10> ) , '<STR_LIT:a>' , <NUM_LIT:1> ) <EOL> self . assertRaises ( ValueError , islice , xrange ( <NUM_LIT:10> ) , <NUM_LIT:1> , '<STR_LIT:a>' ) <EOL> self . assertRaises ( ValueError , islice , xrange ( <NUM_LIT:10> ) , '<STR_LIT:a>' , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . assertRaises ( ValueError , islice , xrange ( <NUM_LIT:10> ) , <NUM_LIT:1> , '<STR_LIT:a>' , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( list ( islice ( count ( ) , <NUM_LIT:1> , <NUM_LIT:10> , sys . maxint ) ) ) , <NUM_LIT:1> ) <EOL> def test_takewhile ( self ) : <EOL> data = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:20> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] <EOL> underten = lambda x : x < <NUM_LIT:10> <EOL> self . assertEqual ( list ( takewhile ( underten , data ) ) , [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> ] ) <EOL> self . assertEqual ( list ( takewhile ( underten , [ ] ) ) , [ ] ) <EOL> self . assertRaises ( TypeError , takewhile ) <EOL> self . assertRaises ( TypeError , takewhile , operator . pow ) <EOL> self . assertRaises ( TypeError , takewhile , operator . pow , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] , '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , takewhile ( <NUM_LIT:10> , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] ) . next ) <EOL> self . assertRaises ( ValueError , takewhile ( errfunc , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] ) . next ) <EOL> t = takewhile ( bool , [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> self . assertEqual ( list ( t ) , [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] ) <EOL> self . assertRaises ( StopIteration , t . next ) <EOL> def test_dropwhile ( self ) : <EOL> data = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:20> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] <EOL> underten = lambda x : x < <NUM_LIT:10> <EOL> self . assertEqual ( list ( dropwhile ( underten , data ) ) , [ <NUM_LIT:20> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) <EOL> self . assertEqual ( list ( dropwhile ( underten , [ ] ) ) , [ ] ) <EOL> self . assertRaises ( TypeError , dropwhile ) <EOL> self . assertRaises ( TypeError , dropwhile , operator . pow ) <EOL> self . assertRaises ( TypeError , dropwhile , operator . pow , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] , '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , dropwhile ( <NUM_LIT:10> , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] ) . next ) <EOL> self . assertRaises ( ValueError , dropwhile ( errfunc , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] ) . next ) <EOL> def test_tee ( self ) : <EOL> n = <NUM_LIT:200> <EOL> def irange ( n ) : <EOL> for i in xrange ( n ) : <EOL> yield i <EOL> a , b = tee ( [ ] ) <EOL> self . assertEqual ( list ( a ) , [ ] ) <EOL> self . assertEqual ( list ( b ) , [ ] ) <EOL> a , b = tee ( irange ( n ) ) <EOL> self . assertEqual ( zip ( a , b ) , zip ( range ( n ) , range ( n ) ) ) <EOL> a , b = tee ( irange ( n ) ) <EOL> self . assertEqual ( list ( a ) , range ( n ) ) <EOL> self . assertEqual ( list ( b ) , range ( n ) ) <EOL> a , b = tee ( irange ( n ) ) <EOL> for i in xrange ( <NUM_LIT:100> ) : <EOL> self . assertEqual ( a . next ( ) , i ) <EOL> del a <EOL> self . assertEqual ( list ( b ) , range ( n ) ) <EOL> a , b = tee ( irange ( n ) ) <EOL> for i in xrange ( <NUM_LIT:100> ) : <EOL> self . assertEqual ( a . next ( ) , i ) <EOL> del b <EOL> self . assertEqual ( list ( a ) , range ( <NUM_LIT:100> , n ) ) <EOL> for j in xrange ( <NUM_LIT:5> ) : <EOL> order = [ <NUM_LIT:0> ] * n + [ <NUM_LIT:1> ] * n <EOL> random . shuffle ( order ) <EOL> lists = ( [ ] , [ ] ) <EOL> its = tee ( irange ( n ) ) <EOL> for i in order : <EOL> value = its [ i ] . next ( ) <EOL> lists [ i ] . append ( value ) <EOL> self . assertEqual ( lists [ <NUM_LIT:0> ] , range ( n ) ) <EOL> self . assertEqual ( lists [ <NUM_LIT:1> ] , range ( n ) ) <EOL> self . assertRaises ( TypeError , tee ) <EOL> self . assertRaises ( TypeError , tee , <NUM_LIT:3> ) <EOL> self . assertRaises ( TypeError , tee , [ <NUM_LIT:1> , <NUM_LIT:2> ] , '<STR_LIT:x>' ) <EOL> self . assertRaises ( TypeError , tee , [ <NUM_LIT:1> , <NUM_LIT:2> ] , <NUM_LIT:3> , '<STR_LIT:x>' ) <EOL> a , b = tee ( '<STR_LIT:abc>' ) <EOL> c = type ( a ) ( '<STR_LIT>' ) <EOL> self . assertEqual ( list ( c ) , list ( '<STR_LIT>' ) ) <EOL> a , b , c = tee ( xrange ( <NUM_LIT> ) , <NUM_LIT:3> ) <EOL> for i in xrange ( <NUM_LIT:100> ) : <EOL> self . assertEqual ( a . next ( ) , i ) <EOL> self . assertEqual ( list ( b ) , range ( <NUM_LIT> ) ) <EOL> self . assertEqual ( [ c . next ( ) , c . next ( ) ] , range ( <NUM_LIT:2> ) ) <EOL> self . assertEqual ( list ( a ) , range ( <NUM_LIT:100> , <NUM_LIT> ) ) <EOL> self . assertEqual ( list ( c ) , range ( <NUM_LIT:2> , <NUM_LIT> ) ) <EOL> self . assertRaises ( TypeError , tee , '<STR_LIT:abc>' , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , tee , [ ] , - <NUM_LIT:1> ) <EOL> for n in xrange ( <NUM_LIT:5> ) : <EOL> result = tee ( '<STR_LIT:abc>' , n ) <EOL> self . assertEqual ( type ( result ) , tuple ) <EOL> self . assertEqual ( len ( result ) , n ) <EOL> self . assertEqual ( map ( list , result ) , [ list ( '<STR_LIT:abc>' ) ] * n ) <EOL> a , b = tee ( '<STR_LIT:abc>' ) <EOL> c , d = tee ( a ) <EOL> t1 , t2 = tee ( '<STR_LIT:abc>' ) <EOL> tnew = type ( t1 ) <EOL> self . assertRaises ( TypeError , tnew ) <EOL> self . assertRaises ( TypeError , tnew , <NUM_LIT:10> ) <EOL> t3 = tnew ( t1 ) <EOL> self . assert_ ( list ( t3 ) == list ( t2 ) == list ( '<STR_LIT:abc>' ) ) <EOL> a , b = tee ( xrange ( <NUM_LIT:10> ) ) <EOL> p = proxy ( a ) <EOL> self . assertEqual ( getattr ( p , '<STR_LIT>' ) , type ( b ) ) <EOL> del a <EOL> def test_StopIteration ( self ) : <EOL> self . assertRaises ( StopIteration , izip ( ) . next ) <EOL> for f in ( chain , cycle , izip , groupby ) : <EOL> self . assertRaises ( StopIteration , f ( [ ] ) . next ) <EOL> self . assertRaises ( StopIteration , f ( StopNow ( ) ) . next ) <EOL> self . assertRaises ( StopIteration , islice ( [ ] , None ) . next ) <EOL> self . assertRaises ( StopIteration , islice ( StopNow ( ) , None ) . next ) <EOL> p , q = tee ( [ ] ) <EOL> self . assertRaises ( StopIteration , p . next ) <EOL> self . assertRaises ( StopIteration , q . next ) <EOL> p , q = tee ( StopNow ( ) ) <EOL> self . assertRaises ( StopIteration , p . next ) <EOL> self . assertRaises ( StopIteration , q . next ) <EOL> self . assertRaises ( StopIteration , repeat ( None , <NUM_LIT:0> ) . next ) <EOL> for f in ( ifilter , ifilterfalse , imap , takewhile , dropwhile , starmap ) : <EOL> self . assertRaises ( StopIteration , f ( lambda x : x , [ ] ) . next ) <EOL> self . assertRaises ( StopIteration , f ( lambda x : x , StopNow ( ) ) . next ) <EOL> class TestGC ( unittest . TestCase ) : <EOL> def makecycle ( self , iterator , container ) : <EOL> container . append ( iterator ) <EOL> iterator . next ( ) <EOL> del container , iterator <EOL> def test_chain ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( chain ( a ) , a ) <EOL> def test_cycle ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( cycle ( [ a ] * <NUM_LIT:2> ) , a ) <EOL> def test_dropwhile ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( dropwhile ( bool , [ <NUM_LIT:0> , a , a ] ) , a ) <EOL> def test_groupby ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( groupby ( [ a ] * <NUM_LIT:2> , lambda x : x ) , a ) <EOL> def test_ifilter ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( ifilter ( lambda x : True , [ a ] * <NUM_LIT:2> ) , a ) <EOL> def test_ifilterfalse ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( ifilterfalse ( lambda x : False , a ) , a ) <EOL> def test_izip ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( izip ( [ a ] * <NUM_LIT:2> , [ a ] * <NUM_LIT:3> ) , a ) <EOL> def test_imap ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( imap ( lambda x : x , [ a ] * <NUM_LIT:2> ) , a ) <EOL> def test_islice ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( islice ( [ a ] * <NUM_LIT:2> , None ) , a ) <EOL> def test_repeat ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( repeat ( a ) , a ) <EOL> def test_starmap ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( starmap ( lambda * t : t , [ ( a , a ) ] * <NUM_LIT:2> ) , a ) <EOL> def test_takewhile ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( takewhile ( bool , [ <NUM_LIT:1> , <NUM_LIT:0> , a , a ] ) , a ) <EOL> def R ( seqn ) : <EOL> '<STR_LIT>' <EOL> for i in seqn : <EOL> yield i <EOL> class G : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> def __getitem__ ( self , i ) : <EOL> return self . seqn [ i ] <EOL> class I : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> if self . i >= len ( self . seqn ) : raise StopIteration <EOL> v = self . seqn [ self . i ] <EOL> self . i += <NUM_LIT:1> <EOL> return v <EOL> class Ig : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> for val in self . seqn : <EOL> yield val <EOL> class X : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def next ( self ) : <EOL> if self . i >= len ( self . seqn ) : raise StopIteration <EOL> v = self . seqn [ self . i ] <EOL> self . i += <NUM_LIT:1> <EOL> return v <EOL> class N : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return self <EOL> class E : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> <NUM_LIT:3> // <NUM_LIT:0> <EOL> class S : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> pass <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> raise StopIteration <EOL> def L ( seqn ) : <EOL> '<STR_LIT>' <EOL> return chain ( imap ( lambda x : x , R ( Ig ( G ( seqn ) ) ) ) ) <EOL> class TestVariousIteratorArgs ( unittest . TestCase ) : <EOL> def test_chain ( self ) : <EOL> for s in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , xrange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( list ( chain ( g ( s ) ) ) , list ( g ( s ) ) ) <EOL> self . assertEqual ( list ( chain ( g ( s ) , g ( s ) ) ) , list ( g ( s ) ) + list ( g ( s ) ) ) <EOL> self . assertRaises ( TypeError , chain , X ( s ) ) <EOL> self . assertRaises ( TypeError , list , chain ( N ( s ) ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , chain ( E ( s ) ) ) <EOL> def test_cycle ( self ) : <EOL> for s in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , xrange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> tgtlen = len ( s ) * <NUM_LIT:3> <EOL> expected = list ( g ( s ) ) * <NUM_LIT:3> <EOL> actual = list ( islice ( cycle ( g ( s ) ) , tgtlen ) ) <EOL> self . assertEqual ( actual , expected ) <EOL> self . assertRaises ( TypeError , cycle , X ( s ) ) <EOL> self . assertRaises ( TypeError , list , cycle ( N ( s ) ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , cycle ( E ( s ) ) ) <EOL> def test_groupby ( self ) : <EOL> for s in ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:1000> ) , ( <NUM_LIT:7> , <NUM_LIT:11> ) , xrange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( [ k for k , sb in groupby ( g ( s ) ) ] , list ( g ( s ) ) ) <EOL> self . assertRaises ( TypeError , groupby , X ( s ) ) <EOL> self . assertRaises ( TypeError , list , groupby ( N ( s ) ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , groupby ( E ( s ) ) ) <EOL> def test_ifilter ( self ) : <EOL> for s in ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:1000> ) , ( <NUM_LIT:7> , <NUM_LIT:11> ) , xrange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( list ( ifilter ( isEven , g ( s ) ) ) , filter ( isEven , g ( s ) ) ) <EOL> self . assertRaises ( TypeError , ifilter , isEven , X ( s ) ) <EOL> self . assertRaises ( TypeError , list , ifilter ( isEven , N ( s ) ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , ifilter ( isEven , E ( s ) ) ) <EOL> def test_ifilterfalse ( self ) : <EOL> for s in ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:1000> ) , ( <NUM_LIT:7> , <NUM_LIT:11> ) , xrange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( list ( ifilterfalse ( isEven , g ( s ) ) ) , filter ( isOdd , g ( s ) ) ) <EOL> self . assertRaises ( TypeError , ifilterfalse , isEven , X ( s ) ) <EOL> self . assertRaises ( TypeError , list , ifilterfalse ( isEven , N ( s ) ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , ifilterfalse ( isEven , E ( s ) ) ) <EOL> def test_izip ( self ) : <EOL> for s in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , xrange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( list ( izip ( g ( s ) ) ) , zip ( g ( s ) ) ) <EOL> self . assertEqual ( list ( izip ( g ( s ) , g ( s ) ) ) , zip ( g ( s ) , g ( s ) ) ) <EOL> self . assertRaises ( TypeError , izip , X ( s ) ) <EOL> self . assertRaises ( TypeError , list , izip ( N ( s ) ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , izip ( E ( s ) ) ) <EOL> def test_imap ( self ) : <EOL> for s in ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:100> ) , ( <NUM_LIT:7> , <NUM_LIT:11> ) , xrange ( <NUM_LIT:20> , <NUM_LIT:50> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( list ( imap ( onearg , g ( s ) ) ) , map ( onearg , g ( s ) ) ) <EOL> self . assertEqual ( list ( imap ( operator . pow , g ( s ) , g ( s ) ) ) , map ( operator . pow , g ( s ) , g ( s ) ) ) <EOL> self . assertRaises ( TypeError , imap , onearg , X ( s ) ) <EOL> self . assertRaises ( TypeError , list , imap ( onearg , N ( s ) ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , imap ( onearg , E ( s ) ) ) <EOL> def test_islice ( self ) : <EOL> for s in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , xrange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( list ( islice ( g ( s ) , <NUM_LIT:1> , None , <NUM_LIT:2> ) ) , list ( g ( s ) ) [ <NUM_LIT:1> : : <NUM_LIT:2> ] ) <EOL> self . assertRaises ( TypeError , islice , X ( s ) , <NUM_LIT:10> ) <EOL> self . assertRaises ( TypeError , list , islice ( N ( s ) , <NUM_LIT:10> ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , islice ( E ( s ) , <NUM_LIT:10> ) ) <EOL> def test_starmap ( self ) : <EOL> for s in ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:100> ) , ( <NUM_LIT:7> , <NUM_LIT:11> ) , xrange ( <NUM_LIT:20> , <NUM_LIT:50> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> ss = zip ( s , s ) <EOL> self . assertEqual ( list ( starmap ( operator . pow , g ( ss ) ) ) , map ( operator . pow , g ( s ) , g ( s ) ) ) <EOL> self . assertRaises ( TypeError , starmap , operator . pow , X ( ss ) ) <EOL> self . assertRaises ( TypeError , list , starmap ( operator . pow , N ( ss ) ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , starmap ( operator . pow , E ( ss ) ) ) <EOL> def test_takewhile ( self ) : <EOL> for s in ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:1000> ) , ( <NUM_LIT:7> , <NUM_LIT:11> ) , xrange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> tgt = [ ] <EOL> for elem in g ( s ) : <EOL> if not isEven ( elem ) : break <EOL> tgt . append ( elem ) <EOL> self . assertEqual ( list ( takewhile ( isEven , g ( s ) ) ) , tgt ) <EOL> self . assertRaises ( TypeError , takewhile , isEven , X ( s ) ) <EOL> self . assertRaises ( TypeError , list , takewhile ( isEven , N ( s ) ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , takewhile ( isEven , E ( s ) ) ) <EOL> def test_dropwhile ( self ) : <EOL> for s in ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:1000> ) , ( <NUM_LIT:7> , <NUM_LIT:11> ) , xrange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> tgt = [ ] <EOL> for elem in g ( s ) : <EOL> if not tgt and isOdd ( elem ) : continue <EOL> tgt . append ( elem ) <EOL> self . assertEqual ( list ( dropwhile ( isOdd , g ( s ) ) ) , tgt ) <EOL> self . assertRaises ( TypeError , dropwhile , isOdd , X ( s ) ) <EOL> self . assertRaises ( TypeError , list , dropwhile ( isOdd , N ( s ) ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , dropwhile ( isOdd , E ( s ) ) ) <EOL> def test_tee ( self ) : <EOL> for s in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , xrange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> it1 , it2 = tee ( g ( s ) ) <EOL> self . assertEqual ( list ( it1 ) , list ( g ( s ) ) ) <EOL> self . assertEqual ( list ( it2 ) , list ( g ( s ) ) ) <EOL> self . assertRaises ( TypeError , tee , X ( s ) ) <EOL> self . assertRaises ( TypeError , list , tee ( N ( s ) ) [ <NUM_LIT:0> ] ) <EOL> self . assertRaises ( ZeroDivisionError , list , tee ( E ( s ) ) [ <NUM_LIT:0> ] ) <EOL> class LengthTransparency ( unittest . TestCase ) : <EOL> def test_repeat ( self ) : <EOL> from test . test_iterlen import len <EOL> self . assertEqual ( len ( repeat ( None , <NUM_LIT:50> ) ) , <NUM_LIT:50> ) <EOL> self . assertRaises ( TypeError , len , repeat ( None ) ) <EOL> class RegressionTests ( unittest . TestCase ) : <EOL> def test_sf_793826 ( self ) : <EOL> def mutatingtuple ( tuple1 , f , tuple2 ) : <EOL> def g ( value , first = [ <NUM_LIT:1> ] ) : <EOL> if first : <EOL> del first [ : ] <EOL> f ( z . next ( ) ) <EOL> return value <EOL> items = list ( tuple2 ) <EOL> items [ <NUM_LIT:1> : <NUM_LIT:1> ] = list ( tuple1 ) <EOL> gen = imap ( g , items ) <EOL> z = izip ( * [ gen ] * len ( tuple1 ) ) <EOL> z . next ( ) <EOL> def f ( t ) : <EOL> global T <EOL> T = t <EOL> first [ : ] = list ( T ) <EOL> first = [ ] <EOL> mutatingtuple ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) , f , ( <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ) ) <EOL> second = list ( T ) <EOL> self . assertEqual ( first , second ) <EOL> def test_sf_950057 ( self ) : <EOL> def gen1 ( ) : <EOL> hist . append ( <NUM_LIT:0> ) <EOL> yield <NUM_LIT:1> <EOL> hist . append ( <NUM_LIT:1> ) <EOL> raise AssertionError <EOL> hist . append ( <NUM_LIT:2> ) <EOL> def gen2 ( x ) : <EOL> hist . append ( <NUM_LIT:3> ) <EOL> yield <NUM_LIT:2> <EOL> hist . append ( <NUM_LIT:4> ) <EOL> if x : <EOL> raise StopIteration <EOL> hist = [ ] <EOL> self . assertRaises ( AssertionError , list , chain ( gen1 ( ) , gen2 ( False ) ) ) <EOL> self . assertEqual ( hist , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> hist = [ ] <EOL> self . assertRaises ( AssertionError , list , chain ( gen1 ( ) , gen2 ( True ) ) ) <EOL> self . assertEqual ( hist , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> hist = [ ] <EOL> self . assertRaises ( AssertionError , list , cycle ( gen1 ( ) ) ) <EOL> self . assertEqual ( hist , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> libreftest = """<STR_LIT>""" <EOL> __test__ = { '<STR_LIT>' : libreftest } <EOL> def test_main ( verbose = None ) : <EOL> test_classes = ( TestBasicOps , TestVariousIteratorArgs , TestGC , <EOL> RegressionTests , LengthTransparency ) <EOL> test_support . run_unittest ( * test_classes ) <EOL> if verbose and hasattr ( sys , "<STR_LIT>" ) : <EOL> import gc <EOL> counts = [ None ] * <NUM_LIT:5> <EOL> for i in xrange ( len ( counts ) ) : <EOL> test_support . run_unittest ( * test_classes ) <EOL> gc . collect ( ) <EOL> counts [ i ] = sys . gettotalrefcount ( ) <EOL> print counts <EOL> test_support . run_doctest ( sys . modules [ __name__ ] , verbose ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( verbose = True ) </s>
