<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import sys <EOL> from gslib . plurality_checkable_iterator import PluralityCheckableIterator <EOL> import gslib . tests . testcase as testcase <EOL> class CustomTestException ( Exception ) : <EOL> pass <EOL> class PluralityCheckableIteratorTests ( testcase . GsUtilUnitTestCase ) : <EOL> """<STR_LIT>""" <EOL> def testPluralityCheckableIteratorWith0Elems ( self ) : <EOL> """<STR_LIT>""" <EOL> input_list = range ( <NUM_LIT:0> ) <EOL> it = iter ( input_list ) <EOL> pcit = PluralityCheckableIterator ( it ) <EOL> self . assertTrue ( pcit . IsEmpty ( ) ) <EOL> self . assertFalse ( pcit . HasPlurality ( ) ) <EOL> output_list = list ( pcit ) <EOL> self . assertEqual ( input_list , output_list ) <EOL> def testPluralityCheckableIteratorWith1Elem ( self ) : <EOL> """<STR_LIT>""" <EOL> input_list = range ( <NUM_LIT:1> ) <EOL> it = iter ( input_list ) <EOL> pcit = PluralityCheckableIterator ( it ) <EOL> self . assertFalse ( pcit . IsEmpty ( ) ) <EOL> self . assertFalse ( pcit . HasPlurality ( ) ) <EOL> output_list = list ( pcit ) <EOL> self . assertEqual ( input_list , output_list ) <EOL> def testPluralityCheckableIteratorWith2Elems ( self ) : <EOL> """<STR_LIT>""" <EOL> input_list = range ( <NUM_LIT:2> ) <EOL> it = iter ( input_list ) <EOL> pcit = PluralityCheckableIterator ( it ) <EOL> self . assertFalse ( pcit . IsEmpty ( ) ) <EOL> self . assertTrue ( pcit . HasPlurality ( ) ) <EOL> output_list = list ( pcit ) <EOL> self . assertEqual ( input_list , output_list ) <EOL> def testPluralityCheckableIteratorWith3Elems ( self ) : <EOL> """<STR_LIT>""" <EOL> input_list = range ( <NUM_LIT:3> ) <EOL> it = iter ( input_list ) <EOL> pcit = PluralityCheckableIterator ( it ) <EOL> self . assertFalse ( pcit . IsEmpty ( ) ) <EOL> self . assertTrue ( pcit . HasPlurality ( ) ) <EOL> output_list = list ( pcit ) <EOL> self . assertEqual ( input_list , output_list ) <EOL> def testPluralityCheckableIteratorWith1Elem1Exception ( self ) : <EOL> """<STR_LIT>""" <EOL> class IterTest ( object ) : <EOL> def __init__ ( self ) : <EOL> self . position = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> if self . position == <NUM_LIT:0> : <EOL> self . position += <NUM_LIT:1> <EOL> return <NUM_LIT:1> <EOL> elif self . position == <NUM_LIT:1> : <EOL> self . position += <NUM_LIT:1> <EOL> raise CustomTestException ( '<STR_LIT>' ) <EOL> else : <EOL> raise StopIteration ( ) <EOL> pcit = PluralityCheckableIterator ( IterTest ( ) ) <EOL> self . assertFalse ( pcit . IsEmpty ( ) ) <EOL> self . assertTrue ( pcit . HasPlurality ( ) ) <EOL> iterated_value = None <EOL> try : <EOL> for value in pcit : <EOL> iterated_value = value <EOL> self . fail ( '<STR_LIT>' ) <EOL> except CustomTestException : <EOL> pass <EOL> self . assertEqual ( iterated_value , <NUM_LIT:1> ) <EOL> def testPluralityCheckableIteratorWith2Exceptions ( self ) : <EOL> """<STR_LIT>""" <EOL> class IterTest ( object ) : <EOL> def __init__ ( self ) : <EOL> self . position = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> if self . position < <NUM_LIT:2> : <EOL> self . position += <NUM_LIT:1> <EOL> raise CustomTestException ( '<STR_LIT>' % self . position ) <EOL> else : <EOL> raise StopIteration ( ) <EOL> pcit = PluralityCheckableIterator ( IterTest ( ) ) <EOL> try : <EOL> pcit . PeekException ( ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except CustomTestException , e : <EOL> self . assertIn ( e . message , '<STR_LIT>' ) <EOL> try : <EOL> for _ in pcit : <EOL> pass <EOL> self . fail ( '<STR_LIT>' ) <EOL> except CustomTestException , e : <EOL> self . assertIn ( e . message , '<STR_LIT>' ) <EOL> try : <EOL> pcit . PeekException ( ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except CustomTestException , e : <EOL> self . assertIn ( e . message , '<STR_LIT>' ) <EOL> try : <EOL> for _ in pcit : <EOL> pass <EOL> self . fail ( '<STR_LIT>' ) <EOL> except CustomTestException , e : <EOL> self . assertIn ( e . message , '<STR_LIT>' ) <EOL> for _ in pcit : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def testPluralityCheckableIteratorWithYieldedException ( self ) : <EOL> """<STR_LIT>""" <EOL> class IterTest ( object ) : <EOL> def __init__ ( self ) : <EOL> self . position = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> if self . position == <NUM_LIT:0> : <EOL> try : <EOL> self . position += <NUM_LIT:1> <EOL> raise CustomTestException ( '<STR_LIT>' ) <EOL> except CustomTestException , e : <EOL> return ( e , sys . exc_info ( ) [ <NUM_LIT:2> ] ) <EOL> elif self . position == <NUM_LIT:1> : <EOL> self . position += <NUM_LIT:1> <EOL> return <NUM_LIT:1> <EOL> else : <EOL> raise StopIteration ( ) <EOL> pcit = PluralityCheckableIterator ( IterTest ( ) ) <EOL> try : <EOL> for _ in pcit : <EOL> pass <EOL> self . fail ( '<STR_LIT>' ) <EOL> except CustomTestException , e : <EOL> self . assertIn ( e . message , '<STR_LIT>' ) <EOL> for value in pcit : <EOL> iterated_value = value <EOL> self . assertEqual ( iterated_value , <NUM_LIT:1> ) </s>
