class TestPyModule(unittest.TestCase): def setUp(self): self.emptyFile = testDir + '/pythonfiles/empty.py' self.emptyStringFile = '# Empty python file\n# Some more' self.realFile = testDir + '/pythonfiles/ParserTest.py' self.indentationFile = testDir + '/pythonfiles/ParserTest2.py' self.parser = PyModule(self.realFile) self.function = self.parser.functions['someMethod'] self.oneLineFunction = self.parser.functions['oneLineMethod'] self.klass = self.parser.classes['ParserTest'] self.method = self.klass.methods['parserMethod'] self.manualMethod = self.klass.methods['parserMethod2'] def testReadFile1(self): """ Don't barf on an empty file """ self.parser.readFile(self.emptyFile) def testReadFile2(self): """ Also accept a file pointer instead of a filename """ file = open(self.emptyFile) self.parser.readFile(file) file.close() def testReadFile3(self): """ Don't barf on an empty string-file """ parser = PyModule(self.emptyStringFile, mode='string') def testReadFile4(self): """ Barf on an empty string-file without correct mode """ self.assertRaises(IOError, self.parser.readFile, self.emptyStringFile) def testFindClassesAndFunctions(self): """ Find the correct number of classes and functions tests/pythonfiles/ParserTest.py contains: 1 class + 1 function """ self.assertEquals(len(self.parser.classes), 1) self.assertEquals(len(self.parser.functions), 2) def testFindProtectedSections(self): """ Find the correct number of protected sections tests/pythonfiles/ParserTest.py contains 4 protected sections: module-header, after-schema, class-header, module-footer. """ self.assertEquals(len(self.parser.protectedSections), 4) def testFindProtectionDeclarations(self): """ Find the correct number of protection declarations tests/pythonfiles/ParserTest.py contains 2 protection declarations. """ self.assertEquals(len(self.parser.protectionDeclarations), 2)
def setUp(self): self.emptyFile = testDir + '/pythonfiles/empty.py' self.emptyStringFile = '# Empty python file\n# Some more' self.realFile = testDir + '/pythonfiles/ParserTest.py' self.indentationFile = testDir + '/pythonfiles/ParserTest2.py' self.parser = PyModule(self.realFile) self.function = self.parser.functions['someMethod'] self.oneLineFunction = self.parser.functions['oneLineMethod'] self.klass = self.parser.classes['ParserTest'] self.method = self.klass.methods['parserMethod'] self.manualMethod = self.klass.methods['parserMethod2']