Example #1
0
 def testGClose_Vanilla(self):
   def vanilla():
     yield 1
   v = vanilla()
   self.assertEqual(pep380.gclose(v), None)
   v = vanilla()
   v.next()
   self.assertEqual(pep380.gclose(v), None)
   v = vanilla()
   v.next()
   self.assertRaises(StopIteration, v.next)
   self.assertEqual(pep380.gclose(v), None)
Example #2
0
    def testGClose_Vanilla(self):
        def vanilla():
            yield 1

        v = vanilla()
        self.assertEqual(pep380.gclose(v), None)
        v = vanilla()
        v.next()
        self.assertEqual(pep380.gclose(v), None)
        v = vanilla()
        v.next()
        self.assertRaises(StopIteration, v.next)
        self.assertEqual(pep380.gclose(v), None)
Example #3
0
 def testGClose(self):
   @pep380.gwrap
   def foo():
     total = 0
     try:
       while True:
         total += (yield)
     except GeneratorExit:
       raise pep380.Return(total)
   gen = foo()
   gen.next()
   gen.send(3)
   gen.send(2)
   val = pep380.gclose(gen)
   self.assertEqual(val, 5)
   gen = foo()
   gen.next()
   gen.send(3)
   val = pep380.gclose(gen)
   self.assertEqual(val, 3)
Example #4
0
    def testGClose(self):
        @pep380.gwrap
        def foo():
            total = 0
            try:
                while True:
                    total += (yield)
            except GeneratorExit:
                raise pep380.Return(total)

        gen = foo()
        gen.next()
        gen.send(3)
        gen.send(2)
        val = pep380.gclose(gen)
        self.assertEqual(val, 5)
        gen = foo()
        gen.next()
        gen.send(3)
        val = pep380.gclose(gen)
        self.assertEqual(val, 3)
Example #5
0
 def testGClose_KeepTrying(self):
   def hard_to_get():
     for i in range(5):
       try:
         yield i
       except GeneratorExit:
         continue
     raise pep380.Return(42)
   gen = hard_to_get()
   self.assertEqual(gen.next(), 0)
   self.assertEqual(gen.next(), 1)
   self.assertEqual(pep380.gclose(gen), 42)
Example #6
0
    def testGClose_KeepTrying(self):
        def hard_to_get():
            for i in range(5):
                try:
                    yield i
                except GeneratorExit:
                    continue
            raise pep380.Return(42)

        gen = hard_to_get()
        self.assertEqual(gen.next(), 0)
        self.assertEqual(gen.next(), 1)
        self.assertEqual(pep380.gclose(gen), 42)