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')
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'])
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()