Commit 952d74b0 authored by Jérome Perrin's avatar Jérome Perrin

testOooInterface: use zope.interface built in verify utility

instead of re-implementing our own. Updating to zope.interface 5.4
caused test failures:

      File "cloudooo/handler/ooo/tests/testOooInterface.py", line 90, in testIOdfDocument
        self.assertEquals(IOdfDocument.names(), method_list)
    AssertionError: Lists differ: ['getFile', 'source_format', '... != ['getContentXml', 'parsed_cont...

    First differing element 0:
    'getFile'
    'getContentXml'

    - ['getFile', 'source_format', 'getContentXml', 'parsed_content']
    + ['getContentXml', 'parsed_content', 'source_format', 'getFile']

This is because Interface.name() order is unspecified.

As we could see in the XXX comments in the test, hardcoding the method
names from the interface was not ideal, using the built-in verifyClass
is better because it performs more checks and because error reporting
is also much more detailed.

cf. https://zopeinterface.readthedocs.io/en/latest/verify.html
parent b2703b2d
Pipeline #23200 passed with stage
in 0 seconds
...@@ -48,137 +48,57 @@ from cloudooo.interfaces.granulate import ITableGranulator, \ ...@@ -48,137 +48,57 @@ from cloudooo.interfaces.granulate import ITableGranulator, \
ITextGranulator ITextGranulator
from cloudooo.tests.backportUnittest import TestCase, expectedFailure from cloudooo.tests.backportUnittest import TestCase, expectedFailure
import zope.interface.verify
class TestInterface(TestCase): class TestInterface(TestCase):
"""Test All Interfaces""" """Test All Interfaces"""
def testITableGranulator(self): def testITableGranulator(self):
"""Test if Manager implements ITableGranulator""" """Test if Manager implements ITableGranulator"""
self.assertTrue(ITableGranulator.implementedBy(Manager)) zope.interface.verify.verifyClass(ITableGranulator, Manager)
method_list = ['getLineItemList',
'getTable',
'getTableItemList',
'getColumnItemList']
self.assertEquals(sorted(ITableGranulator.names()), sorted(method_list))
def testITextGranulator(self): def testITextGranulator(self):
"""Test if Manager implements ITextGranulator""" """Test if Manager implements ITextGranulator"""
self.assertTrue(ITextGranulator.implementedBy(Manager)) zope.interface.verify.verifyClass(ITextGranulator, Manager)
method_list = ['getChapterItemList',
'getParagraph',
'getChapterItem',
'getParagraphItemList']
self.assertEquals(ITextGranulator.names(), method_list)
def testIImageGranulator(self): def testIImageGranulator(self):
"""Test if Manager implements IImageGranulator""" """Test if Manager implements IImageGranulator"""
self.assertTrue(IImageGranulator.implementedBy(Manager)) zope.interface.verify.verifyClass(IImageGranulator, Manager)
method_list = ['getImageItemList', 'getImage']
self.assertEquals(IImageGranulator.names(), method_list)
def testIFile(self): def testIFile(self):
"""Test if FileSystemDocument implements IFile""" """Test if FileSystemDocument implements IFile"""
self.assertTrue(IFile.implementedBy(FileSystemDocument)) zope.interface.verify.verifyClass(IFile, FileSystemDocument)
def testIOdfDocument(self): def testIOdfDocument(self):
"""Test if OdfDocument implements IOdfDocument""" """Test if OdfDocument implements IOdfDocument"""
self.assertTrue(IOdfDocument.implementedBy(OdfDocument)) zope.interface.verify.verifyClass(IOdfDocument, OdfDocument)
method_list = ['getContentXml',
'parsed_content',
'source_format',
'getFile']
self.assertEquals(IOdfDocument.names(), method_list)
def testIFilter(self): def testIFilter(self):
"""Test if Filter implements IFile""" """Test if Filter implements IFile"""
self.assertTrue(IFilter.implementedBy(Filter)) zope.interface.verify.verifyClass(IFilter, Filter)
self.assertEquals(IFilter.names(), ['getLabel', 'getName', 'getSortIndex',
'isPreferred', 'getDocumentService', 'getExtension', 'getMimetype'])
# XXX Change at interfaces are not applied in real classes.
# This tests should be rewrited to test the real classes instead hardcore
# copy and paste information.
@expectedFailure @expectedFailure
def testIManager(self): def testIManager(self):
"""Test if Manager implements IManager""" """Test if Manager implements IManager"""
self.assertTrue(IManager.implementedBy(Manager)) zope.interface.verify.verifyClass(IManager, Manager)
method_list = ['convertFile',
'getFileMetadataItemList',
'updateFileMetadata',
'getAllowedExtensionList',
'granulateFile']
for method in method_list:
self.assertTrue(method in IManager.names())
self.assertEquals(len(method_list), len(IManager.names()))
self.assertEquals(IManager.get('convertFile').required, ('file',
'source_format', 'destination_format', 'zip', 'refresh'))
self.assertEquals(IManager.get('getAllowedExtensionList').required,
('request_dict',))
self.assertEquals(IManager.get('getFileMetadataItemList').required,
('file', 'source_format', 'base_document'))
self.assertEquals(IManager.get('updateFileMetadata').required,
('file', 'source_format', 'metadata_dict'))
# XXX Change at interfaces are not applied in real classes.
# This tests should be rewrited to test the real classes instead hardcore
# copy and paste information.
@expectedFailure @expectedFailure
def testIMimeMapper(self): def testIMimeMapper(self):
"""Test if Mimemapper implements IMimemapper.""" """Test if Mimemapper implements IMimemapper."""
method_list = ['getDocumentTypeDict', 'getFilterName', 'loadFilterList', zope.interface.verify.verifyClass(IMimemapper, MimeMapper)
'getFilterList', 'getAllowedExtensionList',
'isLoaded']
for method in method_list:
self.assertTrue(method in IMimemapper.names())
self.assertTrue(IMimemapper.implementedBy(MimeMapper))
self.assertEquals(len(method_list), len(IMimemapper.names()))
self.assertEquals(IMimemapper.get('getFilterName').required,
('extension', 'document_type'))
self.assertEquals(IMimemapper.get('loadFilterList').required, ())
self.assertEquals(IMimemapper.get('getFilterList').required, ('extension',))
self.assertEquals(IMimemapper.get('getDocumentTypeDict').required, ())
self.assertEquals(IMimemapper.get('getAllowedExtensionList').required,
("document_type",))
def testIMonitor(self): def testIMonitor(self):
"""Test if Monitors implements IMonitor""" """Test if Monitors implements IMonitor"""
self.assertTrue(IMonitor.implementedBy(MonitorRequest)) zope.interface.verify.verifyClass(IMonitor, MonitorRequest)
self.assertEquals(IMonitor.names(), ["run"])
# XXX Change at interfaces are not applied in real classes.
# This tests should be rewrited to test the real classes instead hardcore
# copy and paste information.
@expectedFailure
def testIHandler(self): def testIHandler(self):
"""Test if Handlers implements IHandler""" """Test if Handlers implements IHandler"""
self.assertTrue(IHandler.implementedBy(Handler)) zope.interface.verify.verifyClass(IHandler, Handler)
method_list = ['convert', 'getMetadata', 'setMetadata']
for method in method_list:
self.assertTrue(method in IHandler.names(),
"Method %s is not declared" % method)
self.assertEquals(len(method_list), len(IHandler.names()))
self.assertEquals(IHandler.get('convert').required, ('destination_format',))
self.assertEquals(IHandler.get('getMetadata').required,
('converted_data',))
self.assertEquals(IHandler.get('setMetadata').required,
('metadata_dict',))
def testIApplication(self): def testIApplication(self):
"""Test if OpenOffice implements IApplication""" """Test if OpenOffice implements IApplication"""
self.assertTrue(IApplication.implementedBy(OpenOffice)) zope.interface.verify.verifyClass(IApplication, OpenOffice)
application_method_list = ["start", "stop", "pid",
"status", "restart",
"loadSettings", "getAddress"]
self.assertEquals(sorted(IApplication.names()),
sorted(application_method_list))
def testILockable(self): def testILockable(self):
"""Test if Openoffice implements ILockable""" """Test if Openoffice implements ILockable"""
self.assertTrue(ILockable.implementedBy(OpenOffice)) zope.interface.verify.verifyClass(ILockable, OpenOffice)
lockable_method_list = ["_lock", "acquire", "release", "isLocked"]
self.assertEquals(sorted(ILockable.names()), sorted(lockable_method_list))
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