Esempio n. 1
0
 def next(self):
     try:
         sy, systring = self.read()
     except UnrecognizedInput:
         self.error("Unrecognized character")
     if sy == IDENT:
         if systring in self.keywords:
             if systring == u'print' and print_function in self.context.future_directives:
                 self.keywords.discard('print')
                 systring = EncodedString(systring)
             elif systring == u'exec' and self.context.language_level >= 3:
                 self.keywords.discard('exec')
                 systring = EncodedString(systring)
             else:
                 sy = systring
         else:
             systring = EncodedString(systring)
     self.sy = sy
     self.systring = systring
     if False:  # debug_scanner:
         _, line, col = self.position()
         if not self.systring or self.sy == self.systring:
             t = self.sy
         else:
             t = "%s %s" % (self.sy, self.systring)
         print("--- %3d %2d %s" % (line, col, t))
    def visit_ModuleNode(self, node):
        if node.is_pxd:
            return node
        self.scope_type = 'module'
        self.scope_node = node

        if not self.current_directives['autotestdict']:
            return node
        self.all_docstrings = self.current_directives['autotestdict.all']
        self.cdef_docstrings = self.all_docstrings or self.current_directives['autotestdict.cdef']

        assert isinstance(node.body, StatListNode)

        # First see if __test__ is already created
        if u'__test__' in node.scope.entries:
            # Do nothing
            return node

        pos = node.pos

        self.tests = []
        self.testspos = node.pos

        test_dict_entry = node.scope.declare_var(EncodedString(u'__test__'),
                                                 py_object_type,
                                                 pos,
                                                 visibility='public')
        create_test_dict_assignment = SingleAssignmentNode(pos,
            lhs=NameNode(pos, name=EncodedString(u'__test__'),
                         entry=test_dict_entry),
            rhs=DictNode(pos, key_value_pairs=self.tests))
        self.visitchildren(node)
        node.body.stats.append(create_test_dict_assignment)
        return node
Esempio n. 3
0
    def add_test(self, testpos, name, func_ref_node):
        # func_ref_node must evaluate to the function object containing
        # the docstring, BUT it should not be the function itself (which
        # would lead to a new *definition* of the function)
        pos = self.testspos
        keystr = u'%s (line %d)' % (name, testpos[1])
        key = UnicodeNode(pos, value=EncodedString(keystr))

        value = DocstringRefNode(pos, func_ref_node)
        self.tests.append(DictItemNode(pos, key=key, value=value))
    def macro_call_node(numpy_macro_name):
        array_node = node.obj
        func_entry = numpy_pxd_scope.entries[numpy_macro_name]
        function_name_node = ExprNodes.NameNode(
            name=EncodedString(numpy_macro_name),
            pos=pos,
            entry=func_entry,
            is_called=1,
            type=func_entry.type,
            cf_maybe_null=False,
            cf_is_null=False)

        call_node = ExprNodes.SimpleCallNode(
            pos=pos,
            function=function_name_node,
            name=EncodedString(numpy_macro_name),
            args=[array_node],
            type=func_entry.type.return_type,
            analysed=True)
        return call_node
Esempio n. 5
0
 def next(self):
     try:
         sy, systring = self.read()
     except UnrecognizedInput:
         self.error("Unrecognized character")
     if sy == IDENT:
         if systring in resword_dict:
             sy = systring
         else:
             systring = EncodedString(systring)
     self.sy = sy
     self.systring = systring
     if False: # debug_scanner:
         _, line, col = self.position()
         if not self.systring or self.sy == self.systring:
             t = self.sy
         else:
             t = "%s %s" % (self.sy, self.systring)
         print("--- %3d %2d %s" % (line, col, t))
Esempio n. 6
0
 def add_test(self, testpos, path, doctest):
     pos = self.testspos
     keystr = u'%s (line %d)' % (path, testpos[1])
     key = UnicodeNode(pos, value=EncodedString(keystr))
     value = UnicodeNode(pos, value=doctest)
     self.tests.append(DictItemNode(pos, key=key, value=value))