Example #1
0
 def test_generator_with_broken_name_support(self):
     def fn():
         yield 42
     provider = jeni.GeneratorProvider(fn, support_name=True)
     provider.init()
     self.assertEqual(42, provider.get())
     self.assertRaises(RuntimeError, provider.get, name='name')
Example #2
0
 def test_unyielding_generator(self):
     def fn(work=False):
         if work:
             yield 'foo'
     self.assertEqual(['foo'], list(fn(work=True)))
     provider = jeni.GeneratorProvider(fn)
     self.assertRaises(RuntimeError, provider.init)
Example #3
0
 def test_init_no_error(self):
     def fn():
         yield 42
     provider = jeni.GeneratorProvider(fn)
     provider.init()
     provider.get()
     provider.close()
Example #4
0
    def test_init_error(self):
        def fn():
            yield

        provider = jeni.GeneratorProvider(fn)
        self.assertRaises(RuntimeError, provider.get)
        self.assertRaises(RuntimeError, provider.close)
Example #5
0
    def test_generator_which_keeps_yielding(self):
        def fn():
            yield 'one'
            yield 'two'

        provider = jeni.GeneratorProvider(fn)
        self.assertRaises(RuntimeError, provider.close)
Example #6
0
 def test_generator(self):
     def fn():
         yield 42
     provider = jeni.GeneratorProvider(fn)
     provider.init()
     self.assertEqual(42, provider.get())
     self.assertEqual(42, provider.get())
     self.assertRaises(TypeError, provider.get, name='name')