Commit 11deccde authored by Gabriel Monnerat's avatar Gabriel Monnerat

clean up the code to follow PEP08

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@43709 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7c494df9
...@@ -35,7 +35,7 @@ from tempfile import mktemp ...@@ -35,7 +35,7 @@ from tempfile import mktemp
class FFMPEGHandler(object): class FFMPEGHandler(object):
"""FFMPEGHandler is used to handler inputed video files""" """FFMPEGHandler is used to handler inputed video files"""
implements(IHandler) implements(IHandler)
def __init__(self, base_folder_url, data, source_format, **kw): def __init__(self, base_folder_url, data, source_format, **kw):
...@@ -72,18 +72,17 @@ class FFMPEGHandler(object): ...@@ -72,18 +72,17 @@ class FFMPEGHandler(object):
return self.input.getContent() return self.input.getContent()
finally: finally:
self.input.trash() self.input.trash()
def getMetadata(self, base_document=False): def getMetadata(self, base_document=False):
"""Returns a dictionary with all metadata of the video. """Returns a dictionary with all metadata of the video.
Keywords Arguments: Keywords Arguments:
base_document -- Boolean variable. if true, the video is also returned base_document -- Boolean variable. if true, the video is also returned
along with the metadata.""" along with the metadata."""
raise NotImplementedError raise NotImplementedError
def setMetadata(self, metadata={}): def setMetadata(self, metadata={}):
"""Returns a document with new metadata. """Returns a document with new metadata.
Keyword arguments: Keyword arguments:
metadata -- expected an dictionary with metadata. metadata -- expected an dictionary with metadata.
""" """
raise NotImplementedError raise NotImplementedError
...@@ -33,12 +33,13 @@ from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite ...@@ -33,12 +33,13 @@ from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
file_detector = Magic(mime=True) file_detector = Magic(mime=True)
class TestAllFormats(HandlerTestCase): class TestAllFormats(HandlerTestCase):
def afterSetUp(self): def afterSetUp(self):
self.data = open("./data/test.ogv").read() self.data = open("./data/test.ogv").read()
self.input = FFMPEGHandler(self.tmp_url, self.data, "ogv") self.input = FFMPEGHandler(self.tmp_url, self.data, "ogv")
def testAviFormat(self): def testAviFormat(self):
"""Test convert file to avi format the reverse convertion""" """Test convert file to avi format the reverse convertion"""
output_data = self.input.convert("avi") output_data = self.input.convert("avi")
...@@ -46,9 +47,9 @@ class TestAllFormats(HandlerTestCase): ...@@ -46,9 +47,9 @@ class TestAllFormats(HandlerTestCase):
output = FFMPEGHandler(self.tmp_url, output_data, "avi") output = FFMPEGHandler(self.tmp_url, output_data, "avi")
input_data = output.convert("ogv") input_data = output.convert("ogv")
input_format = file_detector.from_buffer(input_data) input_format = file_detector.from_buffer(input_data)
self.assertTrue((output_format ==('video/avi')) and self.assertEquals(output_format, 'video/avi')
(input_format == 'video/ogg')) self.assertEquals(input_format, 'video/ogg')
def testMp4Format(self): def testMp4Format(self):
"""Test convert file to mp4 format the reverse convertion""" """Test convert file to mp4 format the reverse convertion"""
output_data = self.input.convert("mp4") output_data = self.input.convert("mp4")
...@@ -56,8 +57,8 @@ class TestAllFormats(HandlerTestCase): ...@@ -56,8 +57,8 @@ class TestAllFormats(HandlerTestCase):
output = FFMPEGHandler(self.tmp_url, output_data, "mp4") output = FFMPEGHandler(self.tmp_url, output_data, "mp4")
input_data = output.convert("ogv") input_data = output.convert("ogv")
input_format = file_detector.from_buffer(input_data) input_format = file_detector.from_buffer(input_data)
self.assertTrue((output_format == 'video/mp4') and self.assertEquals(output_format, 'video/mp4')
(input_format == 'video/ogg')) self.assertEquals(input_format, 'video/ogg')
def testWebMFormat(self): def testWebMFormat(self):
"""Test convert file to WebM format and the reverse convertion""" """Test convert file to WebM format and the reverse convertion"""
...@@ -66,8 +67,8 @@ class TestAllFormats(HandlerTestCase): ...@@ -66,8 +67,8 @@ class TestAllFormats(HandlerTestCase):
output = FFMPEGHandler(self.tmp_url, output_data, "webm") output = FFMPEGHandler(self.tmp_url, output_data, "webm")
input_data = output.convert("ogv") input_data = output.convert("ogv")
input_format = file_detector.from_buffer(input_data) input_format = file_detector.from_buffer(input_data)
self.assertTrue((output_format == 'video/webm') and self.assertEquals(output_format, 'video/webm')
(input_format == 'video/ogg')) self.assertEquals(input_format, 'video/ogg')
def testFlvFormat(self): def testFlvFormat(self):
"""Test convert file to flash format the reverse convertion""" """Test convert file to flash format the reverse convertion"""
...@@ -76,8 +77,8 @@ class TestAllFormats(HandlerTestCase): ...@@ -76,8 +77,8 @@ class TestAllFormats(HandlerTestCase):
output = FFMPEGHandler(self.tmp_url, output_data, "flv") output = FFMPEGHandler(self.tmp_url, output_data, "flv")
input_data = output.convert("ogv") input_data = output.convert("ogv")
input_format = file_detector.from_buffer(input_data) input_format = file_detector.from_buffer(input_data)
self.assertTrue((output_format == 'application/x-shockwave-flash') and self.assertEquals(output_format, 'application/x-shockwave-flash')
(input_format == 'video/ogg')) self.assertEquals(input_format, 'video/ogg')
def testMpegFormat(self): def testMpegFormat(self):
"""Test convert file to Mpeg format the reverse convertion""" """Test convert file to Mpeg format the reverse convertion"""
...@@ -86,8 +87,8 @@ class TestAllFormats(HandlerTestCase): ...@@ -86,8 +87,8 @@ class TestAllFormats(HandlerTestCase):
output = FFMPEGHandler(self.tmp_url, output_data, "mpeg") output = FFMPEGHandler(self.tmp_url, output_data, "mpeg")
input_data = output.convert("ogv") input_data = output.convert("ogv")
input_format = file_detector.from_buffer(input_data) input_format = file_detector.from_buffer(input_data)
self.assertTrue((output_format == 'video/mpeg') and self.assertEquals(output_format, 'video/mpeg')
(input_format == 'video/ogg')) self.assertEquals(input_format, 'video/ogg')
def testMkvFormat(self): def testMkvFormat(self):
"""Test convert file to matroska format the reverse convertion""" """Test convert file to matroska format the reverse convertion"""
...@@ -96,8 +97,8 @@ class TestAllFormats(HandlerTestCase): ...@@ -96,8 +97,8 @@ class TestAllFormats(HandlerTestCase):
output = FFMPEGHandler(self.tmp_url, output_data, "mkv") output = FFMPEGHandler(self.tmp_url, output_data, "mkv")
input_data = output.convert("ogv") input_data = output.convert("ogv")
input_format = file_detector.from_buffer(input_data) input_format = file_detector.from_buffer(input_data)
self.assertTrue((output_format == 'video/x-matroska') and self.assertEquals(output_format, 'video/x-matroska')
(input_format == 'video/ogg')) self.assertEquals(input_format, 'video/ogg')
def testOggFormat(self): def testOggFormat(self):
"""Test convert file to ogg format the reverse convertion""" """Test convert file to ogg format the reverse convertion"""
...@@ -106,8 +107,8 @@ class TestAllFormats(HandlerTestCase): ...@@ -106,8 +107,8 @@ class TestAllFormats(HandlerTestCase):
output = FFMPEGHandler(self.tmp_url, output_data, "ogg") output = FFMPEGHandler(self.tmp_url, output_data, "ogg")
input_data = output.convert("ogv") input_data = output.convert("ogv")
input_format = file_detector.from_buffer(input_data) input_format = file_detector.from_buffer(input_data)
self.assertTrue((output_format == 'aplication/ogg') and self.assertEquals(output_format, 'application/ogg')
(input_format == 'video/ogg')) self.assertEquals(input_format, 'video/ogg')
def test_suite(): def test_suite():
......
...@@ -43,11 +43,11 @@ class TestFFMPEGHandler(HandlerTestCase): ...@@ -43,11 +43,11 @@ class TestFFMPEGHandler(HandlerTestCase):
output_data = self.input.convert("ogg") output_data = self.input.convert("ogg")
file_format = file_detector.from_buffer(output_data) file_format = file_detector.from_buffer(output_data)
self.assertEqual(file_format, 'Ogg data, Theora video') self.assertEqual(file_format, 'Ogg data, Theora video')
def testgetMetadata(self): def testgetMetadata(self):
"""Test if metadata is extracted from""" """Test if metadata is extracted from"""
self.assertRaises(NotImplementedError, self.input.getMetadata) self.assertRaises(NotImplementedError, self.input.getMetadata)
def testsetMetadata(self): def testsetMetadata(self):
""" Test if metadata are inserted correclty """ """ Test if metadata are inserted correclty """
self.assertRaises(NotImplementedError, self.input.setMetadata) self.assertRaises(NotImplementedError, self.input.setMetadata)
......
...@@ -31,6 +31,7 @@ from cloudooo.interfaces.handler import IHandler ...@@ -31,6 +31,7 @@ from cloudooo.interfaces.handler import IHandler
from cloudooo.handler.ffmpeg.handler import FFMPEGHandler from cloudooo.handler.ffmpeg.handler import FFMPEGHandler
from cloudooo.handler.tests.handlerTestCase import make_suite from cloudooo.handler.tests.handlerTestCase import make_suite
class TestInterface(unittest.TestCase): class TestInterface(unittest.TestCase):
"""Test IHandler Interface""" """Test IHandler Interface"""
...@@ -42,8 +43,3 @@ class TestInterface(unittest.TestCase): ...@@ -42,8 +43,3 @@ class TestInterface(unittest.TestCase):
def test_suite(): def test_suite():
return make_suite(TestInterface) return make_suite(TestInterface)
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TestInterface)
unittest.TextTestRunner(verbosity=2).run(suite)
...@@ -42,7 +42,7 @@ class TestServer(HandlerTestCase): ...@@ -42,7 +42,7 @@ class TestServer(HandlerTestCase):
"""Creates a connection with cloudooo server""" """Creates a connection with cloudooo server"""
self.proxy = ServerProxy("http://%s:%s/RPC2" % \ self.proxy = ServerProxy("http://%s:%s/RPC2" % \
(self.hostname, self.cloudooo_port), allow_none=True) (self.hostname, self.cloudooo_port), allow_none=True)
def testConvertPDFtoTxt(self): def testConvertPDFtoTxt(self):
"""Converts ogv video to mpeg format""" """Converts ogv video to mpeg format"""
data = open(join('data', 'test.ogv'), 'r').read() data = open(join('data', 'test.ogv'), 'r').read()
...@@ -52,15 +52,13 @@ class TestServer(HandlerTestCase): ...@@ -52,15 +52,13 @@ class TestServer(HandlerTestCase):
mime = Magic(mime=True) mime = Magic(mime=True)
mimetype = mime.from_buffer(decodestring(video)) mimetype = mime.from_buffer(decodestring(video))
self.assertEquals(mimetype, 'video/mpeg') self.assertEquals(mimetype, 'video/mpeg')
def testGetMetadata(self): def testGetMetadata(self):
"""test if metadata are extracted correctly""" """test if metadata are extracted correctly"""
def testSetMetadata(self): def testSetMetadata(self):
"""Test if metadata is inserted correctly""" """Test if metadata is inserted correctly"""
def test_suite(): def test_suite():
return make_suite(TestServer) return make_suite(TestServer)
...@@ -69,7 +69,7 @@ class ImageMagickHandler(object): ...@@ -69,7 +69,7 @@ class ImageMagickHandler(object):
stdout=PIPE, stdout=PIPE,
stderr=PIPE, stderr=PIPE,
env=self.environment).communicate() env=self.environment).communicate()
metadata_dict = {} metadata_dict = {}
for std in stdout.split("\n"): for std in stdout.split("\n"):
std = std.strip() std = std.strip()
...@@ -86,4 +86,4 @@ class ImageMagickHandler(object): ...@@ -86,4 +86,4 @@ class ImageMagickHandler(object):
Keyword arguments: Keyword arguments:
metadata -- expected an dictionary with metadata. metadata -- expected an dictionary with metadata.
""" """
raise NotImplementedError raise NotImplementedError
...@@ -29,5 +29,6 @@ ...@@ -29,5 +29,6 @@
from cloudooo.handler.tests import runHandlerUnitTest from cloudooo.handler.tests import runHandlerUnitTest
def run(): def run():
runHandlerUnitTest.run("imagemagick") runHandlerUnitTest.run("imagemagick")
...@@ -52,7 +52,7 @@ class TestServer(HandlerTestCase): ...@@ -52,7 +52,7 @@ class TestServer(HandlerTestCase):
mime = Magic(mime=True) mime = Magic(mime=True)
mimetype = mime.from_buffer(decodestring(document)) mimetype = mime.from_buffer(decodestring(document))
self.assertEquals(mimetype, "image/jpeg") self.assertEquals(mimetype, "image/jpeg")
def testGetMetadataFromPNG(self): def testGetMetadataFromPNG(self):
"""test if metadata are extracted correctly""" """test if metadata are extracted correctly"""
data = open(join('data', 'test.png'), 'r').read() data = open(join('data', 'test.png'), 'r').read()
......
...@@ -144,8 +144,8 @@ class OOGranulator(object): ...@@ -144,8 +144,8 @@ class OOGranulator(object):
def getLineItemList(self, table_id): def getLineItemList(self, table_id):
"""Returns the lines of a given table as (key, value) pairs.""" """Returns the lines of a given table as (key, value) pairs."""
row_list = self.document.parsed_content.xpath( row_list = self.document.parsed_content.xpath(
'//table:table[@table:name="%s"]/table:table-row' % table_id, '//table:table[@table:name="%s"]/table:table-row' % table_id,
namespaces=self.document.parsed_content.nsmap) namespaces=self.document.parsed_content.nsmap)
if len(row_list) == 0: if len(row_list) == 0:
return None return None
......
...@@ -29,5 +29,6 @@ ...@@ -29,5 +29,6 @@
from cloudooo.handler.tests import runHandlerUnitTest from cloudooo.handler.tests import runHandlerUnitTest
def run(): def run():
runHandlerUnitTest.run("ooo") runHandlerUnitTest.run("ooo")
...@@ -48,6 +48,7 @@ from cloudooo.interfaces.granulate import ITableGranulator, \ ...@@ -48,6 +48,7 @@ from cloudooo.interfaces.granulate import ITableGranulator, \
ITextGranulator ITextGranulator
from cloudooo.handler.tests.handlerTestCase import make_suite from cloudooo.handler.tests.handlerTestCase import make_suite
class TestInterface(unittest.TestCase): class TestInterface(unittest.TestCase):
"""Test All Interfaces""" """Test All Interfaces"""
...@@ -172,7 +173,3 @@ class TestInterface(unittest.TestCase): ...@@ -172,7 +173,3 @@ class TestInterface(unittest.TestCase):
def test_suite(): def test_suite():
return make_suite(TestInterface) return make_suite(TestInterface)
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TestInterface)
unittest.TextTestRunner(verbosity=2).run(suite)
...@@ -82,7 +82,6 @@ class TestOOGranulator(HandlerTestCase): ...@@ -82,7 +82,6 @@ class TestOOGranulator(HandlerTestCase):
table_data = oogranulator.getTableItem('NonExistentTable') table_data = oogranulator.getTableItem('NonExistentTable')
self.assertEquals(table_data, None) self.assertEquals(table_data, None)
def testGetColumnItemList(self): def testGetColumnItemList(self):
"""Test if getColumnItemList() returns the right table columns list""" """Test if getColumnItemList() returns the right table columns list"""
self.assertRaises(NotImplementedError, self.oogranulator.getColumnItemList, self.assertRaises(NotImplementedError, self.oogranulator.getColumnItemList,
...@@ -180,5 +179,6 @@ class TestOOGranulator(HandlerTestCase): ...@@ -180,5 +179,6 @@ class TestOOGranulator(HandlerTestCase):
self.assertRaises(NotImplementedError, self.oogranulator.getChapterItem, self.assertRaises(NotImplementedError, self.oogranulator.getChapterItem,
'chapter_id') 'chapter_id')
def test_suite(): def test_suite():
return make_suite(TestOOGranulator) return make_suite(TestOOGranulator)
...@@ -591,7 +591,7 @@ class TestServer(HandlerTestCase): ...@@ -591,7 +591,7 @@ class TestServer(HandlerTestCase):
'P5'], [15, 'P5'], [16, 'P14'], [17, 'P11'], [18, 'P11'], 'P5'], [15, 'P5'], [16, 'P14'], [17, 'P11'], [18, 'P11'],
[19, 'Standard'], [20, 'P2'], [21, 'P2'], [22, 'P2'], [19, 'Standard'], [20, 'P2'], [21, 'P2'], [22, 'P2'],
[23, 'P2'], [24, 'P2'], [25, 'P2'], [26, 'P2'], [27, [23, 'P2'], [24, 'P2'], [25, 'P2'], [26, 'P2'], [27,
'P2'], [28, 'P2'], [29, 'P2']],paragraph_list) 'P2'], [28, 'P2'], [29, 'P2']], paragraph_list)
def testGetParagraphItem(self): def testGetParagraphItem(self):
"""Test if manager can get a paragraph""" """Test if manager can get a paragraph"""
...@@ -612,5 +612,6 @@ class TestServer(HandlerTestCase): ...@@ -612,5 +612,6 @@ class TestServer(HandlerTestCase):
self.assertRaises(Fault, self.proxy.getChapterItem, ("id", data, "odt")) self.assertRaises(Fault, self.proxy.getChapterItem, ("id", data, "odt"))
def test_suite(): def test_suite():
return make_suite(TestServer) return make_suite(TestServer)
...@@ -33,6 +33,7 @@ from cloudooo.utils.utils import logger, configureLogger, \ ...@@ -33,6 +33,7 @@ from cloudooo.utils.utils import logger, configureLogger, \
from cloudooo.handler.tests.handlerTestCase import make_suite from cloudooo.handler.tests.handlerTestCase import make_suite
import mimetypes import mimetypes
class TestUtils(unittest.TestCase): class TestUtils(unittest.TestCase):
"""Test Utils""" """Test Utils"""
......
...@@ -52,7 +52,7 @@ class TestServer(HandlerTestCase): ...@@ -52,7 +52,7 @@ class TestServer(HandlerTestCase):
mime = Magic(mime=True) mime = Magic(mime=True)
mimetype = mime.from_buffer(decodestring(document)) mimetype = mime.from_buffer(decodestring(document))
self.assertEquals(mimetype, "text/plain") self.assertEquals(mimetype, "text/plain")
def testGetMetadataFromPdf(self): def testGetMetadataFromPdf(self):
"""test if metadata are extracted correctly""" """test if metadata are extracted correctly"""
data = open(join('data', 'test.pdf'), 'r').read() data = open(join('data', 'test.pdf'), 'r').read()
......
...@@ -43,6 +43,7 @@ def make_suite(test_case): ...@@ -43,6 +43,7 @@ def make_suite(test_case):
suite.addTest(unittest.makeSuite(test_case)) suite.addTest(unittest.makeSuite(test_case))
return suite return suite
def check_folder(working_path, tmp_dir_path): def check_folder(working_path, tmp_dir_path):
if not path.exists(working_path): if not path.exists(working_path):
mkdir(working_path) mkdir(working_path)
...@@ -102,6 +103,7 @@ def stopFakeEnvironment(stop_openoffice=True): ...@@ -102,6 +103,7 @@ def stopFakeEnvironment(stop_openoffice=True):
openoffice.stop() openoffice.stop()
return True return True
class HandlerTestCase(unittest.TestCase): class HandlerTestCase(unittest.TestCase):
"""Test Case to load cloudooo conf.""" """Test Case to load cloudooo conf."""
......
...@@ -54,7 +54,8 @@ class IImageGranulator(Interface): ...@@ -54,7 +54,8 @@ class IImageGranulator(Interface):
def getImageItemList(data, source_format): def getImageItemList(data, source_format):
"""Return the list of images in the form of (id, title).""" """Return the list of images in the form of (id, title)."""
def getImage(data, image_id, source_format, format=None, resolution=None, **kw): def getImage(data, image_id, source_format,
format=None, resolution=None, **kw):
"""Return the given image.""" """Return the given image."""
......
...@@ -52,7 +52,7 @@ def getHandlerObject(source_format, destination_format, mimetype_registry): ...@@ -52,7 +52,7 @@ def getHandlerObject(source_format, destination_format, mimetype_registry):
registry_list = pattern.split() registry_list = pattern.split()
if fnmatch(source_mimetype, registry_list[0]) and \ if fnmatch(source_mimetype, registry_list[0]) and \
(fnmatch(destination_mimetype, registry_list[1]) or destination_format is None): (fnmatch(destination_mimetype, registry_list[1]) or destination_format is None):
handler_name = "cloudooo.handler.%s.handler" % registry_list[2] handler_name = "cloudooo.handler.%s.handler" % registry_list[2]
__import__(handler_name) __import__(handler_name)
handler = sys.modules[handler_name] handler = sys.modules[handler_name]
# XXX - Ugly and slow way to find the Handler Object # XXX - Ugly and slow way to find the Handler Object
...@@ -70,7 +70,6 @@ class Manager(object): ...@@ -70,7 +70,6 @@ class Manager(object):
implements(IManager, IERP5Compatibility, ITableGranulator, IImageGranulator, implements(IManager, IERP5Compatibility, ITableGranulator, IImageGranulator,
ITextGranulator) ITextGranulator)
def __init__(self, path_tmp_dir, **kw): def __init__(self, path_tmp_dir, **kw):
"""Need pass the path where the temporary document will be created.""" """Need pass the path where the temporary document will be created."""
self._path_tmp_dir = path_tmp_dir self._path_tmp_dir = path_tmp_dir
......
...@@ -51,7 +51,7 @@ PYTHON_ENVIRONMENT = [ ...@@ -51,7 +51,7 @@ PYTHON_ENVIRONMENT = [
def loadMimetypeList(): def loadMimetypeList():
mime_types_url = pkg_resources.resource_filename("cloudooo", mime_types_url = pkg_resources.resource_filename("cloudooo",
"mime.types") "mime.types")
mimetypes.init(files=[mime_types_url,]) mimetypes.init(files=[mime_types_url, ])
def configureLogger(level=None, debug_mode=False): def configureLogger(level=None, debug_mode=False):
......
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