Beispiel #1
0
    def test_variables(self):
        """ Test bind/return of variables """

        context = Context()
        context.variables = {}
        self.assertTrue(context.get_value('foo') is None)
        self.assertEqual(0, context.mod_count)

        context.bind_variable('foo', 'bar')
        self.assertEqual('bar', context.get_value('foo'))
        self.assertEqual('bar', context.get_values()['foo'])
        self.assertEqual(1, context.mod_count)

        context.bind_variable('foo', 'bar2')
        self.assertEqual('bar2', context.get_value('foo'))
        self.assertEqual(2, context.mod_count)
Beispiel #2
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)