Commit 5dd57a5a authored by Hugo H. Maia Vieira's avatar Hugo H. Maia Vieira

Add initial implementation of granulate features in cloudooo

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@40433 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5d1905aa
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Hugo H. Maia Vieira <hugomaia@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 cloudooo.interfaces.granulate import ITableGranulator, \
IImageGranulator, \
ITextGranulator
class OOGranulate(object):
"""Granulate an OpenOffice document into tables, images, chapters and
paragraphs."""
implements(ITableGranulator, IImageGranulator, ITextGranulator)
def getTableItemList(self, file):
"""Returns the list of table IDs in the form of (id, title)."""
raise NotImplementedError
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, file):
"""Return the list of images in the form of (id, title)."""
raise NotImplementedError
def getImage(self, file, image_id, format=None, resolution=None, **kw):
"""Return the given image."""
raise NotImplementedError
def getParagraphItemList(self, file):
"""Returns the list of paragraphs in the form of (id, class) where class
may have special meaning to define TOC/TOI."""
raise NotImplementedError
def getParagraphItem(self, file, paragraph_id):
"""Returns the paragraph in the form of (text, class)."""
raise NotImplementedError
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
...@@ -35,6 +35,7 @@ from cloudooo.mimemapper import MimeMapper ...@@ -35,6 +35,7 @@ from cloudooo.mimemapper import MimeMapper
from cloudooo.filter import Filter from cloudooo.filter import Filter
from cloudooo.application.xvfb import Xvfb from cloudooo.application.xvfb import Xvfb
from cloudooo.monitor.request import MonitorRequest from cloudooo.monitor.request import MonitorRequest
from cloudooo.granulate.oogranulate import OOGranulate
from cloudooo.interfaces.document import IDocument from cloudooo.interfaces.document import IDocument
from cloudooo.interfaces.lockable import ILockable from cloudooo.interfaces.lockable import ILockable
from cloudooo.interfaces.manager import IManager from cloudooo.interfaces.manager import IManager
...@@ -43,11 +44,35 @@ from cloudooo.interfaces.filter import IFilter ...@@ -43,11 +44,35 @@ from cloudooo.interfaces.filter import IFilter
from cloudooo.interfaces.mimemapper import IMimemapper from cloudooo.interfaces.mimemapper import IMimemapper
from cloudooo.interfaces.handler import IHandler from cloudooo.interfaces.handler import IHandler
from cloudooo.interfaces.monitor import IMonitor from cloudooo.interfaces.monitor import IMonitor
from cloudooo.interfaces.granulate import ITableGranulator, \
IImageGranulator, \
ITextGranulator
from cloudoooTestCase import make_suite from cloudoooTestCase import make_suite
class TestInterface(unittest.TestCase): class TestInterface(unittest.TestCase):
"""Test All Interfaces""" """Test All Interfaces"""
def testITableGranulator(self):
"""Test if OOGranulate implements ITableGranulator"""
self.assertEquals(ITableGranulator.implementedBy(OOGranulate), True)
method_list = ['getColumnItemList', 'getLineItemList', 'getTableItemList']
self.assertEquals(ITableGranulator.names(), method_list)
def testITextGranulator(self):
"""Test if OOGranulate implements ITextGranulator"""
self.assertEquals(ITextGranulator.implementedBy(OOGranulate), True)
method_list = ['getChapterItemList',
'getParagraphItem',
'getChapterItem',
'getParagraphItemList']
self.assertEquals(ITextGranulator.names(), method_list)
def testIImageGranulator(self):
"""Test if OOGranulate implements IImageGranulator"""
self.assertEquals(IImageGranulator.implementedBy(OOGranulate), True)
method_list = ['getImageItemList', 'getImage']
self.assertEquals(IImageGranulator.names(), method_list)
def testIDocument(self): def testIDocument(self):
"""Test if FileSystemDocument implements IDocument""" """Test if FileSystemDocument implements IDocument"""
self.assertEquals(IDocument.implementedBy(FileSystemDocument), True) self.assertEquals(IDocument.implementedBy(FileSystemDocument), True)
...@@ -141,3 +166,4 @@ def test_suite(): ...@@ -141,3 +166,4 @@ def test_suite():
if __name__ == "__main__": if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TestInterface) suite = unittest.TestLoader().loadTestsFromTestCase(TestInterface)
unittest.TextTestRunner(verbosity=2).run(suite) unittest.TextTestRunner(verbosity=2).run(suite)
import unittest
from cloudoooTestCase import cloudoooTestCase, make_suite
from cloudooo.granulate.oogranulate import OOGranulate
class TestOOGranulate(cloudoooTestCase):
def setUp(self):
self.oogranulate = OOGranulate()
def testgetTableItemList(self):
"""Test if getTableItemList() returns the right tables list"""
self.assertRaises(NotImplementedError, self.oogranulate.getTableItemList,
'file')
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"""
self.assertRaises(NotImplementedError, self.oogranulate.getImageItemList,
'file')
def testGetImage(self):
"""Test if getImage() returns the right image file"""
self.assertRaises(NotImplementedError, self.oogranulate.getImage,
'file',
'image_id',
'format',
'resolution')
def testGetParagraphItemList(self):
"""Test if getParagraphItemList() returns the right paragraphs list"""
self.assertRaises(NotImplementedError,
self.oogranulate.getParagraphItemList,
'file')
def testGetParagraphItem(self):
"""Test if getParagraphItem() returns the right paragraph"""
self.assertRaises(NotImplementedError, self.oogranulate.getParagraphItem,
'file',
'paragraph_id')
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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment