[Erp5-report] r41846 hugo.maia - in /erp5/trunk/utils/cloudooo/cloudooo: granulate/ handler...
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Dec 28 22:14:55 CET 2010
Author: hugo.maia
Date: Tue Dec 28 22:14:55 2010
New Revision: 41846
URL: http://svn.erp5.org?rev=41846&view=rev
Log:
Change dir structure of granulate
Rename Granulate to Granulator
Added:
erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/
erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/__init__.py
erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/granulator.py
erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/template.odt (with props)
erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulator.py
- copied, changed from r41844, erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulate.py
Removed:
erp5/trunk/utils/cloudooo/cloudooo/granulate/
erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulate.py
Modified:
erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py
Added: erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/__init__.py?rev=41846&view=auto
==============================================================================
(empty)
Added: erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/granulator.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/granulator.py?rev=41846&view=auto
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/granulator.py (added)
+++ erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/granulator.py [utf8] Tue Dec 28 22:14:55 2010
@@ -0,0 +1,220 @@
+##############################################################################
+#
+# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
+# Hugo H. Maia Vieira <hugomaia at tiolive.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsibility of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# guarantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+
+from zope.interface import implements
+from zipfile import ZipFile
+from StringIO import StringIO
+from lxml import etree
+from os import path
+from cloudooo.utils import logger
+from cloudooo.document import OdfDocument
+from cloudooo.interfaces.granulate import ITableGranulator, \
+ IImageGranulator, \
+ ITextGranulator
+
+# URI Definitions.
+TEXT_URI = 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'
+TABLE_URI = 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'
+
+# Odf Namespaces
+TABLE_ATTRIB_NAME = '{%s}name' % TABLE_URI
+TEXT_ATTRIB_STYLENAME = '{%s}style-name' % TEXT_URI
+
+# XPath queries for ODF format
+RELEVANT_PARAGRAPH_XPATH_QUERY = '//text:p[not(ancestor::draw:frame)]'
+DRAW_XPATH_QUERY = './/draw:image'
+TABLE_XPATH_QUERY = './/table:table'
+IMAGE_TITLE_XPATH_QUERY = './/../../text() | .//../../*/text()'
+
+def getTemplatePath(format):
+ """ Get the path of template file. This should goes to
+ some utils library.
+ """
+ return path.join(path.dirname(__file__), 'template.%s' % format)
+
+class OOGranulator(object):
+ """Granulate an OpenOffice document into tables, images, chapters and
+ paragraphs."""
+
+ implements(ITableGranulator, IImageGranulator, ITextGranulator)
+
+ def __init__(self, file, source_format):
+ self.document = OdfDocument(file, source_format)
+
+ def _odfWithoutContentXml(self, format='odt'):
+ """Returns an odf document without content.xml
+ It is a way to escape from this issue: http://bugs.python.org/issue6818"""
+ new_odf_document = ZipFile(StringIO(), 'a')
+ template_path = getTemplatePath(format)
+ template_file = ZipFile(template_path)
+ for item in template_file.filelist:
+ buffer = template_file.read(item.filename)
+ if item.filename != 'content.xml':
+ new_odf_document.writestr(item.filename, buffer)
+ template_file.close()
+ return new_odf_document
+
+ def getTableItemList(self):
+ """Returns the list of table IDs in the form of (id, title)."""
+ xml_table_list = self.document.parsed_content.xpath(TABLE_XPATH_QUERY,
+ namespaces=self.document.parsed_content.nsmap)
+ table_list = []
+ for table in xml_table_list:
+ title = ''.join(table.xpath('following-sibling::text:p[position()=1] \
+ [starts-with(@text:style-name, "Table")]//text()',
+ namespaces=table.nsmap))
+ id = table.attrib[TABLE_ATTRIB_NAME]
+ table_list.append((id, title))
+ return table_list
+
+ def getTableItem(self, id, format='odt'):
+ """Returns the table into a new 'format' file."""
+ try:
+ template_path = getTemplatePath(format)
+ template = ZipFile(template_path)
+ content_xml = etree.fromstring(template.read('content.xml'))
+ template.close()
+ table_list = self.document.parsed_content.xpath(
+ '//table:table[@table:name="%s"]' % id,
+ namespaces=self.document.parsed_content.nsmap)
+ if len(table_list) == 0:
+ return None
+ table = table_list[0]
+ # Next line do this <office:content><office:body><office:text><table:table>
+ content_xml[-1][0].append(table)
+ # XXX: Next line replace the <office:automatic-styles> tag. This include a
+ # lot of unused style tags. Will be better detect the used styles and
+ # include only those.
+ content_xml.replace(content_xml[-2],
+ self.document.parsed_content[-2])
+
+ odf_document = self._odfWithoutContentXml(format)
+ odf_document.writestr('content.xml', etree.tostring(content_xml))
+ odf_document_as_string = odf_document.fp
+ odf_document.close()
+ odf_document_as_string.seek(0)
+ return odf_document_as_string.read()
+ except Exception, e:
+ logger.error(e)
+ return None
+
+ def getTableMatrix(self, id):
+ """Returns the table as a matrix"""
+ row_list = self.document.parsed_content.xpath(
+ '//table:table[@table:name="%s"]/table:table-row' % id,
+ namespaces=self.document.parsed_content.nsmap)
+ if len(row_list) == 0:
+ return None
+
+ matrix = []
+ for row in row_list:
+ matrix_row = []
+ for cell in row.iterchildren():
+ matrix_row.append(''.join(cell.itertext()))
+ matrix.append(matrix_row)
+ return matrix
+
+
+ def getColumnItemList(self, file, table_id):
+ """Return the list of columns in the form of (id, title)."""
+ raise NotImplementedError
+
+ def getLineItemList(self, file, table_id):
+ """Returns the lines of a given table as (key, value) pairs."""
+ raise NotImplementedError
+
+ def getImageItemList(self):
+ """Return a list of tuples with the id and title of image files"""
+ xml_image_list = self.document.parsed_content.xpath(DRAW_XPATH_QUERY,
+ namespaces=self.document.parsed_content.nsmap)
+
+ image_list = []
+ for xml_image in xml_image_list:
+ title = ''.join(xml_image.xpath(IMAGE_TITLE_XPATH_QUERY,
+ namespaces=xml_image.nsmap))
+ id = xml_image.values()[0].split('/')[-1]
+ image_list.append((id, title))
+ return image_list
+
+ def getImage(self, id, format=None, resolution=None, **kw):
+ """Return the given image."""
+ path = 'Pictures/%s' % id
+ return self.document.getFile(path)
+
+ def _getRelevantParagraphList(self):
+ """ This should use memcache or another cache infrastructure.
+ """
+ RELEVANT_PARAGRAPH_CACHE = getattr(self, "RELEVANT_PARAGRAPH_CACHE", None)
+ if RELEVANT_PARAGRAPH_CACHE is None:
+ relevant_paragraph_list = self.document.parsed_content.xpath(
+ RELEVANT_PARAGRAPH_XPATH_QUERY,
+ namespaces=self.document.parsed_content.nsmap)
+ setattr(self, "RELEVANT_PARAGRAPH_CACHE", relevant_paragraph_list)
+
+ return self.RELEVANT_PARAGRAPH_CACHE
+
+ def getParagraphItemList(self):
+ """Returns the list of paragraphs in the form of (id, class) where class
+ may have special meaning to define TOC/TOI."""
+ id = 0
+ paragraph_list = []
+ for p in self._getRelevantParagraphList():
+ paragraph_list.append((id, p.attrib[TEXT_ATTRIB_STYLENAME]))
+ id += 1
+ return paragraph_list
+
+ def getParagraphItem(self, paragraph_id):
+ """Returns the paragraph in the form of (text, class)."""
+ relevant_paragraph_list = self._getRelevantParagraphList()
+ try:
+ paragraph = relevant_paragraph_list[paragraph_id]
+ except IndexError:
+ logger.error("Unable to find paragraph %s at paragraph list." % paragraph_id)
+ return None
+
+ text = ''.join(paragraph.itertext())
+
+ if TEXT_ATTRIB_STYLENAME not in paragraph.attrib.keys():
+ logger.error("Unable to find %s attribute at paragraph %s " % \
+ (TEXT_ATTRIB_STYLENAME, paragraph_id))
+ return None
+
+ p_class = paragraph.attrib[TEXT_ATTRIB_STYLENAME]
+ return (text, p_class)
+
+ def getChapterItemList(self, file):
+ """Returns the list of chapters in the form of (id, level)."""
+ raise NotImplementedError
+
+ def getChapterItem(self, file, chapter_id):
+ """Return the chapter in the form of (title, level)."""
+ raise NotImplementedError
+
+ def trash(self):
+ """Remove the file in memory."""
+ self.document.trash()
Added: erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/template.odt
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/template.odt?rev=41846&view=auto
==============================================================================
Binary file - no diff available.
Propchange: erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/template.odt
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py?rev=41846&r1=41845&r2=41846&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py [utf8] Tue Dec 28 22:14:55 2010
@@ -35,7 +35,7 @@ from cloudooo.mimemapper import MimeMapp
from cloudooo.filter import Filter
from cloudooo.application.xvfb import Xvfb
from cloudooo.monitor.request import MonitorRequest
-from cloudooo.granulate.oogranulate import OOGranulate
+from cloudooo.handler.ooo.granulator import OOGranulator
from cloudooo.interfaces.document import IDocument, IOdfDocument
from cloudooo.interfaces.lockable import ILockable
from cloudooo.interfaces.manager import IManager
@@ -54,8 +54,8 @@ class TestInterface(unittest.TestCase):
"""Test All Interfaces"""
def testITableGranulator(self):
- """Test if OOGranulate implements ITableGranulator"""
- self.assertEquals(ITableGranulator.implementedBy(OOGranulate), True)
+ """Test if OOGranulator implements ITableGranulator"""
+ self.assertEquals(ITableGranulator.implementedBy(OOGranulator), True)
method_list = ['getLineItemList',
'getTableItem',
'getTableItemList',
@@ -64,8 +64,8 @@ class TestInterface(unittest.TestCase):
self.assertEquals(sorted(ITableGranulator.names()), sorted(method_list))
def testITextGranulator(self):
- """Test if OOGranulate implements ITextGranulator"""
- self.assertEquals(ITextGranulator.implementedBy(OOGranulate), True)
+ """Test if OOGranulator implements ITextGranulator"""
+ self.assertEquals(ITextGranulator.implementedBy(OOGranulator), True)
method_list = ['getChapterItemList',
'getParagraphItem',
'getChapterItem',
@@ -73,8 +73,8 @@ class TestInterface(unittest.TestCase):
self.assertEquals(ITextGranulator.names(), method_list)
def testIImageGranulator(self):
- """Test if OOGranulate implements IImageGranulator"""
- self.assertEquals(IImageGranulator.implementedBy(OOGranulate), True)
+ """Test if OOGranulator implements IImageGranulator"""
+ self.assertEquals(IImageGranulator.implementedBy(OOGranulator), True)
method_list = ['getImageItemList', 'getImage']
self.assertEquals(IImageGranulator.names(), method_list)
Removed: erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulate.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulate.py?rev=41845&view=auto
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulate.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulate.py (removed)
@@ -1,187 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
-# Hugo H. Maia Vieira <hugomaia at tiolive.com>
-#
-# WARNING: This program as such is intended to be used by professional
-# programmers who take the whole responsibility of assessing all potential
-# consequences resulting from its eventual inadequacies and bugs
-# End users who are looking for a ready-to-use solution with commercial
-# guarantees and support are strongly adviced to contract a Free Software
-# Service Company
-#
-# This program is Free Software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-##############################################################################
-
-import unittest
-from zipfile import ZipFile
-from StringIO import StringIO
-from lxml import etree
-from cloudoooTestCase import cloudoooTestCase, make_suite
-from cloudooo.granulate.oogranulate import OOGranulate
-
-
-class TestOOGranulate(cloudoooTestCase):
-
- def setUp(self):
- data = open('./data/granulate_test.odt').read()
- self.oogranulate = OOGranulate(data, 'odt')
-
- def testOdfWithoutContentXml(self):
- """Test if _odfWithoutContentXml() return a ZipFile instance without the
- content.xml file"""
- odf_without_content_xml = self.oogranulate._odfWithoutContentXml('odt')
- self.assertTrue(isinstance(odf_without_content_xml, ZipFile))
- complete_name_list = []
- for item in self.oogranulate.document._zipfile.filelist:
- complete_name_list.append(item.filename)
- for item in odf_without_content_xml.filelist:
- self.assertTrue(item.filename in complete_name_list)
- self.assertTrue(item.filename != 'content.xml')
-
- def testgetTableItemList(self):
- """Test if getTableItemList() returns the right tables list"""
- data = open('./data/granulate_table_test.odt').read()
- oogranulate = OOGranulate(data, 'odt')
- table_list = [('Developers', ''),
- ('Prices', 'Table 1: Prices table from Mon Restaurant'),
- ('SoccerTeams', 'Tabela 2: Soccer Teams')]
- self.assertEquals(table_list, oogranulate.getTableItemList())
-
- def testGetTableItem(self):
- """Test if getTableItem() returns on odf file with the right table"""
- data = open('./data/granulate_table_test.odt').read()
- oogranulate = OOGranulate(data, 'odt')
- table_data_doc = oogranulate.getTableItem('Developers')
- content_xml_str = ZipFile(StringIO(table_data_doc)).read('content.xml')
- content_xml = etree.fromstring(content_xml_str)
- table_list = content_xml.xpath('//table:table',
- namespaces=content_xml.nsmap)
- self.assertEquals(1, len(table_list))
- table = table_list[0]
- name_key = '{urn:oasis:names:tc:opendocument:xmlns:table:1.0}name'
- self.assertEquals('Developers', table.attrib[name_key])
-
- def testGetTableItemWithoutSuccess(self):
- """Test if getTableItem() returns None for an non existent table name"""
- data = open('./data/granulate_table_test.odt').read()
- oogranulate = OOGranulate(data, 'odt')
- table_data = oogranulate.getTableItem('NonExistentTable')
- self.assertEquals(table_data, None)
-
- def testGetTableMatrix(self):
- """Test if getTableMatrix() returns the right matrix"""
- data = open('./data/granulate_table_test.odt').read()
- oogranulate = OOGranulate(data, 'odt')
- matrix = [['Name', 'Phone', 'Email'],
- ['Hugo', '+55 (22) 8888-8888', 'hugomaia at tiolive.com'],
- ['Rafael', '+55 (22) 9999-9999', 'rafael at tiolive.com']]
- self.assertEquals(matrix, oogranulate.getTableMatrix('Developers'))
-
- matrix = [['Product', 'Price'],
- ['Pizza', 'R$ 25,00'],
- ['Petit Gateau', 'R$ 10,00'],
- ['Feijoada', 'R$ 30,00']]
- self.assertEquals(matrix, oogranulate.getTableMatrix('Prices'))
-
- self.assertEquals(None, oogranulate.getTableMatrix('Non existent'))
-
-
- def testGetColumnItemList(self):
- """Test if getColumnItemList() returns the right table columns list"""
- self.assertRaises(NotImplementedError, self.oogranulate.getColumnItemList,
- 'file',
- 'table_id')
-
- def testGetLineItemList(self):
- """Test if getLineItemList() returns the right table lines list"""
- self.assertRaises(NotImplementedError, self.oogranulate.getLineItemList,
- 'file',
- 'table_id')
-
- def testGetImageItemList(self):
- """Test if getImageItemList() returns the right images list"""
- image_list = self.oogranulate.getImageItemList()
- self.assertEquals([
- ('10000000000000C80000009C38276C51.jpg', ''),
- ('10000201000000C80000004E7B947D46.png', ''),
- ('10000201000000C80000004E7B947D46.png', 'Illustration 1: TioLive Logo'),
- # XXX The svg image are stored into odf as svm
- ('2000004F00004233000013707E7DE37A.svm', 'Figure 1: Python Logo'),
- ('10000201000000C80000004E7B947D46.png',
- 'Illustration 2: Again TioLive Logo'),
- ], image_list)
-
- def testGetImageSuccessfully(self):
- """Test if getImage() returns the right image file successfully"""
- data = open('./data/granulate_test.odt').read()
- zip = ZipFile(StringIO(data))
- image_id = '10000000000000C80000009C38276C51.jpg'
- original_image = zip.read('Pictures/%s' % image_id)
- geted_image = self.oogranulate.getImage(image_id)
- self.assertEquals(original_image, geted_image)
-
- def testGetImageWithoutSuccess(self):
- """Test if getImage() returns an empty string for not existent id"""
- obtained_image = self.oogranulate.getImage('anything.png')
- self.assertEquals('', obtained_image)
-
- def testGetParagraphItemList(self):
- """Test if getParagraphItemList() returns the right paragraphs list, with
- the ids always in the same order"""
- for i in range(5):
- data = open('./data/granulate_test.odt').read()
- oogranulate = OOGranulate(data, 'odt')
- paragraph_list = oogranulate.getParagraphItemList()
- self.assertEquals((0, 'P3'), paragraph_list[0])
- self.assertEquals((1, 'P1'), paragraph_list[1])
- self.assertEquals((2, 'P12'), paragraph_list[2])
- self.assertEquals((8, 'P13'), paragraph_list[8])
- self.assertEquals((19, 'Standard'), paragraph_list[19])
-
- def testGetParagraphItemSuccessfully(self):
- """Test if getParagraphItem() returns the right paragraph"""
- self.assertEquals(('Some images without title', 'P13'),
- self.oogranulate.getParagraphItem(8))
-
- big_paragraph = self.oogranulate.getParagraphItem(5)
- self.assertEquals('P8', big_paragraph[1])
- self.assertTrue(big_paragraph[0].startswith(u'A prática cotidiana prova'))
- self.assertTrue(big_paragraph[0].endswith(u'corresponde às necessidades.'))
-
- def testGetParagraphItemWithoutSuccess(self):
- """Test if getParagraphItem() returns None for not existent id"""
- self.assertEquals(None, self.oogranulate.getParagraphItem(200))
-
- def testGetChapterItemList(self):
- """Test if getChapterItemList() returns the right chapters list"""
- self.assertRaises(NotImplementedError, self.oogranulate.getChapterItemList,
- 'file')
-
- def testGetChapterItem(self):
- """Test if getChapterItem() returns the right chapter"""
- self.assertRaises(NotImplementedError, self.oogranulate.getChapterItem,
- 'file',
- 'chapter_id')
-
-
-def test_suite():
- return make_suite(TestOOGranulate)
-
-if __name__ == "__main__":
- suite = unittest.TestLoader().loadTestsFromTestCase(TestOOGranulate)
- unittest.TextTestRunner(verbosity=2).run(suite)
Copied: erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulator.py (from r41844, erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulate.py)
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulator.py?p2=erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulator.py&p1=erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulate.py&r1=41844&r2=41846&rev=41846&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulate.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulator.py [utf8] Tue Dec 28 22:14:55 2010
@@ -32,22 +32,22 @@ from zipfile import ZipFile
from StringIO import StringIO
from lxml import etree
from cloudoooTestCase import cloudoooTestCase, make_suite
-from cloudooo.granulate.oogranulate import OOGranulate
+from cloudooo.handler.ooo.granulator import OOGranulator
-class TestOOGranulate(cloudoooTestCase):
+class TestOOGranulator(cloudoooTestCase):
def setUp(self):
data = open('./data/granulate_test.odt').read()
- self.oogranulate = OOGranulate(data, 'odt')
+ self.oogranulator = OOGranulator(data, 'odt')
def testOdfWithoutContentXml(self):
"""Test if _odfWithoutContentXml() return a ZipFile instance without the
content.xml file"""
- odf_without_content_xml = self.oogranulate._odfWithoutContentXml('odt')
+ odf_without_content_xml = self.oogranulator._odfWithoutContentXml('odt')
self.assertTrue(isinstance(odf_without_content_xml, ZipFile))
complete_name_list = []
- for item in self.oogranulate.document._zipfile.filelist:
+ for item in self.oogranulator.document._zipfile.filelist:
complete_name_list.append(item.filename)
for item in odf_without_content_xml.filelist:
self.assertTrue(item.filename in complete_name_list)
@@ -56,17 +56,17 @@ class TestOOGranulate(cloudoooTestCase):
def testgetTableItemList(self):
"""Test if getTableItemList() returns the right tables list"""
data = open('./data/granulate_table_test.odt').read()
- oogranulate = OOGranulate(data, 'odt')
+ oogranulator = OOGranulator(data, 'odt')
table_list = [('Developers', ''),
('Prices', 'Table 1: Prices table from Mon Restaurant'),
('SoccerTeams', 'Tabela 2: Soccer Teams')]
- self.assertEquals(table_list, oogranulate.getTableItemList())
+ self.assertEquals(table_list, oogranulator.getTableItemList())
def testGetTableItem(self):
"""Test if getTableItem() returns on odf file with the right table"""
data = open('./data/granulate_table_test.odt').read()
- oogranulate = OOGranulate(data, 'odt')
- table_data_doc = oogranulate.getTableItem('Developers')
+ oogranulator = OOGranulator(data, 'odt')
+ table_data_doc = oogranulator.getTableItem('Developers')
content_xml_str = ZipFile(StringIO(table_data_doc)).read('content.xml')
content_xml = etree.fromstring(content_xml_str)
table_list = content_xml.xpath('//table:table',
@@ -79,43 +79,43 @@ class TestOOGranulate(cloudoooTestCase):
def testGetTableItemWithoutSuccess(self):
"""Test if getTableItem() returns None for an non existent table name"""
data = open('./data/granulate_table_test.odt').read()
- oogranulate = OOGranulate(data, 'odt')
- table_data = oogranulate.getTableItem('NonExistentTable')
+ oogranulator = OOGranulator(data, 'odt')
+ table_data = oogranulator.getTableItem('NonExistentTable')
self.assertEquals(table_data, None)
def testGetTableMatrix(self):
"""Test if getTableMatrix() returns the right matrix"""
data = open('./data/granulate_table_test.odt').read()
- oogranulate = OOGranulate(data, 'odt')
+ oogranulator = OOGranulator(data, 'odt')
matrix = [['Name', 'Phone', 'Email'],
['Hugo', '+55 (22) 8888-8888', 'hugomaia at tiolive.com'],
['Rafael', '+55 (22) 9999-9999', 'rafael at tiolive.com']]
- self.assertEquals(matrix, oogranulate.getTableMatrix('Developers'))
+ self.assertEquals(matrix, oogranulator.getTableMatrix('Developers'))
matrix = [['Product', 'Price'],
['Pizza', 'R$ 25,00'],
['Petit Gateau', 'R$ 10,00'],
['Feijoada', 'R$ 30,00']]
- self.assertEquals(matrix, oogranulate.getTableMatrix('Prices'))
+ self.assertEquals(matrix, oogranulator.getTableMatrix('Prices'))
- self.assertEquals(None, oogranulate.getTableMatrix('Non existent'))
+ self.assertEquals(None, oogranulator.getTableMatrix('Non existent'))
def testGetColumnItemList(self):
"""Test if getColumnItemList() returns the right table columns list"""
- self.assertRaises(NotImplementedError, self.oogranulate.getColumnItemList,
+ self.assertRaises(NotImplementedError, self.oogranulator.getColumnItemList,
'file',
'table_id')
def testGetLineItemList(self):
"""Test if getLineItemList() returns the right table lines list"""
- self.assertRaises(NotImplementedError, self.oogranulate.getLineItemList,
+ self.assertRaises(NotImplementedError, self.oogranulator.getLineItemList,
'file',
'table_id')
def testGetImageItemList(self):
"""Test if getImageItemList() returns the right images list"""
- image_list = self.oogranulate.getImageItemList()
+ image_list = self.oogranulator.getImageItemList()
self.assertEquals([
('10000000000000C80000009C38276C51.jpg', ''),
('10000201000000C80000004E7B947D46.png', ''),
@@ -132,12 +132,12 @@ class TestOOGranulate(cloudoooTestCase):
zip = ZipFile(StringIO(data))
image_id = '10000000000000C80000009C38276C51.jpg'
original_image = zip.read('Pictures/%s' % image_id)
- geted_image = self.oogranulate.getImage(image_id)
+ geted_image = self.oogranulator.getImage(image_id)
self.assertEquals(original_image, geted_image)
def testGetImageWithoutSuccess(self):
"""Test if getImage() returns an empty string for not existent id"""
- obtained_image = self.oogranulate.getImage('anything.png')
+ obtained_image = self.oogranulator.getImage('anything.png')
self.assertEquals('', obtained_image)
def testGetParagraphItemList(self):
@@ -145,8 +145,8 @@ class TestOOGranulate(cloudoooTestCase):
the ids always in the same order"""
for i in range(5):
data = open('./data/granulate_test.odt').read()
- oogranulate = OOGranulate(data, 'odt')
- paragraph_list = oogranulate.getParagraphItemList()
+ oogranulator = OOGranulator(data, 'odt')
+ paragraph_list = oogranulator.getParagraphItemList()
self.assertEquals((0, 'P3'), paragraph_list[0])
self.assertEquals((1, 'P1'), paragraph_list[1])
self.assertEquals((2, 'P12'), paragraph_list[2])
@@ -156,32 +156,32 @@ class TestOOGranulate(cloudoooTestCase):
def testGetParagraphItemSuccessfully(self):
"""Test if getParagraphItem() returns the right paragraph"""
self.assertEquals(('Some images without title', 'P13'),
- self.oogranulate.getParagraphItem(8))
+ self.oogranulator.getParagraphItem(8))
- big_paragraph = self.oogranulate.getParagraphItem(5)
+ big_paragraph = self.oogranulator.getParagraphItem(5)
self.assertEquals('P8', big_paragraph[1])
self.assertTrue(big_paragraph[0].startswith(u'A prática cotidiana prova'))
self.assertTrue(big_paragraph[0].endswith(u'corresponde às necessidades.'))
def testGetParagraphItemWithoutSuccess(self):
"""Test if getParagraphItem() returns None for not existent id"""
- self.assertEquals(None, self.oogranulate.getParagraphItem(200))
+ self.assertEquals(None, self.oogranulator.getParagraphItem(200))
def testGetChapterItemList(self):
"""Test if getChapterItemList() returns the right chapters list"""
- self.assertRaises(NotImplementedError, self.oogranulate.getChapterItemList,
+ self.assertRaises(NotImplementedError, self.oogranulator.getChapterItemList,
'file')
def testGetChapterItem(self):
"""Test if getChapterItem() returns the right chapter"""
- self.assertRaises(NotImplementedError, self.oogranulate.getChapterItem,
+ self.assertRaises(NotImplementedError, self.oogranulator.getChapterItem,
'file',
'chapter_id')
def test_suite():
- return make_suite(TestOOGranulate)
+ return make_suite(TestOOGranulator)
if __name__ == "__main__":
- suite = unittest.TestLoader().loadTestsFromTestCase(TestOOGranulate)
+ suite = unittest.TestLoader().loadTestsFromTestCase(TestOOGranulator)
unittest.TextTestRunner(verbosity=2).run(suite)
More information about the Erp5-report
mailing list