pep8 fixes

This commit is contained in:
Tomas Groth 2014-07-11 15:35:44 +02:00
parent 52f298fdc1
commit 98a58d45bf
13 changed files with 41 additions and 43 deletions

View File

@ -434,7 +434,7 @@ class ServiceItem(RegistryProperties):
if path:
self.has_original_files = False
self.add_from_command(path, text_image['title'], text_image['image'],
text_image.get('display_title',''), text_image.get('notes', ''))
text_image.get('display_title', ''), text_image.get('notes', ''))
else:
self.add_from_command(text_image['path'], text_image['title'], text_image['image'])
self._new_item()

View File

@ -431,6 +431,7 @@ class PowerpointDocument(PresentationDocument):
'and the presentation will be stopped. '
'Restart the presentation if you wish to present it.'))
def _get_text_from_shapes(shapes):
"""
Returns any text extracted from the shapes on a presentation slide.
@ -447,6 +448,7 @@ def _get_text_from_shapes(shapes):
if os.name == "nt":
try:
ppE = win32com.client.getevents("PowerPoint.Application")
class PowerpointEvents(ppE):
def OnSlideShowBegin(self, hwnd):
#print("SS Begin")
@ -470,4 +472,3 @@ if os.name == "nt":
return
except pywintypes.com_error:
log.debug('COM error trying to get powerpoint events - powerpoint is probably not installed.')

View File

@ -296,8 +296,7 @@ class PresentationDocument(object):
def get_titles_and_notes(self):
"""
Reads the titles from the titles file and
the notes files and returns the contents
in a two lists
the notes files and returns the content in two lists
"""
titles = []
notes = []
@ -337,6 +336,7 @@ class PresentationDocument(object):
with open(notes_file, mode='w') as fn:
fn.write(note)
class PresentationController(object):
"""
This class is used to control interactions with presentation applications by creating a runtime environment.
@ -471,6 +471,7 @@ class PresentationController(object):
def close_presentation(self):
pass
class TextType(object):
"""
Type Enumeration for Types of Text to request
@ -478,4 +479,3 @@ class TextType(object):
Title = 0
SlideText = 1
Notes = 2

View File

@ -32,4 +32,4 @@ from .httprouter import HttpRouter
from .httpserver import OpenLPServer
from .websocket import WebSocketManager
__all__ = ['RemoteTab', 'OpenLPServer', 'HttpRouter','WebSocketManager']
__all__ = ['RemoteTab', 'OpenLPServer', 'HttpRouter', 'WebSocketManager']

View File

@ -627,4 +627,3 @@ class HttpRouter(RegistryProperties):
item_id = plugin.media_item.create_item_from_id(request_id)
plugin.media_item.emit(QtCore.SIGNAL('%s_add_to_service' % plugin_name), [item_id, True])
self.do_http_success()

View File

@ -162,9 +162,9 @@ class TestAppLocation(TestCase):
patch('openlp.core.common.applocation.os.path.abspath') as mocked_abspath, \
patch('openlp.core.common.applocation.os.path.split') as mocked_split, \
patch('openlp.core.common.applocation.sys') as mocked_sys:
mocked_abspath.return_value = os.path.join('plugins','dir')
mocked_abspath.return_value = os.path.join('plugins', 'dir')
mocked_split.return_value = ['openlp']
mocked_get_frozen_path.return_value = os.path.join('plugins','dir')
mocked_get_frozen_path.return_value = os.path.join('plugins', 'dir')
mocked_sys.frozen = 1
mocked_sys.argv = ['openlp']
@ -172,7 +172,7 @@ class TestAppLocation(TestCase):
directory = AppLocation.get_directory(AppLocation.PluginsDir)
# THEN: The correct directory should be returned
self.assertEqual(os.path.join('plugins','dir'), directory, 'Directory should be "plugins/dir"')
self.assertEqual(os.path.join('plugins', 'dir'), directory, 'Directory should be "plugins/dir"')
def get_frozen_path_in_unfrozen_app_test(self):
"""

View File

@ -37,6 +37,7 @@ from openlp.plugins.presentations.lib.impresscontroller import \
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources'))
class TestLibModule(TestCase):
def setUp(self):

View File

@ -41,7 +41,7 @@ from tests.helpers.testmixin import TestMixin
from tests.utils.constants import TEST_RESOURCES_PATH
from openlp.plugins.presentations.lib.powerpointcontroller import PowerpointController, PowerpointDocument,\
_get_text_from_shapes
_get_text_from_shapes
class TestPowerpointController(TestCase, TestMixin):

View File

@ -40,6 +40,7 @@ from openlp.plugins.presentations.lib.pptviewcontroller import PptviewController
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources'))
class TestLibModule(TestCase):
def setUp(self):
@ -134,8 +135,8 @@ class TestLibModule(TestCase):
"""
# GIVEN: mocked PresentationController.save_titles_and_notes and an invalid file
with patch('builtins.open', mock_open(read_data='this is a test')) as mocked_open, \
patch('openlp.plugins.presentations.lib.pptviewcontroller.os.path.exists') as mocked_exists, \
patch('openlp.plugins.presentations.lib.pptviewcontroller.zipfile.is_zipfile') as mocked_is_zf:
patch('openlp.plugins.presentations.lib.pptviewcontroller.os.path.exists') as mocked_exists, \
patch('openlp.plugins.presentations.lib.pptviewcontroller.zipfile.is_zipfile') as mocked_is_zf:
mocked_is_zf.return_value = False
mocked_exists.return_value = True
mocked_open.filesize = 10
@ -148,4 +149,3 @@ class TestLibModule(TestCase):
# THEN:
self.doc.save_titles_and_notes.assert_called_once_with(None, None)
self.assertEqual(mocked_is_zf.call_count, 1, 'is_zipfile should have been called once')

View File

@ -37,18 +37,17 @@ from tests.functional import MagicMock, patch, mock_open
FOLDER_TO_PATCH = 'openlp.plugins.presentations.lib.presentationcontroller.PresentationDocument.get_thumbnail_folder'
class TestPresentationController(TestCase):
"""
Test the PresentationController.
"""
def setUp(self):
mocked_plugin = MagicMock()
mocked_plugin.settings_section = 'presentations'
self.presentation = PresentationController(mocked_plugin)
self.document = PresentationDocument(self.presentation, '')
def constructor_test(self):
"""
Test the Constructor
@ -100,7 +99,6 @@ class TestPresentationController(TestCase):
# THEN: No file should have been created
self.assertEqual(mocked_open.call_count, 0, 'No file should be created')
def get_titles_and_notes_test(self):
"""
Test PresentationDocument.get_titles_and_notes method
@ -108,8 +106,8 @@ class TestPresentationController(TestCase):
# GIVEN: A mocked open, get_thumbnail_folder and exists
with patch('builtins.open', mock_open(read_data='uno\ndos\n')) as mocked_open, \
patch(FOLDER_TO_PATCH) as mocked_get_thumbnail_folder, \
patch('openlp.plugins.presentations.lib.presentationcontroller.os.path.exists') as mocked_exists:
patch(FOLDER_TO_PATCH) as mocked_get_thumbnail_folder, \
patch('openlp.plugins.presentations.lib.presentationcontroller.os.path.exists') as mocked_exists:
mocked_get_thumbnail_folder.return_value = 'test'
mocked_exists.return_value = True
@ -133,8 +131,8 @@ class TestPresentationController(TestCase):
"""
# GIVEN: A mocked open, get_thumbnail_folder and exists
with patch('builtins.open') as mocked_open, \
patch(FOLDER_TO_PATCH) as mocked_get_thumbnail_folder, \
patch('openlp.plugins.presentations.lib.presentationcontroller.os.path.exists') as mocked_exists:
patch(FOLDER_TO_PATCH) as mocked_get_thumbnail_folder, \
patch('openlp.plugins.presentations.lib.presentationcontroller.os.path.exists') as mocked_exists:
mocked_get_thumbnail_folder.return_value = 'test'
mocked_exists.return_value = False
@ -155,8 +153,8 @@ class TestPresentationController(TestCase):
"""
# GIVEN: A mocked open, get_thumbnail_folder and exists
with patch('builtins.open') as mocked_open, \
patch(FOLDER_TO_PATCH) as mocked_get_thumbnail_folder, \
patch('openlp.plugins.presentations.lib.presentationcontroller.os.path.exists') as mocked_exists:
patch(FOLDER_TO_PATCH) as mocked_get_thumbnail_folder, \
patch('openlp.plugins.presentations.lib.presentationcontroller.os.path.exists') as mocked_exists:
mocked_get_thumbnail_folder.return_value = 'test'
mocked_exists.return_value = True
mocked_open.side_effect = IOError()
@ -166,4 +164,3 @@ class TestPresentationController(TestCase):
# THEN: it should return two empty lists
self.assertIs(type(result_titles), list, 'result_titles should be a list')

View File

@ -178,7 +178,7 @@ class TestRouter(TestCase, TestMixin):
self.router.html_dir = os.path.normpath('test/dir')
self.router.template_vars = MagicMock()
with patch('openlp.core.lib.os.path.exists') as mocked_exists, \
patch('builtins.open', mock_open(read_data='123')):
patch('builtins.open', mock_open(read_data='123')):
mocked_exists.return_value = True
# WHEN: call serve_file with an existing html file
@ -248,13 +248,13 @@ class TestRouter(TestCase, TestMixin):
Registry.create()
Registry().register('image_manager', mocked_image_manager)
file_name = 'another%20test/slide1.png'
full_path = os.path.normpath(os.path.join('thumbnails',file_name))
full_path = os.path.normpath(os.path.join('thumbnails', file_name))
width = 120
height = 90
with patch('openlp.core.lib.os.path.exists') as mocked_exists, \
patch('builtins.open', mock_open(read_data='123')), \
patch('openlp.plugins.remotes.lib.httprouter.AppLocation') as mocked_location, \
patch('openlp.plugins.remotes.lib.httprouter.image_to_byte') as mocked_image_to_byte:
patch('builtins.open', mock_open(read_data='123')), \
patch('openlp.plugins.remotes.lib.httprouter.AppLocation') as mocked_location, \
patch('openlp.plugins.remotes.lib.httprouter.image_to_byte') as mocked_image_to_byte:
mocked_exists.return_value = True
mocked_image_to_byte.return_value = '123'
mocked_location.get_section_data_path.return_value = ''