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