예제 #1
0
 def test_mixing_binds(self):
     """ Ensure that variables are set correctly when mixing explicit declaration and variables """
     context = Context()
     context.add_generator('gen', count_gen())
     context.bind_variable('foo', '100')
     self.assertEqual(1, context.mod_count)
     context.bind_generator_next('foo', 'gen')
     self.assertEqual(1, context.get_value('foo'))
     self.assertEqual(2, context.mod_count)
예제 #2
0
    def test_generator_bind(self):
        """ Test generator setting to variables """
        context = Context()
        self.assertEqual(0, len(context.get_generators()))
        my_gen = count_gen()
        context.add_generator('gen', my_gen)

        context.bind_generator_next('foo', 'gen')
        self.assertEqual(1, context.mod_count)
        self.assertEqual(1, context.get_value('foo'))
        self.assertTrue(2, next(context.get_generator('gen')))
        self.assertTrue(3, next(my_gen))
예제 #3
0
 def test_update_context_generators(self):
     """ Test updating context variables using generator """
     variable_binds = {'foo': 'initial_value'}
     generator_binds = {'foo': 'gen'}
     context = Context()
     test = TestCase('', None, variable_binds, context=context)
     test.generator_binds = generator_binds
     context.bind_variable('foo', 'broken')
     context.add_generator('gen', generators.generator_basic_ids())
     context.bind_generator_next('foo', 'gen')
     self.assertEqual(1, context.get_value('foo'))
     context.bind_generator_next('foo', 'gen')
     self.assertEqual(2, context.get_value('foo'))
예제 #4
0
    def test_basic_ids(self):
        """ Test starting ids """
        ids1 = generators.generator_basic_ids()
        ids2 = generators.generator_basic_ids()
        self.generator_repeat_test(ids1)
        self.generator_repeat_test(ids2)
        self.assertEqual(next(ids1), next(ids2))

        c = Context()
        c.variables = {'x': '$x'}
        x = generators.factory_generate_ids(1, increment=0)()
        c.add_generator('x', x)

        self.assertEqual(c.bind_generator_next('x', 'x'),
                         c.bind_generator_next('x', 'x'))

        c.bind_variable('x', 1)
        var1 = c.get_value('x')
        c.bind_variable('x', 1)
        var2 = c.get_value('x')
        self.assertEqual(var1, var2)