예제 #1
0
 def setUp(self):
     """
     Sets up a temporary AST for use with our unit tests.
     """
     self.options = TestDoxypypy.__Options(True, True, False, 'dummy',
                                           'dummy', 4)
     self.dummyWalker = AstWalker(TestDoxypypy.__dummySrc, self.options,
                                  'dummy.py')
예제 #2
0
 def snippetComparison(self, sampleSnippets):
     """
     Compare docstring parsing for a list of code snippets.
     """
     for snippetTest in sampleSnippets:
         testWalker = AstWalker(snippetTest['inputCode'].split(linesep),
                                self.options, snippetTest['name'] + '.py')
         funcAst = parse(snippetTest['inputCode'])
         getattr(testWalker, snippetTest['visitor'])(funcAst.body[0])
         self.assertEqual(testWalker.lines, snippetTest['expectedOutput'])
예제 #3
0
 def readAndParseFile(inFilename, options):
     """
     Helper function to read and parse a given file and create an AST walker.
     """
     # Read contents of input file.
     inFile = open(inFilename)
     lines = inFile.readlines()
     inFile.close()
     # Create the abstract syntax tree for the input file.
     testWalker = AstWalker(lines, options, inFilename)
     testWalker.parseLines()
     # Output the modified source.
     return testWalker.getLines()
예제 #4
0
    def __call__(self, filename, lines):
        """
        ### &doc_id postprocess:DoxypypyPostProcess_call

        The main bridge between DoxyTH and Doxypypy. Re-creates the doxypypy variables and gives it to the AstWalker

        Args:
            filename: The file_name name
            lines: The file_name lines
        """

        from doxypypy.doxypypy import AstWalker
        from os import sep
        from optparse import Values
        from .langs import ascii_encode

        # Replace all the lines by a normal \n at the end
        try:
            lines = [f"{line.rstrip()}\n" for line in lines]
        except UnicodeEncodeError:
            lines = [f"{ascii_encode(line).rstrip()}\n" for line in lines]

        # Define options
        options = {'autobrief': True, 'autocode': True, 'topLevelNamespace': None, 'tablength': 4, 'debug': None}

        # All the code below is extracted from doxypypy (with a few edits to fit in with doxyth)

        full_path_namespace = filename.replace(sep, '.')[:-3]
        # Use any provided top-level namespace argument to trim off excess.
        real_namespace = full_path_namespace
        if options['topLevelNamespace']:
            namespace_start = full_path_namespace.find(options['topLevelNamespace'])
            if namespace_start >= 0:
                real_namespace = full_path_namespace[namespace_start:]
        options['fullPathNamespace'] = real_namespace

        ast_walker = AstWalker(lines, Values(defaults=options), filename)
        ast_walker.parseLines()
        # Output the modified source.
        print(ast_walker.getLines())