Example #1
0
    def visit_Module(self, node):
        """
        Handler for top-level AST nodes. Sets this visitor's module
        attribute to a newly generated ModuleContext.

        :param node: The current AST node being visited.
        """
        self.module = ModuleContext()
        self.module.indent = self.default_indent
        self.push(self.module)
        self.block(node.body)
Example #2
0
class TestModuleContext:
    def setUp(self):
        self.c = ModuleContext()

    def test_arg_names_attr(self):
        assert self.c.arg_names == ['__module__']

    def test_scope_prefix(self):
        assert self.c.scope.prefix == ['__module__']

    def test_str(self):
        assert str(self.c) == '''(function(__module__) {
})'''

    def test_str_with_vars_and_body(self):
        self.c.scope.declare('a', True)
        self.c.scope.declare('b', True)
        self.c.scope.declare('c', False)
        self.c.add('  foo\n')
        # Note: No 'var a,b;' because prefix is __module__.
        assert str(self.c) == '''(function(__module__) {
Example #3
0
 def setUp(self):
     self.c = ModuleContext()