Ejemplo n.º 1
0
def test_context_depend_variables():
    push_context(Root())
    assert_equals(len(get_context().variables['index']), 0)
    assert_equals(len(get_context().variables['name']), 0)

    get_context().add_var(1, Variable(1, value='one'))
    get_context().add_var('some', Variable('some', value='some'))

    assert_equals(get_context().get_var(1).value, 'one')
    assert_equals(get_context().get_var('some').value, 'some')

    # Checks top context variables are still exists
    push_context(Root())
    assert_equals(get_context().get_var(1).value, 'one')
    assert_equals(get_context().get_var('some').value, 'some')

    # Checks variable overriding
    get_context().add_var('some', Variable('some', value='some_new'))
    get_context().add_var('foo', Variable('foo', value='foo'))
    assert_not_equals(get_context().get_var('some').value, 'some')
    assert_equals(get_context().get_var('some').value, 'some_new')
    assert_equals(get_context().get_var('foo').value, 'foo')
    assert_equals(get_context().get_var(1).value, 'one')

    # Checks variables after restore previous context
    pop_context()
    assert_not_equals(get_context().get_var('some').value, 'some_new')
    assert_equals(get_context().get_var('some').value, 'some')
    assert_equals(get_context().get_var('foo'), None)
    assert_equals(get_context().get_var(1).value, 'one')
Ejemplo n.º 2
0
 def _audit_recursive(self, tree):
     for directive in tree:
         self._update_variables(directive)
         self.auditor.audit(directive)
         if directive.is_block:
             if directive.self_context:
                 push_context(directive)
             self._audit_recursive(directive.children)
             if directive.self_context:
                 pop_context()
Ejemplo n.º 3
0
def test_push_pop_context():
    root_a = Root()
    push_context(root_a)
    assert_equals(len(CONTEXTS), 1)
    root_b = Root()
    push_context(root_b)
    assert_equals(len(CONTEXTS), 2)

    poped = pop_context()
    assert_equals(len(CONTEXTS), 1)
    assert_equals(poped.block, root_b)
    poped = pop_context()
    assert_equals(len(CONTEXTS), 0)
    assert_equals(poped.block, root_a)