[Erp5-report] r40433 hugo.maia - in /erp5/trunk/utils/cloudooo/cloudooo: granulate/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Sat Nov 20 22:20:58 CET 2010


Author: hugo.maia
Date: Sat Nov 20 22:20:58 2010
New Revision: 40433

URL: http://svn.erp5.org?rev=40433&view=rev
Log:
Add initial implementation of granulate features in cloudooo

Added:
    erp5/trunk/utils/cloudooo/cloudooo/granulate/
    erp5/trunk/utils/cloudooo/cloudooo/granulate/__init__.py
    erp5/trunk/utils/cloudooo/cloudooo/granulate/oogranulate.py
    erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulate.py
Modified:
    erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py

Added: erp5/trunk/utils/cloudooo/cloudooo/granulate/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/granulate/__init__.py?rev=40433&view=auto
==============================================================================
    (empty)

Added: erp5/trunk/utils/cloudooo/cloudooo/granulate/oogranulate.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/granulate/oogranulate.py?rev=40433&view=auto
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/granulate/oogranulate.py (added)
+++ erp5/trunk/utils/cloudooo/cloudooo/granulate/oogranulate.py [utf8] Sat Nov 20 22:20:58 2010
@@ -0,0 +1,77 @@
+##############################################################################
+#
+# 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 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
+

Modified: erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py?rev=40433&r1=40432&r2=40433&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py [utf8] Sat Nov 20 22:20:58 2010
@@ -35,6 +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.interfaces.document import IDocument
 from cloudooo.interfaces.lockable import ILockable
 from cloudooo.interfaces.manager import IManager
@@ -43,11 +44,35 @@ from cloudooo.interfaces.filter import I
 from cloudooo.interfaces.mimemapper import IMimemapper
 from cloudooo.interfaces.handler import IHandler
 from cloudooo.interfaces.monitor import IMonitor
+from cloudooo.interfaces.granulate import ITableGranulator, \
+                                          IImageGranulator, \
+                                          ITextGranulator
 from cloudoooTestCase import make_suite
 
 class TestInterface(unittest.TestCase):
   """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):
     """Test if FileSystemDocument implements IDocument"""
     self.assertEquals(IDocument.implementedBy(FileSystemDocument), True)
@@ -86,7 +111,7 @@ class TestInterface(unittest.TestCase):
         'isLoaded']
     for method in method_list:
       self.assertEquals(method in IMimemapper.names(), True)
-    
+
     self.assertEquals(IMimemapper.implementedBy(MimeMapper),True)
     self.assertEquals(len(method_list),len(IMimemapper.names()))
     self.assertEquals(IMimemapper.get('getFilterName').required, ('extension',
@@ -109,7 +134,7 @@ class TestInterface(unittest.TestCase):
     self.assertEquals(IHandler.implementedBy(OOHandler), True)
     method_list = ['convert', 'getMetadata', 'setMetadata']
     for method in method_list:
-      self.assertEquals(method in IHandler.names(), True, 
+      self.assertEquals(method in IHandler.names(), True,
           "Method %s is not declared" % method)
     self.assertEquals(len(method_list), len(IHandler.names()))
     self.assertEquals(IHandler.get('convert').required, ('destination_format',))
@@ -125,7 +150,7 @@ class TestInterface(unittest.TestCase):
     application_method_list = ["start", "stop", "pid",
                               "status", "restart",
                               "loadSettings", "getAddress"]
-    self.assertEquals(sorted(IApplication.names()), 
+    self.assertEquals(sorted(IApplication.names()),
         sorted(application_method_list))
 
   def testILockable(self):
@@ -141,3 +166,4 @@ def test_suite():
 if __name__ == "__main__":
   suite = unittest.TestLoader().loadTestsFromTestCase(TestInterface)
   unittest.TextTestRunner(verbosity=2).run(suite)
+

Added: erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulate.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulate.py?rev=40433&view=auto
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulate.py (added)
+++ erp5/trunk/utils/cloudooo/cloudooo/tests/testOOGranulate.py [utf8] Sat Nov 20 22:20:58 2010
@@ -0,0 +1,71 @@
+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)
+




More information about the Erp5-report mailing list