#NEWLINE# def assertIteration( self , iterable , expectedResults , orderMatters = True , onlyMembershipMatters = False ) : #NEWLINE# #INDENT# '\n        Asserts that the iterable yields the expectedResults.\n        \n        \'expectedResults\' should be a sequence of items, where each item matches\n        an item returned while iterating \'iterable\'.\n\n        If onlyMembershipMatters is True, then as long as the results of\n        iterable are containined within expectedResults, and every member of\n        expectedResults is returned by iterable at least once, the test will\n        pass. (Ie, onlyMembershipMatters will override orderMatters.)\n        \n        If onlyMembershipMatters is False and orderMatters is True, then the\n        items in expectedResults should match the order of items returned by the\n        iterable.\n\n        If onlyMembershipMatters is False and orderMatters is False, the\n        assertion will pass as long as there is a one-to-one correspondence\n        between the items of expectedResults and the items returned by\n        iterable. Note that in this case, duplicate return values from the\n        iterable will still need duplicate results in the expectedResults.\n\n        Examples:\n\n        # orderMatters=True, onlyMembershipMatters=False by default\n\n        #################################################\n        ## orderMatters=True, onlyMembershipMatters=False\n        #################################################\n\n        # will PASS\n        assertIteration( "foo", [\'f\', \'o\', \'o\'])\n\n        # will FAIL - last \'o\' not present in expectedResults\n        assertIteration( "foo", [\'f\', \'o\'])\n\n        # will FAIL - \'x\' not present in iterable\n        assertIteration( "foo", [\'f\', \'o\', \'o\', \'x\'])\n\n        # will FAIL - order incorrect\n        assertIteration( "foo", [\'o\', \'f\', \'o\'])\n\n        #################################################\n\n        \n        \n        #################################################\n        ## orderMatters=True, onlyMembershipMatters=True\n        #################################################\n\n        # will PASS - if onlyMembershipMatters, duplicate entries are ignored\n        assertIteration( "foo", [\'f\', \'o\', \'o\'], onlyMemberShipMatters=True)        \n\n        #will PASS\n        assertIteration( "foo", [\'f\', \'o\'], onlyMemberShipMatters=True)\n\n        #will FAIL - \'o\' not present in expectedResults\n        assertIteration( "foo", [\'f\'], onlyMemberShipMatters=True)\n\n        # will FAIL - \'x\' not present in iterable\n        assertIteration( "foo", [\'f\', \'o\', \'x\'], onlyMemberShipMatters=True)\n\n        # will PASS - order irrelevant\n        assertIteration( "foo", [\'o\', \'f\', \'o\'], onlyMemberShipMatters=True)        \n        #################################################\n\n\n        \n        #################################################\n        ## orderMatters=False, onlyMembershipMatters=False\n        #################################################\n\n        # will PASS\n        assertIteration( "foo", [\'f\', \'o\', \'o\'], orderMatters=False)        \n\n        #will FAIL - second \'o\' not in expectedResults\n        assertIteration( "foo", [\'f\', \'o\'], orderMatters=False)\n\n        # will FAIL - \'x\' not present in iterable\n        assertIteration( "foo", [\'f\', \'o\', \'o\', \'x\'], orderMatters=False))\n\n        # will PASS - order irrelevant\n        assertIteration( "foo", [\'o\', \'f\', \'o\'], orderMatters=False)\n        #################################################\n        ' #NEWLINE# expectedResults = list ( expectedResults ) #NEWLINE# if onlyMembershipMatters : #NEWLINE# #INDENT# unmatchedResults = set ( expectedResults ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# unmatchedResults = list ( expectedResults ) #NEWLINE# #UNINDENT# for item in iterable : #NEWLINE# #INDENT# notInExpectedResultsFormat = "iterable '%s' contained item '%s', not found in %s '%s'" #NEWLINE# if onlyMembershipMatters : #NEWLINE# #INDENT# self . assertTrue ( ( item in expectedResults ) , ( notInExpectedResultsFormat % ( iterable , item , 'expectedResults' , expectedResults ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . assertTrue ( ( item in unmatchedResults ) , ( notInExpectedResultsFormat % ( iterable , item , 'unmatched expectedResults' , unmatchedResults ) ) ) #NEWLINE# if orderMatters : #NEWLINE# #INDENT# self . assertEqual ( item , unmatchedResults [ 0 ] , ( "iterable returned '%s' when '%s' was expected" % ( item , unmatchedResults [ 0 ] ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( item in unmatchedResults ) : #NEWLINE# #INDENT# unmatchedResults . remove ( item ) #NEWLINE# #UNINDENT# #UNINDENT# message = ( "iterable '%s' did not contain expected item(s): %s" % ( iterable , [ str ( x ) for x in unmatchedResults ] ) ) #NEWLINE# self . assertEqual ( len ( unmatchedResults ) , 0 , message )