1 more done

This commit is contained in:
Tim Bentley 2017-12-17 15:35:35 +00:00
parent fbaeca26f2
commit 9f735e0cc5
4 changed files with 97 additions and 106 deletions

View File

@ -42,4 +42,4 @@ class TestValidationError(TestCase):
# THEN: Then calling str on the error should return the correct text and it should be an instance of `Exception` # THEN: Then calling str on the error should return the correct text and it should be an instance of `Exception`
assert str(error) == 'Test ValidationError' assert str(error) == 'Test ValidationError'
assert isinstance(error, Exception) assert isinstance(error, Exception) is True

View File

@ -309,7 +309,7 @@ class Htmbuilder(TestCase, TestMixin):
html = build_html(item, screen, is_live, background, plugins=plugins) html = build_html(item, screen, is_live, background, plugins=plugins)
# THEN: The returned html should match. # THEN: The returned html should match.
self.assertEqual(html, HTML, 'The returned html should match') assert html == HTML, 'The returned html should match'
def test_build_background_css_radial(self): def test_build_background_css_radial(self):
""" """
@ -325,7 +325,7 @@ class Htmbuilder(TestCase, TestMixin):
css = build_background_css(item, width) css = build_background_css(item, width)
# THEN: The returned css should match. # THEN: The returned css should match.
self.assertEqual(BACKGROUND_CSS_RADIAL, css, 'The background css should be equal.') assert BACKGROUND_CSS_RADIAL == css, 'The background css should be equal.'
def test_build_lyrics_css(self): def test_build_lyrics_css(self):
""" """
@ -346,7 +346,7 @@ class Htmbuilder(TestCase, TestMixin):
css = build_lyrics_css(item) css = build_lyrics_css(item)
# THEN: The css should be equal. # THEN: The css should be equal.
self.assertEqual(LYRICS_CSS, css, 'The lyrics css should be equal.') assert LYRICS_CSS == css, 'The lyrics css should be equal.'
def test_build_lyrics_outline_css(self): def test_build_lyrics_outline_css(self):
""" """
@ -363,7 +363,7 @@ class Htmbuilder(TestCase, TestMixin):
css = build_lyrics_outline_css(theme_data) css = build_lyrics_outline_css(theme_data)
# THEN: The css should be equal. # THEN: The css should be equal.
self.assertEqual(LYRICS_OUTLINE_CSS, css, 'The outline css should be equal.') assert LYRICS_OUTLINE_CSS == css, 'The outline css should be equal.'
def test_build_lyrics_format_css(self): def test_build_lyrics_format_css(self):
""" """
@ -386,7 +386,7 @@ class Htmbuilder(TestCase, TestMixin):
css = build_lyrics_format_css(theme_data, width, height) css = build_lyrics_format_css(theme_data, width, height)
# THEN: They should be equal. # THEN: They should be equal.
self.assertEqual(LYRICS_FORMAT_CSS, css, 'The lyrics format css should be equal.') assert LYRICS_FORMAT_CSS == css, 'The lyrics format css should be equal.'
def test_build_footer_css(self): def test_build_footer_css(self):
""" """
@ -404,7 +404,7 @@ class Htmbuilder(TestCase, TestMixin):
css = build_footer_css(item, height) css = build_footer_css(item, height)
# THEN: THE css should be the same. # THEN: THE css should be the same.
self.assertEqual(FOOTER_CSS, css, 'The footer strings should be equal.') assert FOOTER_CSS == css, 'The footer strings should be equal.'
def test_build_footer_css_wrap(self): def test_build_footer_css_wrap(self):
""" """
@ -423,7 +423,7 @@ class Htmbuilder(TestCase, TestMixin):
css = build_footer_css(item, height) css = build_footer_css(item, height)
# THEN: Footer should wrap # THEN: Footer should wrap
self.assertEqual(FOOTER_CSS_WRAP, css, 'The footer strings should be equal.') assert FOOTER_CSS_WRAP == css, 'The footer strings should be equal.'
def test_build_footer_invalid(self): def test_build_footer_invalid(self):
""" """
@ -443,8 +443,8 @@ class Htmbuilder(TestCase, TestMixin):
css.append(build_footer_css(item, height)) css.append(build_footer_css(item, height))
# THEN: Footer should wrap # THEN: Footer should wrap
self.assertEqual(FOOTER_CSS_INVALID, css[0], 'The footer strings should be blank.') assert FOOTER_CSS_INVALID == css[0], 'The footer strings should be blank.'
self.assertEqual(FOOTER_CSS_INVALID, css[1], 'The footer strings should be blank.') assert FOOTER_CSS_INVALID == css[1], 'The footer strings should be blank.'
def test_webkit_version(self): def test_webkit_version(self):
""" """
@ -454,7 +454,7 @@ class Htmbuilder(TestCase, TestMixin):
webkit_ver = float(QtWebKit.qWebKitVersion()) webkit_ver = float(QtWebKit.qWebKitVersion())
# WHEN: Retrieving the webkit version # WHEN: Retrieving the webkit version
# THEN: Webkit versions should match # THEN: Webkit versions should match
self.assertEquals(webkit_version(), webkit_ver, "The returned webkit version doesn't match the installed one") assert webkit_version() == webkit_ver, "The returned webkit version doesn't match the installed one"
def test_build_chords_css(self): def test_build_chords_css(self):
""" """
@ -468,4 +468,4 @@ class Htmbuilder(TestCase, TestMixin):
chord_css = build_chords_css() chord_css = build_chords_css()
# THEN: The build css should look as expected # THEN: The build css should look as expected
self.assertEqual(CHORD_CSS_ENABLED, chord_css, 'The chord CSS should look as expected') assert CHORD_CSS_ENABLED == chord_css, 'The chord CSS should look as expected'

View File

@ -84,7 +84,7 @@ class TestImageManager(TestCase, TestMixin):
# THEN a KeyError is thrown # THEN a KeyError is thrown
with self.assertRaises(KeyError) as context: with self.assertRaises(KeyError) as context:
self.image_manager.get_image(TEST_PATH, 'church1.jpg') self.image_manager.get_image(TEST_PATH, 'church1.jpg')
self.assertNotEquals(context.exception, '', 'KeyError exception should have been thrown for missing image') assert context.exception is not '', 'KeyError exception should have been thrown for missing image'
def test_different_dimension_image(self): def test_different_dimension_image(self):
""" """
@ -98,7 +98,7 @@ class TestImageManager(TestCase, TestMixin):
image = self.image_manager.get_image(full_path, 'church.jpg', 80, 80) image = self.image_manager.get_image(full_path, 'church.jpg', 80, 80)
# THEN: The return should be of type image # THEN: The return should be of type image
self.assertEqual(isinstance(image, QtGui.QImage), True, 'The returned object should be a QImage') assert isinstance(image, QtGui.QImage) is True, 'The returned object should be a QImage'
# WHEN: adding the same image with different dimensions # WHEN: adding the same image with different dimensions
self.image_manager.add_image(full_path, 'church.jpg', None, 100, 100) self.image_manager.add_image(full_path, 'church.jpg', None, 100, 100)
@ -116,7 +116,7 @@ class TestImageManager(TestCase, TestMixin):
# WHEN: calling with correct image, but wrong dimensions # WHEN: calling with correct image, but wrong dimensions
with self.assertRaises(KeyError) as context: with self.assertRaises(KeyError) as context:
self.image_manager.get_image(full_path, 'church.jpg', 120, 120) self.image_manager.get_image(full_path, 'church.jpg', 120, 120)
self.assertNotEquals(context.exception, '', 'KeyError exception should have been thrown for missing dimension') assert context.exception is not '', 'KeyError exception should have been thrown for missing dimension'
def test_process_cache(self): def test_process_cache(self):
""" """
@ -141,10 +141,8 @@ class TestImageManager(TestCase, TestMixin):
# is being processed (see mocked methods/functions). # is being processed (see mocked methods/functions).
# Note: Priority.Normal means, that the resize_image() was not completed yet (because afterwards the # # Note: Priority.Normal means, that the resize_image() was not completed yet (because afterwards the #
# priority is adjusted to Priority.Lowest). # priority is adjusted to Priority.Lowest).
self.assertEqual(self.get_image_priority(image1), Priority.Normal, assert self.get_image_priority(image1) == Priority.Normal, "image1's priority should be 'Priority.Normal'"
"image1's priority should be 'Priority.Normal'") assert self.get_image_priority(image2) == Priority.Normal, "image2's priority should be 'Priority.Normal'"
self.assertEqual(self.get_image_priority(image2), Priority.Normal,
"image2's priority should be 'Priority.Normal'")
# WHEN: Add more images. # WHEN: Add more images.
self.image_manager.add_image(TEST_PATH, image3, None) self.image_manager.add_image(TEST_PATH, image3, None)
@ -162,15 +160,15 @@ class TestImageManager(TestCase, TestMixin):
# Because empty() is not reliable, wait a litte; just to make sure. # Because empty() is not reliable, wait a litte; just to make sure.
time.sleep(0.1) time.sleep(0.1)
# THEN: The images' priority reflect how they were processed. # THEN: The images' priority reflect how they were processed.
self.assertEqual(self.image_manager._conversion_queue.qsize(), 0, "The queue should be empty.") assert self.image_manager._conversion_queue.qsize() == 0, "The queue should be empty."
self.assertEqual(self.get_image_priority(image1), Priority.Lowest, assert self.get_image_priority(image1) == Priority.Lowest, \
"The image should have not been requested (=Lowest)") "The image should have not been requested (=Lowest)"
self.assertEqual(self.get_image_priority(image2), Priority.Lowest, assert self.get_image_priority(image2) == Priority.Lowest, \
"The image should have not been requested (=Lowest)") "The image should have not been requested (=Lowest)"
self.assertEqual(self.get_image_priority(image3), Priority.Low, assert self.get_image_priority(image3) == Priority.Low, \
"Only the QImage should have been requested (=Low).") "Only the QImage should have been requested (=Low)."
self.assertEqual(self.get_image_priority(image4), Priority.Urgent, assert self.get_image_priority(image4) == Priority.Urgent, \
"The image bytes should have been requested (=Urgent).") "The image bytes should have been requested (=Urgent)."
def get_image_priority(self, image): def get_image_priority(self, image):
""" """

View File

@ -49,8 +49,8 @@ class TestLib(TestCase):
true_result = str_to_bool(true_boolean) true_result = str_to_bool(true_boolean)
# THEN: We should get back a True bool # THEN: We should get back a True bool
self.assertIsInstance(true_result, bool, 'The result should be a boolean') assert isinstance(true_result, bool), 'The result should be a boolean'
self.assertTrue(true_result, 'The result should be True') assert true_result is True, 'The result should be True'
def test_str_to_bool_with_bool_false(self): def test_str_to_bool_with_bool_false(self):
""" """
@ -63,8 +63,8 @@ class TestLib(TestCase):
false_result = str_to_bool(false_boolean) false_result = str_to_bool(false_boolean)
# THEN: We should get back a True bool # THEN: We should get back a True bool
self.assertIsInstance(false_result, bool, 'The result should be a boolean') assert isinstance(false_result, bool), 'The result should be a boolean'
self.assertFalse(false_result, 'The result should be True') assert false_result is False, 'The result should be True'
def test_str_to_bool_with_integer(self): def test_str_to_bool_with_integer(self):
""" """
@ -77,7 +77,7 @@ class TestLib(TestCase):
int_result = str_to_bool(int_string) int_result = str_to_bool(int_string)
# THEN: we should get back a false # THEN: we should get back a false
self.assertFalse(int_result, 'The result should be False') assert int_result is False, 'The result should be False'
def test_str_to_bool_with_invalid_string(self): def test_str_to_bool_with_invalid_string(self):
""" """
@ -90,7 +90,7 @@ class TestLib(TestCase):
str_result = str_to_bool(invalid_string) str_result = str_to_bool(invalid_string)
# THEN: we should get back a false # THEN: we should get back a false
self.assertFalse(str_result, 'The result should be False') assert str_result is False, 'The result should be False'
def test_str_to_bool_with_string_false(self): def test_str_to_bool_with_string_false(self):
""" """
@ -103,7 +103,7 @@ class TestLib(TestCase):
false_result = str_to_bool(false_string) false_result = str_to_bool(false_string)
# THEN: we should get back a false # THEN: we should get back a false
self.assertFalse(false_result, 'The result should be False') assert false_result is False, 'The result should be False'
def test_str_to_bool_with_string_no(self): def test_str_to_bool_with_string_no(self):
""" """
@ -116,7 +116,7 @@ class TestLib(TestCase):
str_result = str_to_bool(no_string) str_result = str_to_bool(no_string)
# THEN: we should get back a false # THEN: we should get back a false
self.assertFalse(str_result, 'The result should be False') assert str_result is False, 'The result should be False'
def test_str_to_bool_with_true_string_value(self): def test_str_to_bool_with_true_string_value(self):
""" """
@ -129,7 +129,7 @@ class TestLib(TestCase):
true_result = str_to_bool(true_string) true_result = str_to_bool(true_string)
# THEN: we should get back a true # THEN: we should get back a true
self.assertTrue(true_result, 'The result should be True') assert true_result is True, 'The result should be True'
def test_str_to_bool_with_yes_string_value(self): def test_str_to_bool_with_yes_string_value(self):
""" """
@ -142,7 +142,7 @@ class TestLib(TestCase):
str_result = str_to_bool(yes_string) str_result = str_to_bool(yes_string)
# THEN: we should get back a true # THEN: we should get back a true
self.assertTrue(str_result, 'The result should be True') assert str_result is True, 'The result should be True'
def test_get_text_file_string_no_file(self): def test_get_text_file_string_no_file(self):
""" """
@ -157,7 +157,7 @@ class TestLib(TestCase):
# THEN: The result should be False # THEN: The result should be False
file_path.is_file.assert_called_with() file_path.is_file.assert_called_with()
self.assertFalse(result, 'False should be returned if no file exists') assert result is False, 'False should be returned if no file exists'
def test_get_text_file_string_read_error(self): def test_get_text_file_string_read_error(self):
""" """
@ -176,7 +176,7 @@ class TestLib(TestCase):
# THEN: None should be returned # THEN: None should be returned
file_path.is_file.assert_called_once_with() file_path.is_file.assert_called_once_with()
file_path.open.assert_called_once_with('r', encoding='utf-8') file_path.open.assert_called_once_with('r', encoding='utf-8')
self.assertIsNone(result, 'None should be returned if the file cannot be opened') assert result is None, 'None should be returned if the file cannot be opened'
def test_get_text_file_string_decode_error(self): def test_get_text_file_string_decode_error(self):
""" """
@ -195,7 +195,7 @@ class TestLib(TestCase):
result = build_icon(icon) result = build_icon(icon)
# THEN: The result should be the same icon as we passed in # THEN: The result should be the same icon as we passed in
self.assertIs(icon, result, 'The result should be the same icon as we passed in') assert icon is result, 'The result should be the same icon as we passed in'
def test_build_icon_with_resource(self): def test_build_icon_with_resource(self):
""" """
@ -217,7 +217,7 @@ class TestLib(TestCase):
MockedQPixmap.assert_called_with(resource_uri) MockedQPixmap.assert_called_with(resource_uri)
# There really should be more assert statements here but due to type checking and things they all break. The # There really should be more assert statements here but due to type checking and things they all break. The
# best we can do is to assert that we get back a MagicMock object. # best we can do is to assert that we get back a MagicMock object.
self.assertIsInstance(result, MagicMock, 'The result should be a MagicMock, because we mocked it out') assert isinstance(result, MagicMock), 'The result should be a MagicMock, because we mocked it out'
def test_image_to_byte(self): def test_image_to_byte(self):
""" """
@ -240,8 +240,8 @@ class TestLib(TestCase):
MockedQtCore.QBuffer.assert_called_with(mocked_byte_array) MockedQtCore.QBuffer.assert_called_with(mocked_byte_array)
mocked_buffer.open.assert_called_with('writeonly') mocked_buffer.open.assert_called_with('writeonly')
mocked_image.save.assert_called_with(mocked_buffer, "PNG") mocked_image.save.assert_called_with(mocked_buffer, "PNG")
self.assertFalse(mocked_byte_array.toBase64.called) assert mocked_byte_array.toBase64.called is False
self.assertEqual(mocked_byte_array, result, 'The mocked out byte array should be returned') assert mocked_byte_array == result, 'The mocked out byte array should be returned'
def test_image_to_byte_base_64(self): def test_image_to_byte_base_64(self):
""" """
@ -266,8 +266,7 @@ class TestLib(TestCase):
mocked_buffer.open.assert_called_with('writeonly') mocked_buffer.open.assert_called_with('writeonly')
mocked_image.save.assert_called_with(mocked_buffer, "PNG") mocked_image.save.assert_called_with(mocked_buffer, "PNG")
mocked_byte_array.toBase64.assert_called_with() mocked_byte_array.toBase64.assert_called_with()
self.assertEqual('base64mock', result, 'The result should be the return value of the mocked out ' assert 'base64mock' == result, 'The result should be the return value of the mocked out base64 method'
'base64 method')
def test_create_thumb_with_size(self): def test_create_thumb_with_size(self):
""" """
@ -286,16 +285,16 @@ class TestLib(TestCase):
pass pass
# Only continue when the thumb does not exist. # Only continue when the thumb does not exist.
self.assertFalse(thumb_path.exists(), 'Test was not run, because the thumb already exists.') assert thumb_path.exists() is False, 'Test was not run, because the thumb already exists.'
# WHEN: Create the thumb. # WHEN: Create the thumb.
icon = create_thumb(image_path, thumb_path, size=thumb_size) icon = create_thumb(image_path, thumb_path, size=thumb_size)
# THEN: Check if the thumb was created and scaled to the given size. # THEN: Check if the thumb was created and scaled to the given size.
self.assertTrue(thumb_path.exists(), 'Test was not ran, because the thumb already exists') self.assertTrue(thumb_path.exists(), 'Test was not ran, because the thumb already exists')
self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon'
self.assertFalse(icon.isNull(), 'The icon should not be null') assert icon.isNull()is False, 'The icon should not be null'
self.assertEqual(thumb_size, QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size') assert thumb_size == QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size'
# Remove the thumb so that the test actually tests if the thumb will be created. # Remove the thumb so that the test actually tests if the thumb will be created.
try: try:
@ -320,17 +319,16 @@ class TestLib(TestCase):
pass pass
# Only continue when the thumb does not exist. # Only continue when the thumb does not exist.
self.assertFalse(thumb_path.exists(), 'Test was not run, because the thumb already exists.') assert thumb_path.exists() is False, 'Test was not run, because the thumb already exists.'
# WHEN: Create the thumb. # WHEN: Create the thumb.
icon = create_thumb(image_path, thumb_path) icon = create_thumb(image_path, thumb_path)
# THEN: Check if the thumb was created, retaining its aspect ratio. # THEN: Check if the thumb was created, retaining its aspect ratio.
self.assertTrue(thumb_path.exists(), 'Test was not ran, because the thumb already exists') self.assertTrue(thumb_path.exists(), 'Test was not ran, because the thumb already exists')
self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon'
self.assertFalse(icon.isNull(), 'The icon should not be null') assert icon.isNull() is False, 'The icon should not be null'
self.assertEqual(expected_size, QtGui.QImageReader(str(thumb_path)).size(), assert expected_size == QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size'
'The thumb should have the given size')
# Remove the thumb so that the test actually tests if the thumb will be created. # Remove the thumb so that the test actually tests if the thumb will be created.
try: try:
@ -356,17 +354,16 @@ class TestLib(TestCase):
pass pass
# Only continue when the thumb does not exist. # Only continue when the thumb does not exist.
self.assertFalse(thumb_path.exists(), 'Test was not run, because the thumb already exists.') assert thumb_path.exists() is False, 'Test was not run, because the thumb already exists.'
# WHEN: Create the thumb. # WHEN: Create the thumb.
icon = create_thumb(image_path, thumb_path, size=thumb_size) icon = create_thumb(image_path, thumb_path, size=thumb_size)
# THEN: Check if the thumb was created, retaining its aspect ratio. # THEN: Check if the thumb was created, retaining its aspect ratio.
self.assertTrue(thumb_path.exists(), 'Test was not ran, because the thumb already exists') assert thumb_path.exists() is True, 'Test was not ran, because the thumb already exists'
self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon'
self.assertFalse(icon.isNull(), 'The icon should not be null') assert icon.isNull() is False, 'The icon should not be null'
self.assertEqual(expected_size, QtGui.QImageReader(str(thumb_path)).size(), assert expected_size == QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size'
'The thumb should have the given size')
# Remove the thumb so that the test actually tests if the thumb will be created. # Remove the thumb so that the test actually tests if the thumb will be created.
try: try:
@ -392,17 +389,16 @@ class TestLib(TestCase):
pass pass
# Only continue when the thumb does not exist. # Only continue when the thumb does not exist.
self.assertFalse(thumb_path.exists(), 'Test was not run, because the thumb already exists.') assert thumb_path.exists() is False, 'Test was not run, because the thumb already exists.'
# WHEN: Create the thumb. # WHEN: Create the thumb.
icon = create_thumb(image_path, thumb_path, size=thumb_size) icon = create_thumb(image_path, thumb_path, size=thumb_size)
# THEN: Check if the thumb was created, retaining its aspect ratio. # THEN: Check if the thumb was created, retaining its aspect ratio.
self.assertTrue(thumb_path.exists(), 'Test was not ran, because the thumb already exists') assert thumb_path.exists() is True, 'Test was not ran, because the thumb already exists'
self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon'
self.assertFalse(icon.isNull(), 'The icon should not be null') assert icon.isNull() is False, 'The icon should not be null'
self.assertEqual( assert expected_size == QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size'
expected_size, QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size')
# Remove the thumb so that the test actually tests if the thumb will be created. # Remove the thumb so that the test actually tests if the thumb will be created.
try: try:
@ -428,17 +424,16 @@ class TestLib(TestCase):
pass pass
# Only continue when the thumb does not exist. # Only continue when the thumb does not exist.
self.assertFalse(thumb_path.exists(), 'Test was not run, because the thumb already exists.') assert thumb_path.exists() is False, 'Test was not run, because the thumb already exists.'
# WHEN: Create the thumb. # WHEN: Create the thumb.
icon = create_thumb(image_path, thumb_path, size=thumb_size) icon = create_thumb(image_path, thumb_path, size=thumb_size)
# THEN: Check if the thumb was created, retaining its aspect ratio. # THEN: Check if the thumb was created, retaining its aspect ratio.
self.assertTrue(thumb_path.exists(), 'Test was not ran, because the thumb already exists') self.assertTrue(thumb_path.exists(), 'Test was not ran, because the thumb already exists')
self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon'
self.assertFalse(icon.isNull(), 'The icon should not be null') assert icon.isNull() is False, 'The icon should not be null'
self.assertEqual( assert expected_size == QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size'
expected_size, QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size')
# Remove the thumb so that the test actually tests if the thumb will be created. # Remove the thumb so that the test actually tests if the thumb will be created.
try: try:
@ -465,7 +460,7 @@ class TestLib(TestCase):
pass pass
# Only continue when the thumb does not exist. # Only continue when the thumb does not exist.
self.assertFalse(thumb_path.exists(), 'Test was not run, because the thumb already exists.') assert thumb_path.exists() is False, 'Test was not run, because the thumb already exists.'
# WHEN: Create the thumb. # WHEN: Create the thumb.
with patch('openlp.core.lib.QtGui.QImageReader.size') as mocked_size: with patch('openlp.core.lib.QtGui.QImageReader.size') as mocked_size:
@ -474,10 +469,9 @@ class TestLib(TestCase):
# THEN: Check if the thumb was created with aspect ratio of 1. # THEN: Check if the thumb was created with aspect ratio of 1.
self.assertTrue(thumb_path.exists(), 'Test was not ran, because the thumb already exists') self.assertTrue(thumb_path.exists(), 'Test was not ran, because the thumb already exists')
self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon'
self.assertFalse(icon.isNull(), 'The icon should not be null') assert icon.isNull() is False, 'The icon should not be null'
self.assertEqual( assert expected_size_1 == QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size'
expected_size_1, QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size')
# WHEN: Create the thumb. # WHEN: Create the thumb.
with patch('openlp.core.lib.QtGui.QImageReader.size') as mocked_size: with patch('openlp.core.lib.QtGui.QImageReader.size') as mocked_size:
@ -485,10 +479,9 @@ class TestLib(TestCase):
icon = create_thumb(image_path, thumb_path, size=thumb_size) icon = create_thumb(image_path, thumb_path, size=thumb_size)
# THEN: Check if the thumb was created with aspect ratio of 1. # THEN: Check if the thumb was created with aspect ratio of 1.
self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon'
self.assertFalse(icon.isNull(), 'The icon should not be null') assert icon.isNull() is False, 'The icon should not be null'
self.assertEqual( assert expected_size_2 == QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size'
expected_size_2, QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size')
# Remove the thumb so that the test actually tests if the thumb will be created. # Remove the thumb so that the test actually tests if the thumb will be created.
try: try:
@ -511,7 +504,7 @@ class TestLib(TestCase):
# THEN: The selectedIndexes function should have been called and the result should be true # THEN: The selectedIndexes function should have been called and the result should be true
mocked_list_widget.selectedIndexes.assert_called_with() mocked_list_widget.selectedIndexes.assert_called_with()
self.assertTrue(result, 'The result should be True') assert result is True, 'The result should be True'
def test_check_item_selected_false(self): def test_check_item_selected_false(self):
""" """
@ -532,7 +525,7 @@ class TestLib(TestCase):
# THEN: The selectedIndexes function should have been called and the result should be true # THEN: The selectedIndexes function should have been called and the result should be true
mocked_list_widget.selectedIndexes.assert_called_with() mocked_list_widget.selectedIndexes.assert_called_with()
MockedQtWidgets.QMessageBox.information.assert_called_with('parent', 'mocked translate', 'message') MockedQtWidgets.QMessageBox.information.assert_called_with('parent', 'mocked translate', 'message')
self.assertFalse(result, 'The result should be False') assert result is False, 'The result should be False'
def test_clean_tags(self): def test_clean_tags(self):
""" """
@ -554,7 +547,7 @@ class TestLib(TestCase):
result_string = clean_tags(string_to_pass) result_string = clean_tags(string_to_pass)
# THEN: The strings should be identical. # THEN: The strings should be identical.
self.assertEqual(wanted_string, result_string, 'The strings should be identical') assert wanted_string == result_string, 'The strings should be identical'
def test_expand_tags(self): def test_expand_tags(self):
""" """
@ -593,7 +586,7 @@ class TestLib(TestCase):
result_string = expand_tags(string_to_pass) result_string = expand_tags(string_to_pass)
# THEN: The strings should be identical. # THEN: The strings should be identical.
self.assertEqual(wanted_string, result_string, 'The strings should be identical.') assert wanted_string == result_string, 'The strings should be identical.'
def test_validate_thumb_file_does_not_exist(self): def test_validate_thumb_file_does_not_exist(self):
""" """
@ -609,7 +602,7 @@ class TestLib(TestCase):
# THEN: we should have called a few functions, and the result should be False # THEN: we should have called a few functions, and the result should be False
thumb_path.exists.assert_called_once_with() thumb_path.exists.assert_called_once_with()
self.assertFalse(result, 'The result should be False') assert result is False, 'The result should be False'
def test_validate_thumb_file_exists_and_newer(self): def test_validate_thumb_file_exists_and_newer(self):
""" """
@ -624,7 +617,7 @@ class TestLib(TestCase):
result = validate_thumb(file_path, thumb_path) result = validate_thumb(file_path, thumb_path)
# THEN: `validate_thumb` should return True # THEN: `validate_thumb` should return True
self.assertTrue(result) assert result is True
def test_validate_thumb_file_exists_and_older(self): def test_validate_thumb_file_exists_and_older(self):
""" """
@ -639,7 +632,7 @@ class TestLib(TestCase):
# THEN: `validate_thumb` should return False # THEN: `validate_thumb` should return False
thumb_path.stat.assert_called_once_with() thumb_path.stat.assert_called_once_with()
self.assertFalse(result, 'The result should be False') assert result is False, 'The result should be False'
def test_resize_thumb(self): def test_resize_thumb(self):
""" """
@ -658,9 +651,9 @@ class TestLib(TestCase):
# THEN: Check if the size is correct and the background was set. # THEN: Check if the size is correct and the background was set.
result_size = image.size() result_size = image.size()
self.assertEqual(wanted_height, result_size.height(), 'The image should have the requested height.') assert wanted_height == result_size.height(), 'The image should have the requested height.'
self.assertEqual(wanted_width, result_size.width(), 'The image should have the requested width.') assert wanted_width == result_size.width(), 'The image should have the requested width.'
self.assertEqual(image.pixel(0, 0), wanted_background_rgb, 'The background should be white.') assert image.pixel(0, 0) == wanted_background_rgb, 'The background should be white.'
def test_resize_thumb_ignoring_aspect_ratio(self): def test_resize_thumb_ignoring_aspect_ratio(self):
""" """
@ -679,9 +672,9 @@ class TestLib(TestCase):
# THEN: Check if the size is correct and the background was set. # THEN: Check if the size is correct and the background was set.
result_size = image.size() result_size = image.size()
self.assertEqual(wanted_height, result_size.height(), 'The image should have the requested height.') assert wanted_height == result_size.height(), 'The image should have the requested height.'
self.assertEqual(wanted_width, result_size.width(), 'The image should have the requested width.') assert wanted_width == result_size.width(), 'The image should have the requested width.'
self.assertEqual(image.pixel(0, 0), wanted_background_rgb, 'The background should be white.') assert image.pixel(0, 0) == wanted_background_rgb, 'The background should be white.'
@patch('openlp.core.lib.QtCore.QLocale.createSeparatedList') @patch('openlp.core.lib.QtCore.QLocale.createSeparatedList')
def test_create_separated_list_qlocate(self, mocked_createSeparatedList): def test_create_separated_list_qlocate(self, mocked_createSeparatedList):
@ -696,8 +689,8 @@ class TestLib(TestCase):
string_result = create_separated_list(string_list) string_result = create_separated_list(string_list)
# THEN: We should have "Author 1, Author 2, and Author 3" # THEN: We should have "Author 1, Author 2, and Author 3"
self.assertEqual(string_result, 'Author 1, Author 2 and Author 3', 'The string should be "Author 1, ' assert string_result == 'Author 1, Author 2 and Author 3', \
'Author 2, and Author 3".') 'The string should be "Author 1, Author 2, and Author 3".'
def test_create_separated_list_empty_list(self): def test_create_separated_list_empty_list(self):
""" """
@ -710,7 +703,7 @@ class TestLib(TestCase):
string_result = create_separated_list(string_list) string_result = create_separated_list(string_list)
# THEN: We shoud have an emptry string. # THEN: We shoud have an emptry string.
self.assertEqual(string_result, '', 'The string sould be empty.') assert string_result == '', 'The string sould be empty.'
def test_create_separated_list_with_one_item(self): def test_create_separated_list_with_one_item(self):
""" """
@ -723,7 +716,7 @@ class TestLib(TestCase):
string_result = create_separated_list(string_list) string_result = create_separated_list(string_list)
# THEN: We should have "Author 1" # THEN: We should have "Author 1"
self.assertEqual(string_result, 'Author 1', 'The string should be "Author 1".') assert string_result == 'Author 1', 'The string should be "Author 1".'
def test_create_separated_list_with_two_items(self): def test_create_separated_list_with_two_items(self):
""" """
@ -736,7 +729,7 @@ class TestLib(TestCase):
string_result = create_separated_list(string_list) string_result = create_separated_list(string_list)
# THEN: We should have "Author 1 and Author 2" # THEN: We should have "Author 1 and Author 2"
self.assertEqual(string_result, 'Author 1 and Author 2', 'The string should be "Author 1 and Author 2".') assert string_result == 'Author 1 and Author 2', 'The string should be "Author 1 and Author 2".'
def test_create_separated_list_with_three_items(self): def test_create_separated_list_with_three_items(self):
""" """
@ -749,8 +742,8 @@ class TestLib(TestCase):
string_result = create_separated_list(string_list) string_result = create_separated_list(string_list)
# THEN: We should have "Author 1, Author 2 and Author 3" # THEN: We should have "Author 1, Author 2 and Author 3"
self.assertEqual(string_result, 'Author 1, Author 2 and Author 3', 'The string should be "Author 1, ' assert string_result == 'Author 1, Author 2 and Author 3', \
'Author 2, and Author 3".') 'The string should be "Author 1, Author 2, and Author 3".'
def test_expand_chords(self): def test_expand_chords(self):
""" """
@ -766,7 +759,7 @@ class TestLib(TestCase):
expected_html = '<span class="chordline firstchordline">H<span class="chord"><span><strong>C</strong></span>' \ expected_html = '<span class="chordline firstchordline">H<span class="chord"><span><strong>C</strong></span>' \
'</span>alleluya.<span class="chord"><span><strong>F</strong></span></span><span class="ws">' \ '</span>alleluya.<span class="chord"><span><strong>F</strong></span></span><span class="ws">' \
'&nbsp;&nbsp;</span> <span class="chord"><span><strong>G</strong></span></span></span>' '&nbsp;&nbsp;</span> <span class="chord"><span><strong>G</strong></span></span></span>'
self.assertEqual(expected_html, text_with_expanded_chords, 'The expanded chords should look as expected!') assert expected_html == text_with_expanded_chords, 'The expanded chords should look as expected!'
def test_expand_chords2(self): def test_expand_chords2(self):
""" """
@ -782,7 +775,7 @@ class TestLib(TestCase):
expected_html = '<span class="chordline firstchordline">I<span class="chord"><span><strong>D</strong></span>' \ expected_html = '<span class="chordline firstchordline">I<span class="chord"><span><strong>D</strong></span>' \
'</span>&#x27;M NOT MOVED BY WHAT I SEE HALLE<span class="chord"><span><strong>F</strong>' \ '</span>&#x27;M NOT MOVED BY WHAT I SEE HALLE<span class="chord"><span><strong>F</strong>' \
'</span></span>LUJA<span class="chord"><span><strong>C</strong></span></span>H</span>' '</span></span>LUJA<span class="chord"><span><strong>C</strong></span></span>H</span>'
self.assertEqual(expected_html, text_with_expanded_chords, 'The expanded chords should look as expected!') assert expected_html == text_with_expanded_chords, 'The expanded chords should look as expected!'
def test_compare_chord_lyric_short_chord(self): def test_compare_chord_lyric_short_chord(self):
""" """
@ -810,7 +803,7 @@ class TestLib(TestCase):
ret = compare_chord_lyric(chord, lyrics) ret = compare_chord_lyric(chord, lyrics)
# THEN: The returned value should 4 because the chord is longer than the lyric # THEN: The returned value should 4 because the chord is longer than the lyric
self.assertEquals(4, ret, 'The returned value should 4 because the chord is longer than the lyric') assert 4 == ret, 'The returned value should 4 because the chord is longer than the lyric'
def test_find_formatting_tags(self): def test_find_formatting_tags(self):
""" """
@ -825,7 +818,7 @@ class TestLib(TestCase):
active_tags = find_formatting_tags(lyrics, tags) active_tags = find_formatting_tags(lyrics, tags)
# THEN: The list of active tags should contain only 'st' # THEN: The list of active tags should contain only 'st'
self.assertListEqual(['st'], active_tags, 'The list of active tags should contain only "st"') assert ['st'] == active_tags, 'The list of active tags should contain only "st"'
def test_expand_chords_for_printing(self): def test_expand_chords_for_printing(self):
""" """
@ -862,4 +855,4 @@ class TestLib(TestCase):
'<table class="segment" cellpadding="0" cellspacing="0" border="0" align="left"><tr ' \ '<table class="segment" cellpadding="0" cellspacing="0" border="0" align="left"><tr ' \
'class="chordrow"><td class="chord">F</td></tr><tr><td class="lyrics">{st}{/st}&nbsp;</td>' \ 'class="chordrow"><td class="chord">F</td></tr><tr><td class="lyrics">{st}{/st}&nbsp;</td>' \
'</tr></table></td></tr></table>' '</tr></table></td></tr></table>'
self.assertEqual(expected_html, text_with_expanded_chords, 'The expanded chords should look as expected!') assert expected_html == text_with_expanded_chords, 'The expanded chords should look as expected!'