def testIter(self):

        class i:
            def __init__(self):
                self.idx = 0

            def __iter__(self):
                return self

            def next(self):
                self.idx += 1
                if self.idx == 5:
                    raise StopIteration
                return self.idx


        res = []
        try:
            for j in i():
                res.append(j)
                if len(res) > 5:
                    self.fail("too many items in user-defined iterator")
                    break
        except:
            self.fail("error in user-defined iterator (caught here so tests can proceed)")
            
        self.assertEqual(res, range(1,5))
dataset/ETHPy150Open anandology/pyjamas/examples/libtest/BuiltinTest.py/BuiltinTest.testIter/original