Fix various tests and broken code revealed by tests

This commit is contained in:
Jeffrey S. Smith 2013-09-09 16:10:40 -05:00
parent 02b7f232bc
commit 334cef478d
7 changed files with 13 additions and 9 deletions

View File

@ -88,9 +88,9 @@ class StartTimeForm(QtGui.QDialog, Ui_StartTimeDialog):
"""
Split time up into hours minutes and seconds from secongs
"""
hours = seconds / 3600
hours = seconds // 3600
seconds -= 3600 * hours
minutes = seconds / 60
minutes = seconds // 60
seconds -= 60 * minutes
return hours, minutes, seconds

View File

@ -256,7 +256,7 @@ def is_not_image_file(file_name):
if not file_name:
return True
else:
formats = [str(fmt).lower() for fmt in QtGui.QImageReader.supportedImageFormats()]
formats = [bytes(fmt).decode().lower() for fmt in QtGui.QImageReader.supportedImageFormats()]
file_part, file_extension = os.path.splitext(str(file_name))
if file_extension[1:].lower() in formats and os.path.exists(file_name):
return False

View File

@ -717,7 +717,7 @@ def get_soup_for_bible_ref(reference_url, header=None, pre_parse_regex=None, pre
return None
page_source = page.read()
if pre_parse_regex and pre_parse_substitute is not None:
page_source = re.sub(pre_parse_regex, pre_parse_substitute, page_source)
page_source = re.sub(pre_parse_regex, pre_parse_substitute, page_source.decode())
soup = None
try:
soup = BeautifulSoup(page_source)

View File

@ -187,7 +187,7 @@ class TestLib(TestCase):
"""
Test the get_text_file_string() method when a read error happens
"""
with patch('openlp.core.lib.os.path.isfile') as mocked_isfile, patch('builtins.open') as mocked_open:
with patch('openlp.core.lib.os.path.isfile') as mocked_isfile, patch('openlp.core.lib.open', create=True) as mocked_open:
# GIVEN: A mocked-out open() which raises an exception and isfile returns True
filename = 'testfile.txt'
mocked_isfile.return_value = True
@ -252,7 +252,7 @@ class TestLib(TestCase):
# GIVEN: A set of mocked-out Qt classes
mocked_byte_array = MagicMock()
MockedQtCore.QByteArray.return_value = mocked_byte_array
mocked_byte_array.toBase64.return_value = 'base64mock'
mocked_byte_array.toBase64.return_value = QtCore.QByteArray('base64mock')
mocked_buffer = MagicMock()
MockedQtCore.QBuffer.return_value = mocked_buffer
MockedQtCore.QIODevice.WriteOnly = 'writeonly'

View File

@ -8,6 +8,8 @@ from mock import patch
from openlp.core.utils import clean_filename, get_filesystem_encoding, _get_frozen_path, get_locale_key, \
get_natural_key, split_filename
import os
class TestUtils(TestCase):
"""
@ -120,6 +122,8 @@ class TestUtils(TestCase):
# THEN: We get a properly sorted list
test_passes = sorted(unsorted_list, key=get_locale_key) == ['Aushang', '\u00C4u\u00DFerung', 'Auszug']
assert test_passes, 'Strings should be sorted properly'
if os.name != 'nt':
del get_locale_key_windows_test
def get_locale_key_linux_test(self):

View File

@ -43,7 +43,7 @@ class TestBibleHTTP(TestCase):
results = handler.get_bible_chapter('NIV', 'John', 3)
# THEN: We should get back a valid service item
assert len(results.verselist) == 36, 'The book of John should not have had any verses added or removed'
assert len(results.verse_list) == 36, 'The book of John should not have had any verses added or removed'
def crosswalk_extract_books_test(self):
"""
@ -69,5 +69,5 @@ class TestBibleHTTP(TestCase):
results = handler.get_bible_chapter('niv', 'john', 3)
# THEN: We should get back a valid service item
assert len(results.verselist) == 36, 'The book of John should not have had any verses added or removed'
assert len(results.verse_list) == 36, 'The book of John should not have had any verses added or removed'

View File

@ -9,7 +9,7 @@ from mock import MagicMock
import urllib.request, urllib.error, urllib.parse
import cherrypy
from BeautifulSoup import BeautifulSoup
from bs4 import BeautifulSoup
from openlp.core.lib import Settings
from openlp.plugins.remotes.lib.httpserver import HttpServer