Package nsi :: Package granulate :: Package tests :: Module testGranulateOffice
[hide private]
[frames] | no frames]

Source Code for Module nsi.granulate.tests.testGranulateOffice

  1  #!/usr/bin/python 
  2  ############################################################################## 
  3  # 
  4  # Copyright (c) 2007 ISrg (NSI, CEFETCAMPOS, BRAZIL) and Contributors.  
  5  #                                                         All Rights Reserved. 
  6  #                              Ronaldo Amaral Santos <ronaldinho.as@gmail.com>  
  7  # 
  8  # WARNING: This program as such is intended to be used by professional 
  9  # programmers who take the whole responsability of assessing all potential 
 10  # consequences resulting from its eventual inadequacies and bugs 
 11  # End users who are looking for a ready-to-use solution with commercial 
 12  # garantees and support are strongly adviced to contract a Free Software 
 13  # Service Company 
 14  # 
 15  # This program is Free Software; you can redistribute it and/or 
 16  # modify it under the terms of the GNU General Public License 
 17  # as published by the Free Software Foundation; either version 2 
 18  # of the License, or (at your option) any later version. 
 19  # 
 20  # This program is distributed in the hope that it will be useful, 
 21  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 22  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 23  # GNU General Public License for more details. 
 24  # 
 25  # You should have received a copy of the GNU General Public License 
 26  # along with this program; if not, write to the Free Software 
 27  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 28  # 
 29  ############################################################################## 
 30   
 31  __author__ = """Ronaldo Amaral Santos <ronaldinho.as@gmail.com>""" 
 32  __docformat__ = 'plaintext' 
 33   
 34  """ 
 35  Test methods GranulateOffice  
 36  """ 
 37   
 38  import sys, unittest 
 39  import re, time,os 
 40  from nsi.granulate import File 
 41  from nsi.granulate import GranulateOffice 
 42   
 43   
 44  filePath = os.path.join(os.path.dirname(__file__), 'data', 'test.odt') 
 45   
 46  try: 
 47      filedata = open(filePath, 'rb').read() 
 48  except IOError: 
 49      print "File not found" 
 50      sys.exit(1) 
 51   
 52   
53 -class TestGranulateOffice(unittest.TestCase):
54
55 - def createInstanceGraOffice(self):
56 fileDoc = File(data=filedata,filename='test.odt') 57 granObj = GranulateOffice(fileDoc) 58 return granObj
59
61 """ 62 This test passes arguments the old way. 63 """ 64 t1 = time.time() 65 granObj = self.createInstanceGraOffice() 66 print (time.time() -t1)/(24*3600) 67 self.failUnless(granObj is not None) 68 self.failUnless(granObj.Document is not None)
69 #self.failUnless(granObj.__parseContent is not None) 70 #self.failUnless(granObj.__zipFile is not None) 71
72 - def testGranulateDocument(self):
73 """ 74 This test passes arguments the old way. 75 """ 76 t1 = time.time() 77 granObj = self.createInstanceGraOffice() 78 self.failUnless(granObj is not None) 79 resultDict = granObj.granulateDocument() 80 self.assertEquals(len(resultDict['image_list']), 26) 81 self.assertEquals(len(resultDict['table_list']), 1) 82 print (time.time() -t1)/(24*3600)
83
84 - def testGetTableDocumentList(self):
85 """ 86 This test passes arguments the old way. 87 """ 88 t1 = time.time() 89 granObj = self.createInstanceGraOffice() 90 self.failUnless(granObj is not None) 91 resultList = granObj.getTableDocumentList() 92 self.assertEquals(len(resultList), 1) 93 print (time.time() -t1)/(24*3600)
94
95 - def testGetImageDocumentList(self):
96 """ 97 This test passes arguments the old way. 98 """ 99 t1 = time.time() 100 granObj = self.createInstanceGraOffice() 101 self.failUnless(granObj is not None) 102 resultList = granObj.getImageDocumentList() 103 self.assertEquals(len(resultList), 26) 104 print (time.time() -t1)/(24*3600)
105
107 """ 108 This test passes arguments the old way. 109 """ 110 t1 = time.time() 111 granObj = self.createInstanceGraOffice() 112 self.failUnless(granObj is not None) 113 result = granObj.getThumbnailsDocument() 114 self.failUnless(result is not None) 115 #self.assertEquals(resultDict['thumbnails'], is instance) 116 print (time.time() -t1)/(24*3600)
117
118 - def testGetSummaryDocument(self):
119 """ 120 This test passes arguments the old way. 121 """ 122 t1 = time.time() 123 granObj = self.createInstanceGraOffice() 124 self.failUnless(granObj is not None) 125 resultList = granObj.getSummaryDocument() 126 self.failUnless(resultList is None) 127 #self.assertEquals(resultDict['summary'], None) 128 print (time.time() -t1)/(24*3600)
129
131 """ 132 This test all methods. 133 """ 134 t1 = time.time() 135 #import pdb; pdb.set_trace() 136 granObj = self.createInstanceGraOffice() 137 self.failUnless(granObj is not None) 138 resultDict = granObj.granulateDocument() 139 self.assertEquals(len(resultDict['image_list']), 26) 140 self.assertEquals(len(resultDict['table_list']), 1) 141 142 resultListTable = granObj.getTableDocumentList() 143 self.assertEquals(len(resultListTable), 1) 144 145 resultListImage = granObj.getImageDocumentList() 146 self.assertEquals(len(resultListImage), 26) 147 148 resultThumbnails = granObj.getThumbnailsDocument() 149 self.failUnless(resultThumbnails is not None) 150 151 resultListSummary = granObj.getSummaryDocument() 152 self.failUnless(resultListSummary is None) 153 154 print (time.time() -t1)/(24*3600)
155 156 157 if __name__=='__main__': 158 tests=(TestGranulateOffice,) 159 for t in tests: 160 suite = unittest.makeSuite(t) 161 unittest.TextTestRunner(verbosity=2).run(suite) 162