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: if path:
self.has_original_files = False self.has_original_files = False
self.add_from_command(path, text_image['title'], text_image['image'], 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: else:
self.add_from_command(text_image['path'], text_image['title'], text_image['image']) self.add_from_command(text_image['path'], text_image['title'], text_image['image'])
self._new_item() self._new_item()

View File

@ -477,8 +477,8 @@ class ImpressDocument(PresentationDocument):
def create_titles_and_notes(self): def create_titles_and_notes(self):
""" """
Writes the list of titles (one per slide) Writes the list of titles (one per slide)
to 'titles.txt' to 'titles.txt'
and the notes to 'slideNotes[x].txt' and the notes to 'slideNotes[x].txt'
in the thumbnails directory in the thumbnails directory
""" """

View File

@ -400,8 +400,8 @@ class PowerpointDocument(PresentationDocument):
def create_titles_and_notes(self): def create_titles_and_notes(self):
""" """
Writes the list of titles (one per slide) Writes the list of titles (one per slide)
to 'titles.txt' to 'titles.txt'
and the notes to 'slideNotes[x].txt' and the notes to 'slideNotes[x].txt'
in the thumbnails directory in the thumbnails directory
""" """
@ -431,6 +431,7 @@ class PowerpointDocument(PresentationDocument):
'and the presentation will be stopped. ' 'and the presentation will be stopped. '
'Restart the presentation if you wish to present it.')) 'Restart the presentation if you wish to present it.'))
def _get_text_from_shapes(shapes): def _get_text_from_shapes(shapes):
""" """
Returns any text extracted from the shapes on a presentation slide. 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": if os.name == "nt":
try: try:
ppE = win32com.client.getevents("PowerPoint.Application") ppE = win32com.client.getevents("PowerPoint.Application")
class PowerpointEvents(ppE): class PowerpointEvents(ppE):
def OnSlideShowBegin(self, hwnd): def OnSlideShowBegin(self, hwnd):
#print("SS Begin") #print("SS Begin")
@ -470,4 +472,3 @@ if os.name == "nt":
return return
except pywintypes.com_error: except pywintypes.com_error:
log.debug('COM error trying to get powerpoint events - powerpoint is probably not installed.') log.debug('COM error trying to get powerpoint events - powerpoint is probably not installed.')

View File

@ -160,8 +160,8 @@ class PptviewDocument(PresentationDocument):
def create_titles_and_notes(self): def create_titles_and_notes(self):
""" """
Extracts the titles and notes from the zipped file Extracts the titles and notes from the zipped file
and writes the list of titles (one per slide) and writes the list of titles (one per slide)
to 'titles.txt' to 'titles.txt'
and the notes to 'slideNotes[x].txt' and the notes to 'slideNotes[x].txt'
in the thumbnails directory in the thumbnails directory
""" """
@ -210,9 +210,9 @@ class PptviewDocument(PresentationDocument):
if nodes and len(nodes) > 0: if nodes and len(nodes) > 0:
for node in nodes: for node in nodes:
if len(text) > 0: if len(text) > 0:
text += '\n' text += '\n'
text += node.text text += node.text
# Let's remove the \n from the titles and # Let's remove the \n from the titles and
# just add one at the end # just add one at the end
if node_type == 'ctrTitle': if node_type == 'ctrTitle':
text = text.replace('\n', ' ').replace('\x0b', ' ') + '\n' text = text.replace('\n', ' ').replace('\x0b', ' ') + '\n'

View File

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

View File

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

View File

@ -503,7 +503,7 @@ class HttpRouter(RegistryProperties):
if current_item.is_capable(ItemCapabilities.HasNotes): if current_item.is_capable(ItemCapabilities.HasNotes):
item['notes'] = str(frame['notes']) item['notes'] = str(frame['notes'])
if current_item.is_capable(ItemCapabilities.HasThumbnails): if current_item.is_capable(ItemCapabilities.HasThumbnails):
# If the file is under our app directory tree send the # If the file is under our app directory tree send the
# portion after the match # portion after the match
data_path = AppLocation.get_data_path() data_path = AppLocation.get_data_path()
if frame['image'][0:len(data_path)] == data_path: if frame['image'][0:len(data_path)] == data_path:
@ -627,4 +627,3 @@ class HttpRouter(RegistryProperties):
item_id = plugin.media_item.create_item_from_id(request_id) 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]) plugin.media_item.emit(QtCore.SIGNAL('%s_add_to_service' % plugin_name), [item_id, True])
self.do_http_success() 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.abspath') as mocked_abspath, \
patch('openlp.core.common.applocation.os.path.split') as mocked_split, \ patch('openlp.core.common.applocation.os.path.split') as mocked_split, \
patch('openlp.core.common.applocation.sys') as mocked_sys: 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_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.frozen = 1
mocked_sys.argv = ['openlp'] mocked_sys.argv = ['openlp']
@ -172,7 +172,7 @@ class TestAppLocation(TestCase):
directory = AppLocation.get_directory(AppLocation.PluginsDir) directory = AppLocation.get_directory(AppLocation.PluginsDir)
# THEN: The correct directory should be returned # 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): 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')) TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources'))
class TestLibModule(TestCase): class TestLibModule(TestCase):
def setUp(self): def setUp(self):

View File

@ -41,7 +41,7 @@ from tests.helpers.testmixin import TestMixin
from tests.utils.constants import TEST_RESOURCES_PATH from tests.utils.constants import TEST_RESOURCES_PATH
from openlp.plugins.presentations.lib.powerpointcontroller import PowerpointController, PowerpointDocument,\ from openlp.plugins.presentations.lib.powerpointcontroller import PowerpointController, PowerpointDocument,\
_get_text_from_shapes _get_text_from_shapes
class TestPowerpointController(TestCase, TestMixin): class TestPowerpointController(TestCase, TestMixin):
@ -205,7 +205,7 @@ class TestPowerpointDocument(TestCase, TestMixin):
def get_text_from_shapes_test(self): def get_text_from_shapes_test(self):
""" """
Test getting text from powerpoint shapes Test getting text from powerpoint shapes
""" """
# GIVEN: mocked shapes # GIVEN: mocked shapes
shape = MagicMock() shape = MagicMock()

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')) TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources'))
class TestLibModule(TestCase): class TestLibModule(TestCase):
def setUp(self): def setUp(self):
@ -65,7 +66,7 @@ class TestLibModule(TestCase):
def verify_loading_document(self): def verify_loading_document(self):
""" """
Test loading a document in PowerpointViewer Test loading a document in PowerpointViewer
""" """
# GIVEN: the filename # GIVEN: the filename
print(self.file_name) print(self.file_name)
# WHEN: loading the filename # WHEN: loading the filename
@ -95,7 +96,7 @@ class TestLibModule(TestCase):
""" """
Test PowerpointController.create_titles_and_notes Test PowerpointController.create_titles_and_notes
""" """
# GIVEN: mocked PresentationController.save_titles_and_notes # GIVEN: mocked PresentationController.save_titles_and_notes
self.doc.save_titles_and_notes = MagicMock() self.doc.save_titles_and_notes = MagicMock()
# WHEN reading the titles and notes # WHEN reading the titles and notes
@ -127,15 +128,15 @@ class TestLibModule(TestCase):
self.doc.save_titles_and_notes.assert_called_once_with(None, None) self.doc.save_titles_and_notes.assert_called_once_with(None, None)
mocked_exists.assert_any_call('Idontexist.pptx') mocked_exists.assert_any_call('Idontexist.pptx')
self.assertEqual(mocked_open.call_count, 0, 'There should be no calls to open a file') self.assertEqual(mocked_open.call_count, 0, 'There should be no calls to open a file')
def create_titles_and_notes_invalid_file_test(self): def create_titles_and_notes_invalid_file_test(self):
""" """
Test PowerpointController.create_titles_and_notes with invalid file Test PowerpointController.create_titles_and_notes with invalid file
""" """
# GIVEN: mocked PresentationController.save_titles_and_notes and an invalid file # 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, \ 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.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.zipfile.is_zipfile') as mocked_is_zf:
mocked_is_zf.return_value = False mocked_is_zf.return_value = False
mocked_exists.return_value = True mocked_exists.return_value = True
mocked_open.filesize = 10 mocked_open.filesize = 10
@ -148,4 +149,3 @@ class TestLibModule(TestCase):
# THEN: # THEN:
self.doc.save_titles_and_notes.assert_called_once_with(None, None) 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') 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' FOLDER_TO_PATCH = 'openlp.plugins.presentations.lib.presentationcontroller.PresentationDocument.get_thumbnail_folder'
class TestPresentationController(TestCase): class TestPresentationController(TestCase):
""" """
Test the PresentationController. Test the PresentationController.
""" """
def setUp(self): def setUp(self):
mocked_plugin = MagicMock() mocked_plugin = MagicMock()
mocked_plugin.settings_section = 'presentations' mocked_plugin.settings_section = 'presentations'
self.presentation = PresentationController(mocked_plugin) self.presentation = PresentationController(mocked_plugin)
self.document = PresentationDocument(self.presentation, '') self.document = PresentationDocument(self.presentation, '')
def constructor_test(self): def constructor_test(self):
""" """
Test the Constructor Test the Constructor
@ -100,7 +99,6 @@ class TestPresentationController(TestCase):
# THEN: No file should have been created # THEN: No file should have been created
self.assertEqual(mocked_open.call_count, 0, 'No file should be created') self.assertEqual(mocked_open.call_count, 0, 'No file should be created')
def get_titles_and_notes_test(self): def get_titles_and_notes_test(self):
""" """
Test PresentationDocument.get_titles_and_notes method Test PresentationDocument.get_titles_and_notes method
@ -108,8 +106,8 @@ class TestPresentationController(TestCase):
# GIVEN: A mocked open, get_thumbnail_folder and exists # GIVEN: A mocked open, get_thumbnail_folder and exists
with patch('builtins.open', mock_open(read_data='uno\ndos\n')) as mocked_open, \ with patch('builtins.open', mock_open(read_data='uno\ndos\n')) as mocked_open, \
patch(FOLDER_TO_PATCH) as mocked_get_thumbnail_folder, \ patch(FOLDER_TO_PATCH) as mocked_get_thumbnail_folder, \
patch('openlp.plugins.presentations.lib.presentationcontroller.os.path.exists') as mocked_exists: patch('openlp.plugins.presentations.lib.presentationcontroller.os.path.exists') as mocked_exists:
mocked_get_thumbnail_folder.return_value = 'test' mocked_get_thumbnail_folder.return_value = 'test'
mocked_exists.return_value = True mocked_exists.return_value = True
@ -133,8 +131,8 @@ class TestPresentationController(TestCase):
""" """
# GIVEN: A mocked open, get_thumbnail_folder and exists # GIVEN: A mocked open, get_thumbnail_folder and exists
with patch('builtins.open') as mocked_open, \ with patch('builtins.open') as mocked_open, \
patch(FOLDER_TO_PATCH) as mocked_get_thumbnail_folder, \ patch(FOLDER_TO_PATCH) as mocked_get_thumbnail_folder, \
patch('openlp.plugins.presentations.lib.presentationcontroller.os.path.exists') as mocked_exists: patch('openlp.plugins.presentations.lib.presentationcontroller.os.path.exists') as mocked_exists:
mocked_get_thumbnail_folder.return_value = 'test' mocked_get_thumbnail_folder.return_value = 'test'
mocked_exists.return_value = False mocked_exists.return_value = False
@ -155,8 +153,8 @@ class TestPresentationController(TestCase):
""" """
# GIVEN: A mocked open, get_thumbnail_folder and exists # GIVEN: A mocked open, get_thumbnail_folder and exists
with patch('builtins.open') as mocked_open, \ with patch('builtins.open') as mocked_open, \
patch(FOLDER_TO_PATCH) as mocked_get_thumbnail_folder, \ patch(FOLDER_TO_PATCH) as mocked_get_thumbnail_folder, \
patch('openlp.plugins.presentations.lib.presentationcontroller.os.path.exists') as mocked_exists: patch('openlp.plugins.presentations.lib.presentationcontroller.os.path.exists') as mocked_exists:
mocked_get_thumbnail_folder.return_value = 'test' mocked_get_thumbnail_folder.return_value = 'test'
mocked_exists.return_value = True mocked_exists.return_value = True
mocked_open.side_effect = IOError() mocked_open.side_effect = IOError()
@ -166,4 +164,3 @@ class TestPresentationController(TestCase):
# THEN: it should return two empty lists # THEN: it should return two empty lists
self.assertIs(type(result_titles), list, 'result_titles should be a list') 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.html_dir = os.path.normpath('test/dir')
self.router.template_vars = MagicMock() self.router.template_vars = MagicMock()
with patch('openlp.core.lib.os.path.exists') as mocked_exists, \ 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 mocked_exists.return_value = True
# WHEN: call serve_file with an existing html file # WHEN: call serve_file with an existing html file
@ -248,13 +248,13 @@ class TestRouter(TestCase, TestMixin):
Registry.create() Registry.create()
Registry().register('image_manager', mocked_image_manager) Registry().register('image_manager', mocked_image_manager)
file_name = 'another%20test/slide1.png' 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 width = 120
height = 90 height = 90
with patch('openlp.core.lib.os.path.exists') as mocked_exists, \ 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')), \
patch('openlp.plugins.remotes.lib.httprouter.AppLocation') as mocked_location, \ 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('openlp.plugins.remotes.lib.httprouter.image_to_byte') as mocked_image_to_byte:
mocked_exists.return_value = True mocked_exists.return_value = True
mocked_image_to_byte.return_value = '123' mocked_image_to_byte.return_value = '123'
mocked_location.get_section_data_path.return_value = '' mocked_location.get_section_data_path.return_value = ''