mirror of https://gitlab.com/openlp/openlp.git
functional lib completed
lp:~trb143/openlp/asserts (revision 2815) https://ci.openlp.io/job/Branch-01-Pull/2362/ [SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/2263/ [SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/2124/ [SUCCESS] https://ci.openlp.io/job/Branch-04a-Code_Analysis/1450/ [SUCCESS] https://ci.openlp.io/job/Branch-04b-Test_Coverage/1266/ [SUCCESS] https://ci.openlp.io/jo... bzr-revno: 2797
This commit is contained in:
commit
66bc4bcf98
|
@ -113,7 +113,7 @@ class TestRenderer(TestCase):
|
|||
result = get_start_tags(given_raw_text)
|
||||
|
||||
# THEN: Check if the correct tuple is returned.
|
||||
self.assertEqual(result, expected_tuple), 'A tuple should be returned containing the text with correct ' \
|
||||
assert result == expected_tuple, 'A tuple should be returned containing the text with correct ' \
|
||||
'tags, the opening tags, and the opening html tags.'
|
||||
|
||||
def test_word_split(self):
|
||||
|
@ -128,7 +128,7 @@ class TestRenderer(TestCase):
|
|||
result_words = words_split(given_line)
|
||||
|
||||
# THEN: The word lists should be the same.
|
||||
self.assertListEqual(result_words, expected_words)
|
||||
assert result_words == expected_words
|
||||
|
||||
def test_format_slide_logical_split(self):
|
||||
"""
|
||||
|
@ -145,7 +145,7 @@ class TestRenderer(TestCase):
|
|||
result_words = renderer.format_slide(given_line, service_item)
|
||||
|
||||
# THEN: The word lists should be the same.
|
||||
self.assertListEqual(result_words, expected_words)
|
||||
assert result_words == expected_words
|
||||
|
||||
def test_format_slide_blank_before_split(self):
|
||||
"""
|
||||
|
@ -162,7 +162,7 @@ class TestRenderer(TestCase):
|
|||
result_words = renderer.format_slide(given_line, service_item)
|
||||
|
||||
# THEN: The blanks have been removed.
|
||||
self.assertListEqual(result_words, expected_words)
|
||||
assert result_words == expected_words
|
||||
|
||||
def test_format_slide_blank_after_split(self):
|
||||
"""
|
||||
|
@ -179,7 +179,7 @@ class TestRenderer(TestCase):
|
|||
result_words = renderer.format_slide(given_line, service_item)
|
||||
|
||||
# THEN: The blanks have been removed.
|
||||
self.assertListEqual(result_words, expected_words)
|
||||
assert result_words == expected_words
|
||||
|
||||
@patch('openlp.core.display.renderer.QtWebKitWidgets.QWebView')
|
||||
@patch('openlp.core.display.renderer.build_lyrics_format_css')
|
||||
|
|
|
@ -75,6 +75,6 @@ class TestScreenList(TestCase):
|
|||
|
||||
# THEN: The screen should have been added and the screens should be identical
|
||||
new_screen_count = len(self.screens.screen_list)
|
||||
self.assertEqual(old_screen_count + 1, new_screen_count, 'The new_screens list should be bigger')
|
||||
self.assertEqual(SCREEN, self.screens.screen_list.pop(),
|
||||
'The 2nd screen should be identical to the first screen')
|
||||
assert old_screen_count + 1 == new_screen_count, 'The new_screens list should be bigger'
|
||||
assert SCREEN == self.screens.screen_list.pop(), \
|
||||
'The 2nd screen should be identical to the first screen'
|
||||
|
|
|
@ -80,8 +80,8 @@ class TestDB(TestCase):
|
|||
MockedMetaData.assert_called_with(bind=mocked_engine)
|
||||
mocked_sessionmaker.assert_called_with(autoflush=True, autocommit=False, bind=mocked_engine)
|
||||
mocked_scoped_session.assert_called_with(mocked_sessionmaker_object)
|
||||
self.assertIs(session, mocked_scoped_session_object, 'The ``session`` object should be the mock')
|
||||
self.assertIs(metadata, mocked_metadata, 'The ``metadata`` object should be the mock')
|
||||
assert session is mocked_scoped_session_object, 'The ``session`` object should be the mock'
|
||||
assert metadata is mocked_metadata, 'The ``metadata`` object should be the mock'
|
||||
|
||||
def test_init_db_defaults(self):
|
||||
"""
|
||||
|
@ -94,8 +94,8 @@ class TestDB(TestCase):
|
|||
session, metadata = init_db(db_url)
|
||||
|
||||
# THEN: Valid session and metadata objects should be returned
|
||||
self.assertIsInstance(session, ScopedSession, 'The ``session`` object should be a ``ScopedSession`` instance')
|
||||
self.assertIsInstance(metadata, MetaData, 'The ``metadata`` object should be a ``MetaData`` instance')
|
||||
assert isinstance(session, ScopedSession), 'The ``session`` object should be a ``ScopedSession`` instance'
|
||||
assert isinstance(metadata, MetaData), 'The ``metadata`` object should be a ``MetaData`` instance'
|
||||
|
||||
def test_get_upgrade_op(self):
|
||||
"""
|
||||
|
@ -116,7 +116,7 @@ class TestDB(TestCase):
|
|||
op = get_upgrade_op(mocked_session)
|
||||
|
||||
# THEN: The op object should be mocked_op, and the correction function calls should have been made
|
||||
self.assertIs(op, mocked_op, 'The return value should be the mocked object')
|
||||
assert op is mocked_op, 'The return value should be the mocked object'
|
||||
mocked_session.bind.connect.assert_called_with()
|
||||
MockedMigrationContext.configure.assert_called_with(mocked_connection)
|
||||
MockedOperations.assert_called_with(mocked_context)
|
||||
|
@ -139,7 +139,7 @@ class TestDB(TestCase):
|
|||
# THEN: The AppLocation.get_section_data_path and delete_file methods should have been called
|
||||
MockedAppLocation.get_section_data_path.assert_called_with(test_plugin)
|
||||
mocked_delete_file.assert_called_with(test_location)
|
||||
self.assertTrue(result, 'The result of delete_file should be True (was rigged that way)')
|
||||
assert result is True, 'The result of delete_file should be True (was rigged that way)'
|
||||
|
||||
def test_delete_database_with_db_file_name(self):
|
||||
"""
|
||||
|
@ -160,7 +160,7 @@ class TestDB(TestCase):
|
|||
# THEN: The AppLocation.get_section_data_path and delete_file methods should have been called
|
||||
MockedAppLocation.get_section_data_path.assert_called_with(test_plugin)
|
||||
mocked_delete_file.assert_called_with(test_location)
|
||||
self.assertFalse(result, 'The result of delete_file should be False (was rigged that way)')
|
||||
assert result is False, 'The result of delete_file should be False (was rigged that way)'
|
||||
|
||||
def test_skip_db_upgrade_with_no_database(self):
|
||||
"""
|
||||
|
@ -174,4 +174,4 @@ class TestDB(TestCase):
|
|||
upgrade_db(url, mocked_upgrade)
|
||||
|
||||
# THEN: upgrade should NOT have been called
|
||||
self.assertFalse(mocked_upgrade.called, 'Database upgrade function should NOT have been called')
|
||||
assert mocked_upgrade.called is False, 'Database upgrade function should NOT have been called'
|
||||
|
|
|
@ -309,7 +309,7 @@ class Htmbuilder(TestCase, TestMixin):
|
|||
html = build_html(item, screen, is_live, background, plugins=plugins)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -325,7 +325,7 @@ class Htmbuilder(TestCase, TestMixin):
|
|||
css = build_background_css(item, width)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -346,7 +346,7 @@ class Htmbuilder(TestCase, TestMixin):
|
|||
css = build_lyrics_css(item)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -363,7 +363,7 @@ class Htmbuilder(TestCase, TestMixin):
|
|||
css = build_lyrics_outline_css(theme_data)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -386,7 +386,7 @@ class Htmbuilder(TestCase, TestMixin):
|
|||
css = build_lyrics_format_css(theme_data, width, height)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -404,7 +404,7 @@ class Htmbuilder(TestCase, TestMixin):
|
|||
css = build_footer_css(item, height)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -423,7 +423,7 @@ class Htmbuilder(TestCase, TestMixin):
|
|||
css = build_footer_css(item, height)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -443,8 +443,8 @@ class Htmbuilder(TestCase, TestMixin):
|
|||
css.append(build_footer_css(item, height))
|
||||
|
||||
# THEN: Footer should wrap
|
||||
self.assertEqual(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[0], 'The footer strings should be blank.'
|
||||
assert FOOTER_CSS_INVALID == css[1], 'The footer strings should be blank.'
|
||||
|
||||
def test_webkit_version(self):
|
||||
"""
|
||||
|
@ -454,7 +454,7 @@ class Htmbuilder(TestCase, TestMixin):
|
|||
webkit_ver = float(QtWebKit.qWebKitVersion())
|
||||
# WHEN: Retrieving the webkit version
|
||||
# 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):
|
||||
"""
|
||||
|
@ -468,4 +468,4 @@ class Htmbuilder(TestCase, TestMixin):
|
|||
chord_css = build_chords_css()
|
||||
|
||||
# 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'
|
||||
|
|
|
@ -84,7 +84,7 @@ class TestImageManager(TestCase, TestMixin):
|
|||
# THEN a KeyError is thrown
|
||||
with self.assertRaises(KeyError) as context:
|
||||
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):
|
||||
"""
|
||||
|
@ -98,7 +98,7 @@ class TestImageManager(TestCase, TestMixin):
|
|||
image = self.image_manager.get_image(full_path, 'church.jpg', 80, 80)
|
||||
|
||||
# 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), 'The returned object should be a QImage'
|
||||
|
||||
# WHEN: adding the same image with different dimensions
|
||||
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
|
||||
with self.assertRaises(KeyError) as context:
|
||||
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):
|
||||
"""
|
||||
|
@ -141,10 +141,8 @@ class TestImageManager(TestCase, TestMixin):
|
|||
# is being processed (see mocked methods/functions).
|
||||
# Note: Priority.Normal means, that the resize_image() was not completed yet (because afterwards the #
|
||||
# priority is adjusted to Priority.Lowest).
|
||||
self.assertEqual(self.get_image_priority(image1), Priority.Normal,
|
||||
"image1's priority should be 'Priority.Normal'")
|
||||
self.assertEqual(self.get_image_priority(image2), Priority.Normal,
|
||||
"image2's priority should be 'Priority.Normal'")
|
||||
assert self.get_image_priority(image1) == Priority.Normal, "image1's priority should be 'Priority.Normal'"
|
||||
assert self.get_image_priority(image2) == Priority.Normal, "image2's priority should be 'Priority.Normal'"
|
||||
|
||||
# WHEN: Add more images.
|
||||
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.
|
||||
time.sleep(0.1)
|
||||
# THEN: The images' priority reflect how they were processed.
|
||||
self.assertEqual(self.image_manager._conversion_queue.qsize(), 0, "The queue should be empty.")
|
||||
self.assertEqual(self.get_image_priority(image1), Priority.Lowest,
|
||||
"The image should have not been requested (=Lowest)")
|
||||
self.assertEqual(self.get_image_priority(image2), Priority.Lowest,
|
||||
"The image should have not been requested (=Lowest)")
|
||||
self.assertEqual(self.get_image_priority(image3), Priority.Low,
|
||||
"Only the QImage should have been requested (=Low).")
|
||||
self.assertEqual(self.get_image_priority(image4), Priority.Urgent,
|
||||
"The image bytes should have been requested (=Urgent).")
|
||||
assert self.image_manager._conversion_queue.qsize() == 0, "The queue should be empty."
|
||||
assert self.get_image_priority(image1) == Priority.Lowest, \
|
||||
"The image should have not been requested (=Lowest)"
|
||||
assert self.get_image_priority(image2) == Priority.Lowest, \
|
||||
"The image should have not been requested (=Lowest)"
|
||||
assert self.get_image_priority(image3) == Priority.Low, \
|
||||
"Only the QImage should have been requested (=Low)."
|
||||
assert self.get_image_priority(image4) == Priority.Urgent, \
|
||||
"The image bytes should have been requested (=Urgent)."
|
||||
|
||||
def get_image_priority(self, image):
|
||||
"""
|
||||
|
|
|
@ -49,8 +49,8 @@ class TestLib(TestCase):
|
|||
true_result = str_to_bool(true_boolean)
|
||||
|
||||
# THEN: We should get back a True bool
|
||||
self.assertIsInstance(true_result, bool, 'The result should be a boolean')
|
||||
self.assertTrue(true_result, 'The result should be True')
|
||||
assert isinstance(true_result, bool), 'The result should be a boolean'
|
||||
assert true_result is True, 'The result should be True'
|
||||
|
||||
def test_str_to_bool_with_bool_false(self):
|
||||
"""
|
||||
|
@ -63,8 +63,8 @@ class TestLib(TestCase):
|
|||
false_result = str_to_bool(false_boolean)
|
||||
|
||||
# THEN: We should get back a True bool
|
||||
self.assertIsInstance(false_result, bool, 'The result should be a boolean')
|
||||
self.assertFalse(false_result, 'The result should be True')
|
||||
assert isinstance(false_result, bool), 'The result should be a boolean'
|
||||
assert false_result is False, 'The result should be True'
|
||||
|
||||
def test_str_to_bool_with_integer(self):
|
||||
"""
|
||||
|
@ -77,7 +77,7 @@ class TestLib(TestCase):
|
|||
int_result = str_to_bool(int_string)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -90,7 +90,7 @@ class TestLib(TestCase):
|
|||
str_result = str_to_bool(invalid_string)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -103,7 +103,7 @@ class TestLib(TestCase):
|
|||
false_result = str_to_bool(false_string)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -116,7 +116,7 @@ class TestLib(TestCase):
|
|||
str_result = str_to_bool(no_string)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -129,7 +129,7 @@ class TestLib(TestCase):
|
|||
true_result = str_to_bool(true_string)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -142,7 +142,7 @@ class TestLib(TestCase):
|
|||
str_result = str_to_bool(yes_string)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -157,7 +157,7 @@ class TestLib(TestCase):
|
|||
|
||||
# THEN: The result should be False
|
||||
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):
|
||||
"""
|
||||
|
@ -176,7 +176,7 @@ class TestLib(TestCase):
|
|||
# THEN: None should be returned
|
||||
file_path.is_file.assert_called_once_with()
|
||||
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):
|
||||
"""
|
||||
|
@ -195,7 +195,7 @@ class TestLib(TestCase):
|
|||
result = build_icon(icon)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -217,7 +217,7 @@ class TestLib(TestCase):
|
|||
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
|
||||
# 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):
|
||||
"""
|
||||
|
@ -240,8 +240,8 @@ class TestLib(TestCase):
|
|||
MockedQtCore.QBuffer.assert_called_with(mocked_byte_array)
|
||||
mocked_buffer.open.assert_called_with('writeonly')
|
||||
mocked_image.save.assert_called_with(mocked_buffer, "PNG")
|
||||
self.assertFalse(mocked_byte_array.toBase64.called)
|
||||
self.assertEqual(mocked_byte_array, result, 'The mocked out byte array should be returned')
|
||||
assert mocked_byte_array.toBase64.called is False
|
||||
assert mocked_byte_array == result, 'The mocked out byte array should be returned'
|
||||
|
||||
def test_image_to_byte_base_64(self):
|
||||
"""
|
||||
|
@ -266,8 +266,7 @@ class TestLib(TestCase):
|
|||
mocked_buffer.open.assert_called_with('writeonly')
|
||||
mocked_image.save.assert_called_with(mocked_buffer, "PNG")
|
||||
mocked_byte_array.toBase64.assert_called_with()
|
||||
self.assertEqual('base64mock', result, 'The result should be the return value of the mocked out '
|
||||
'base64 method')
|
||||
assert 'base64mock' == result, 'The result should be the return value of the mocked out base64 method'
|
||||
|
||||
def test_create_thumb_with_size(self):
|
||||
"""
|
||||
|
@ -286,16 +285,16 @@ class TestLib(TestCase):
|
|||
pass
|
||||
|
||||
# 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.
|
||||
icon = create_thumb(image_path, thumb_path, size=thumb_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.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon')
|
||||
self.assertFalse(icon.isNull(), 'The icon should not be null')
|
||||
self.assertEqual(thumb_size, QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size')
|
||||
assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon'
|
||||
assert icon.isNull() is False, 'The icon should not be null'
|
||||
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.
|
||||
try:
|
||||
|
@ -320,17 +319,16 @@ class TestLib(TestCase):
|
|||
pass
|
||||
|
||||
# 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.
|
||||
icon = create_thumb(image_path, thumb_path)
|
||||
|
||||
# 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.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon')
|
||||
self.assertFalse(icon.isNull(), 'The icon should not be null')
|
||||
self.assertEqual(expected_size, QtGui.QImageReader(str(thumb_path)).size(),
|
||||
'The thumb should have the given size')
|
||||
assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon'
|
||||
assert icon.isNull() is False, 'The icon should not be null'
|
||||
assert 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.
|
||||
try:
|
||||
|
@ -356,17 +354,16 @@ class TestLib(TestCase):
|
|||
pass
|
||||
|
||||
# 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.
|
||||
icon = create_thumb(image_path, thumb_path, size=thumb_size)
|
||||
|
||||
# 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.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon')
|
||||
self.assertFalse(icon.isNull(), 'The icon should not be null')
|
||||
self.assertEqual(expected_size, QtGui.QImageReader(str(thumb_path)).size(),
|
||||
'The thumb should have the given size')
|
||||
assert thumb_path.exists() is True, 'Test was not ran, because the thumb already exists'
|
||||
assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon'
|
||||
assert icon.isNull() is False, 'The icon should not be null'
|
||||
assert 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.
|
||||
try:
|
||||
|
@ -392,17 +389,16 @@ class TestLib(TestCase):
|
|||
pass
|
||||
|
||||
# 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.
|
||||
icon = create_thumb(image_path, thumb_path, size=thumb_size)
|
||||
|
||||
# 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.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon')
|
||||
self.assertFalse(icon.isNull(), 'The icon should not be null')
|
||||
self.assertEqual(
|
||||
expected_size, QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size')
|
||||
assert thumb_path.exists() is True, 'Test was not ran, because the thumb already exists'
|
||||
assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon'
|
||||
assert icon.isNull() is False, 'The icon should not be null'
|
||||
assert 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.
|
||||
try:
|
||||
|
@ -428,17 +424,16 @@ class TestLib(TestCase):
|
|||
pass
|
||||
|
||||
# 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.
|
||||
icon = create_thumb(image_path, thumb_path, size=thumb_size)
|
||||
|
||||
# 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.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon')
|
||||
self.assertFalse(icon.isNull(), 'The icon should not be null')
|
||||
self.assertEqual(
|
||||
expected_size, QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size')
|
||||
assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon'
|
||||
assert icon.isNull() is False, 'The icon should not be null'
|
||||
assert 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.
|
||||
try:
|
||||
|
@ -465,7 +460,7 @@ class TestLib(TestCase):
|
|||
pass
|
||||
|
||||
# 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.
|
||||
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.
|
||||
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')
|
||||
self.assertFalse(icon.isNull(), 'The icon should not be null')
|
||||
self.assertEqual(
|
||||
expected_size_1, QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size')
|
||||
assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon'
|
||||
assert icon.isNull() is False, 'The icon should not be null'
|
||||
assert expected_size_1 == QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size'
|
||||
|
||||
# WHEN: Create the thumb.
|
||||
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)
|
||||
|
||||
# THEN: Check if the thumb was created with aspect ratio of 1.
|
||||
self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon')
|
||||
self.assertFalse(icon.isNull(), 'The icon should not be null')
|
||||
self.assertEqual(
|
||||
expected_size_2, QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size')
|
||||
assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon'
|
||||
assert icon.isNull() is False, 'The icon should not be null'
|
||||
assert 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.
|
||||
try:
|
||||
|
@ -511,7 +504,7 @@ class TestLib(TestCase):
|
|||
|
||||
# THEN: The selectedIndexes function should have been called and the result should be true
|
||||
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):
|
||||
"""
|
||||
|
@ -532,7 +525,7 @@ class TestLib(TestCase):
|
|||
# THEN: The selectedIndexes function should have been called and the result should be true
|
||||
mocked_list_widget.selectedIndexes.assert_called_with()
|
||||
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):
|
||||
"""
|
||||
|
@ -554,7 +547,7 @@ class TestLib(TestCase):
|
|||
result_string = clean_tags(string_to_pass)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -593,7 +586,7 @@ class TestLib(TestCase):
|
|||
result_string = expand_tags(string_to_pass)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -609,7 +602,7 @@ class TestLib(TestCase):
|
|||
|
||||
# THEN: we should have called a few functions, and the result should be False
|
||||
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):
|
||||
"""
|
||||
|
@ -624,7 +617,7 @@ class TestLib(TestCase):
|
|||
result = validate_thumb(file_path, thumb_path)
|
||||
|
||||
# THEN: `validate_thumb` should return True
|
||||
self.assertTrue(result)
|
||||
assert result is True
|
||||
|
||||
def test_validate_thumb_file_exists_and_older(self):
|
||||
"""
|
||||
|
@ -639,7 +632,7 @@ class TestLib(TestCase):
|
|||
|
||||
# THEN: `validate_thumb` should return False
|
||||
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):
|
||||
"""
|
||||
|
@ -658,9 +651,9 @@ class TestLib(TestCase):
|
|||
|
||||
# THEN: Check if the size is correct and the background was set.
|
||||
result_size = image.size()
|
||||
self.assertEqual(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.')
|
||||
self.assertEqual(image.pixel(0, 0), wanted_background_rgb, 'The background should be white.')
|
||||
assert wanted_height == result_size.height(), 'The image should have the requested height.'
|
||||
assert wanted_width == result_size.width(), 'The image should have the requested width.'
|
||||
assert image.pixel(0, 0) == wanted_background_rgb, 'The background should be white.'
|
||||
|
||||
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.
|
||||
result_size = image.size()
|
||||
self.assertEqual(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.')
|
||||
self.assertEqual(image.pixel(0, 0), wanted_background_rgb, 'The background should be white.')
|
||||
assert wanted_height == result_size.height(), 'The image should have the requested height.'
|
||||
assert wanted_width == result_size.width(), 'The image should have the requested width.'
|
||||
assert image.pixel(0, 0) == wanted_background_rgb, 'The background should be white.'
|
||||
|
||||
@patch('openlp.core.lib.QtCore.QLocale.createSeparatedList')
|
||||
def test_create_separated_list_qlocate(self, mocked_createSeparatedList):
|
||||
|
@ -696,8 +689,8 @@ class TestLib(TestCase):
|
|||
string_result = create_separated_list(string_list)
|
||||
|
||||
# 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, '
|
||||
'Author 2, and Author 3".')
|
||||
assert string_result == 'Author 1, Author 2 and Author 3', \
|
||||
'The string should be "Author 1, Author 2, and Author 3".'
|
||||
|
||||
def test_create_separated_list_empty_list(self):
|
||||
"""
|
||||
|
@ -710,7 +703,7 @@ class TestLib(TestCase):
|
|||
string_result = create_separated_list(string_list)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -723,7 +716,7 @@ class TestLib(TestCase):
|
|||
string_result = create_separated_list(string_list)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -736,7 +729,7 @@ class TestLib(TestCase):
|
|||
string_result = create_separated_list(string_list)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -749,8 +742,8 @@ class TestLib(TestCase):
|
|||
string_result = create_separated_list(string_list)
|
||||
|
||||
# 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, '
|
||||
'Author 2, and Author 3".')
|
||||
assert string_result == 'Author 1, Author 2 and Author 3', \
|
||||
'The string should be "Author 1, Author 2, and Author 3".'
|
||||
|
||||
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>' \
|
||||
'</span>alleluya.<span class="chord"><span><strong>F</strong></span></span><span class="ws">' \
|
||||
' </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):
|
||||
"""
|
||||
|
@ -782,7 +775,7 @@ class TestLib(TestCase):
|
|||
expected_html = '<span class="chordline firstchordline">I<span class="chord"><span><strong>D</strong></span>' \
|
||||
'</span>'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>'
|
||||
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):
|
||||
"""
|
||||
|
@ -810,7 +803,7 @@ class TestLib(TestCase):
|
|||
ret = compare_chord_lyric(chord, lyrics)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -825,7 +818,7 @@ class TestLib(TestCase):
|
|||
active_tags = find_formatting_tags(lyrics, tags)
|
||||
|
||||
# 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):
|
||||
"""
|
||||
|
@ -862,4 +855,4 @@ class TestLib(TestCase):
|
|||
'<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} </td>' \
|
||||
'</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!'
|
||||
|
|
|
@ -69,11 +69,11 @@ class TestMediaManagerItem(TestCase, TestMixin):
|
|||
# WHEN: Object is created
|
||||
mmi.required_icons()
|
||||
# THEN: Default icons should be populated
|
||||
self.assertFalse(mmi.has_import_icon, 'There should be no import icon by default')
|
||||
self.assertTrue(mmi.has_new_icon, 'By default a new icon should be present')
|
||||
self.assertFalse(mmi.has_file_icon, 'There should be no file icon by default')
|
||||
self.assertTrue(mmi.has_delete_icon, 'By default a delete icon should be present')
|
||||
self.assertFalse(mmi.add_to_service_item, 'There should be no add_to_service icon by default')
|
||||
assert mmi.has_import_icon is False, 'There should be no import icon by default'
|
||||
assert mmi.has_new_icon is True, 'By default a new icon should be present'
|
||||
assert mmi.has_file_icon is False, 'There should be no file icon by default'
|
||||
assert mmi.has_delete_icon is True, 'By default a delete icon should be present'
|
||||
assert mmi.add_to_service_item is False, 'There should be no add_to_service icon by default'
|
||||
|
||||
@patch('openlp.core.lib.mediamanageritem.Settings')
|
||||
@patch('openlp.core.lib.mediamanageritem.MediaManagerItem.on_live_click')
|
||||
|
@ -111,5 +111,5 @@ class TestMediaManagerItem(TestCase, TestMixin):
|
|||
mmi.on_double_clicked()
|
||||
|
||||
# THEN: on_live_click() should have been called
|
||||
self.assertEqual(0, mocked_on_live_click.call_count, 'on_live_click() should not have been called')
|
||||
self.assertEqual(0, mocked_on_preview_click.call_count, 'on_preview_click() should not have been called')
|
||||
assert 0 == mocked_on_live_click.call_count, 'on_live_click() should not have been called'
|
||||
assert 0 == mocked_on_preview_click.call_count, 'on_preview_click() should not have been called'
|
||||
|
|
|
@ -64,8 +64,8 @@ class TestPluginManager(TestCase):
|
|||
plugin_manager.hook_media_manager()
|
||||
|
||||
# THEN: The create_media_manager_item() method should have been called
|
||||
self.assertEqual(0, mocked_plugin.create_media_manager_item.call_count,
|
||||
'The create_media_manager_item() method should not have been called.')
|
||||
assert 0 == mocked_plugin.create_media_manager_item.call_count, \
|
||||
'The create_media_manager_item() method should not have been called.'
|
||||
|
||||
def test_hook_media_manager_with_active_plugin(self):
|
||||
"""
|
||||
|
@ -97,8 +97,8 @@ class TestPluginManager(TestCase):
|
|||
plugin_manager.hook_settings_tabs()
|
||||
|
||||
# THEN: The hook_settings_tabs() method should have been called
|
||||
self.assertEqual(0, mocked_plugin.create_media_manager_item.call_count,
|
||||
'The create_media_manager_item() method should not have been called.')
|
||||
assert 0 == mocked_plugin.create_media_manager_item.call_count, \
|
||||
'The create_media_manager_item() method should not have been called.'
|
||||
|
||||
def test_hook_settings_tabs_with_disabled_plugin_and_mocked_form(self):
|
||||
"""
|
||||
|
@ -117,10 +117,10 @@ class TestPluginManager(TestCase):
|
|||
plugin_manager.hook_settings_tabs()
|
||||
|
||||
# THEN: The create_settings_tab() method should not have been called, but the plugins lists should be the same
|
||||
self.assertEqual(0, mocked_plugin.create_settings_tab.call_count,
|
||||
'The create_media_manager_item() method should not have been called.')
|
||||
self.assertEqual(mocked_settings_form.plugin_manager.plugins, plugin_manager.plugins,
|
||||
'The plugins on the settings form should be the same as the plugins in the plugin manager')
|
||||
assert 0 == mocked_plugin.create_settings_tab.call_count, \
|
||||
'The create_media_manager_item() method should not have been called.'
|
||||
assert mocked_settings_form.plugin_manager.plugins == plugin_manager.plugins, \
|
||||
'The plugins on the settings form should be the same as the plugins in the plugin manager'
|
||||
|
||||
def test_hook_settings_tabs_with_active_plugin_and_mocked_form(self):
|
||||
"""
|
||||
|
@ -139,10 +139,10 @@ class TestPluginManager(TestCase):
|
|||
plugin_manager.hook_settings_tabs()
|
||||
|
||||
# THEN: The create_media_manager_item() method should have been called with the mocked settings form
|
||||
self.assertEqual(1, mocked_plugin.create_settings_tab.call_count,
|
||||
'The create_media_manager_item() method should have been called once.')
|
||||
self.assertEqual(plugin_manager.plugins, mocked_settings_form.plugin_manager.plugins,
|
||||
'The plugins on the settings form should be the same as the plugins in the plugin manager')
|
||||
assert 1 == mocked_plugin.create_settings_tab.call_count, \
|
||||
'The create_media_manager_item() method should have been called once.'
|
||||
assert plugin_manager.plugins == mocked_settings_form.plugin_manager.plugins, \
|
||||
'The plugins on the settings form should be the same as the plugins in the plugin manager'
|
||||
|
||||
def test_hook_settings_tabs_with_active_plugin_and_no_form(self):
|
||||
"""
|
||||
|
@ -174,8 +174,8 @@ class TestPluginManager(TestCase):
|
|||
plugin_manager.hook_import_menu()
|
||||
|
||||
# THEN: The create_media_manager_item() method should have been called
|
||||
self.assertEqual(0, mocked_plugin.add_import_menu_item.call_count,
|
||||
'The add_import_menu_item() method should not have been called.')
|
||||
assert 0 == mocked_plugin.add_import_menu_item.call_count, \
|
||||
'The add_import_menu_item() method should not have been called.'
|
||||
|
||||
def test_hook_import_menu_with_active_plugin(self):
|
||||
"""
|
||||
|
@ -207,8 +207,8 @@ class TestPluginManager(TestCase):
|
|||
plugin_manager.hook_export_menu()
|
||||
|
||||
# THEN: The add_export_menu_item() method should not have been called
|
||||
self.assertEqual(0, mocked_plugin.add_export_menu_item.call_count,
|
||||
'The add_export_menu_item() method should not have been called.')
|
||||
assert 0 == mocked_plugin.add_export_menu_item.call_count, \
|
||||
'The add_export_menu_item() method should not have been called.'
|
||||
|
||||
def test_hook_export_menu_with_active_plugin(self):
|
||||
"""
|
||||
|
@ -241,8 +241,8 @@ class TestPluginManager(TestCase):
|
|||
plugin_manager.hook_upgrade_plugin_settings(settings)
|
||||
|
||||
# THEN: The upgrade_settings() method should not have been called
|
||||
self.assertEqual(0, mocked_plugin.upgrade_settings.call_count,
|
||||
'The upgrade_settings() method should not have been called.')
|
||||
assert 0 == mocked_plugin.upgrade_settings.call_count, \
|
||||
'The upgrade_settings() method should not have been called.'
|
||||
|
||||
def test_hook_upgrade_plugin_settings_with_active_plugin(self):
|
||||
"""
|
||||
|
@ -275,8 +275,8 @@ class TestPluginManager(TestCase):
|
|||
plugin_manager.hook_tools_menu()
|
||||
|
||||
# THEN: The add_tools_menu_item() method should have been called
|
||||
self.assertEqual(0, mocked_plugin.add_tools_menu_item.call_count,
|
||||
'The add_tools_menu_item() method should not have been called.')
|
||||
assert 0 == mocked_plugin.add_tools_menu_item.call_count, \
|
||||
'The add_tools_menu_item() method should not have been called.'
|
||||
|
||||
def test_hook_tools_menu_with_active_plugin(self):
|
||||
"""
|
||||
|
@ -310,7 +310,7 @@ class TestPluginManager(TestCase):
|
|||
|
||||
# THEN: The is_active() method should have been called, and initialise() method should NOT have been called
|
||||
mocked_plugin.is_active.assert_called_with()
|
||||
self.assertEqual(0, mocked_plugin.initialise.call_count, 'The initialise() method should not have been called.')
|
||||
assert 0 == mocked_plugin.initialise.call_count, 'The initialise() method should not have been called.'
|
||||
|
||||
def test_initialise_plugins_with_active_plugin(self):
|
||||
"""
|
||||
|
@ -346,7 +346,7 @@ class TestPluginManager(TestCase):
|
|||
|
||||
# THEN: The is_active() method should have been called, and initialise() method should NOT have been called
|
||||
mocked_plugin.is_active.assert_called_with()
|
||||
self.assertEqual(0, mocked_plugin.finalise.call_count, 'The finalise() method should not have been called.')
|
||||
assert 0 == mocked_plugin.finalise.call_count, 'The finalise() method should not have been called.'
|
||||
|
||||
def test_finalise_plugins_with_active_plugin(self):
|
||||
"""
|
||||
|
@ -380,7 +380,7 @@ class TestPluginManager(TestCase):
|
|||
result = plugin_manager.get_plugin_by_name('Missing Plugin')
|
||||
|
||||
# THEN: The is_active() and finalise() methods should have been called
|
||||
self.assertIsNone(result, 'The result for get_plugin_by_name should be None')
|
||||
assert result is None, 'The result for get_plugin_by_name should be None'
|
||||
|
||||
def test_get_plugin_by_name_exists(self):
|
||||
"""
|
||||
|
@ -396,7 +396,7 @@ class TestPluginManager(TestCase):
|
|||
result = plugin_manager.get_plugin_by_name('Mocked Plugin')
|
||||
|
||||
# THEN: The is_active() and finalise() methods should have been called
|
||||
self.assertEqual(result, mocked_plugin, 'The result for get_plugin_by_name should be the mocked plugin')
|
||||
assert result == mocked_plugin, 'The result for get_plugin_by_name should be the mocked plugin'
|
||||
|
||||
def test_new_service_created_with_disabled_plugin(self):
|
||||
"""
|
||||
|
@ -414,8 +414,8 @@ class TestPluginManager(TestCase):
|
|||
|
||||
# THEN: The isActive() method should have been called, and initialise() method should NOT have been called
|
||||
mocked_plugin.is_active.assert_called_with()
|
||||
self.assertEqual(0, mocked_plugin.new_service_created.call_count,
|
||||
'The new_service_created() method should not have been called.')
|
||||
assert 0 == mocked_plugin.new_service_created.call_count, \
|
||||
'The new_service_created() method should not have been called.'
|
||||
|
||||
def test_new_service_created_with_active_plugin(self):
|
||||
"""
|
||||
|
|
|
@ -28,7 +28,9 @@ from unittest.mock import MagicMock, patch
|
|||
|
||||
from openlp.core.common import md5_hash
|
||||
from openlp.core.common.registry import Registry
|
||||
from openlp.core.common.settings import Settings
|
||||
from openlp.core.lib import ItemCapabilities, ServiceItem, ServiceItemType, FormattingTags
|
||||
from tests.helpers.testmixin import TestMixin
|
||||
|
||||
from tests.utils import assert_length, convert_file_service_item
|
||||
|
||||
|
@ -59,19 +61,31 @@ RENDERED_VERSE = 'The Lord said to <span style="-webkit-text-fill-color:red">Noa
|
|||
FOOTER = ['Arky Arky (Unknown)', 'Public Domain', 'CCLI 123456']
|
||||
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'service'))
|
||||
|
||||
__default_settings__ = {
|
||||
'songs/enable chords': True,
|
||||
}
|
||||
|
||||
class TestServiceItem(TestCase):
|
||||
|
||||
class TestServiceItem(TestCase, TestMixin):
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
Set up the Registry
|
||||
"""
|
||||
self.build_settings()
|
||||
Settings().extend_default_settings(__default_settings__)
|
||||
Registry.create()
|
||||
mocked_renderer = MagicMock()
|
||||
mocked_renderer.format_slide.return_value = [VERSE]
|
||||
Registry().register('renderer', mocked_renderer)
|
||||
Registry().register('image_manager', MagicMock())
|
||||
|
||||
def tearDown(self):
|
||||
"""
|
||||
Clean up
|
||||
"""
|
||||
self.destroy_settings()
|
||||
|
||||
def test_service_item_basic(self):
|
||||
"""
|
||||
Test the Service Item - basic test
|
||||
|
@ -82,8 +96,8 @@ class TestServiceItem(TestCase):
|
|||
service_item = ServiceItem(None)
|
||||
|
||||
# THEN: We should get back a valid service item
|
||||
self.assertTrue(service_item.is_valid, 'The new service item should be valid')
|
||||
self.assertTrue(service_item.missing_frames(), 'There should not be any frames in the service item')
|
||||
assert service_item.is_valid is True, 'The new service item should be valid'
|
||||
assert service_item.missing_frames() is True, 'There should not be any frames in the service item'
|
||||
|
||||
def test_service_item_load_custom_from_service(self):
|
||||
"""
|
||||
|
@ -99,7 +113,7 @@ class TestServiceItem(TestCase):
|
|||
service_item.set_from_service(line)
|
||||
|
||||
# THEN: We should get back a valid service item
|
||||
self.assertTrue(service_item.is_valid, 'The new service item should be valid')
|
||||
assert service_item.is_valid is True, 'The new service item should be valid'
|
||||
assert_length(0, service_item._display_frames, 'The service item should have no display frames')
|
||||
assert_length(5, service_item.capabilities, 'There should be 5 default custom item capabilities')
|
||||
|
||||
|
@ -107,14 +121,14 @@ class TestServiceItem(TestCase):
|
|||
service_item.render(True)
|
||||
|
||||
# THEN: The frames should also be valid
|
||||
self.assertEqual('Test Custom', service_item.get_display_title(), 'The title should be "Test Custom"')
|
||||
self.assertEqual(CLEANED_VERSE[:-1], service_item.get_frames()[0]['text'],
|
||||
'The returned text matches the input, except the last line feed')
|
||||
self.assertEqual(RENDERED_VERSE.split('\n', 1)[0], service_item.get_rendered_frame(1),
|
||||
'The first line has been returned')
|
||||
self.assertEqual('Slide 1', service_item.get_frame_title(0), '"Slide 1" has been returned as the title')
|
||||
self.assertEqual('Slide 2', service_item.get_frame_title(1), '"Slide 2" has been returned as the title')
|
||||
self.assertEqual('', service_item.get_frame_title(2), 'Blank has been returned as the title of slide 3')
|
||||
assert 'Test Custom' == service_item.get_display_title(), 'The title should be "Test Custom"'
|
||||
assert CLEANED_VERSE[:-1] == service_item.get_frames()[0]['text'], \
|
||||
'The returned text matches the input, except the last line feed'
|
||||
assert RENDERED_VERSE.split('\n', 1)[0] == service_item.get_rendered_frame(1), \
|
||||
'The first line has been returned'
|
||||
assert 'Slide 1' == service_item.get_frame_title(0), '"Slide 1" has been returned as the title'
|
||||
assert 'Slide 2' == service_item.get_frame_title(1), '"Slide 2" has been returned as the title'
|
||||
assert '' == service_item.get_frame_title(2), 'Blank has been returned as the title of slide 3'
|
||||
|
||||
def test_service_item_load_image_from_service(self):
|
||||
"""
|
||||
|
@ -138,26 +152,22 @@ class TestServiceItem(TestCase):
|
|||
service_item.set_from_service(line, TEST_PATH)
|
||||
|
||||
# THEN: We should get back a valid service item
|
||||
self.assertTrue(service_item.is_valid, 'The new service item should be valid')
|
||||
self.assertEqual(os.path.normpath(test_file), os.path.normpath(service_item.get_rendered_frame(0)),
|
||||
'The first frame should match the path to the image')
|
||||
self.assertEqual(frame_array, service_item.get_frames()[0],
|
||||
'The return should match frame array1')
|
||||
self.assertEqual(test_file, service_item.get_frame_path(0),
|
||||
'The frame path should match the full path to the image')
|
||||
self.assertEqual(image_name, service_item.get_frame_title(0),
|
||||
'The frame title should match the image name')
|
||||
self.assertEqual(image_name, service_item.get_display_title(),
|
||||
'The display title should match the first image name')
|
||||
self.assertTrue(service_item.is_image(), 'This service item should be of an "image" type')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanMaintain),
|
||||
'This service item should be able to be Maintained')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanPreview),
|
||||
'This service item should be able to be be Previewed')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanLoop),
|
||||
'This service item should be able to be run in a can be made to Loop')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanAppend),
|
||||
'This service item should be able to have new items added to it')
|
||||
assert service_item.is_valid is True, 'The new service item should be valid'
|
||||
assert os.path.normpath(test_file) == os.path.normpath(service_item.get_rendered_frame(0)), \
|
||||
'The first frame should match the path to the image'
|
||||
assert frame_array == service_item.get_frames()[0], 'The return should match frame array1'
|
||||
assert test_file == service_item.get_frame_path(0), 'The frame path should match the full path to the image'
|
||||
assert image_name == service_item.get_frame_title(0), 'The frame title should match the image name'
|
||||
assert image_name == service_item.get_display_title(), 'The display title should match the first image name'
|
||||
assert service_item.is_image() is True, 'This service item should be of an "image" type'
|
||||
assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, \
|
||||
'This service item should be able to be Maintained'
|
||||
assert service_item.is_capable(ItemCapabilities.CanPreview) is True, \
|
||||
'This service item should be able to be be Previewed'
|
||||
assert service_item.is_capable(ItemCapabilities.CanLoop) is True, \
|
||||
'This service item should be able to be run in a can be made to Loop'
|
||||
assert service_item.is_capable(ItemCapabilities.CanAppend) is True, \
|
||||
'This service item should be able to have new items added to it'
|
||||
|
||||
def test_service_item_load_image_from_local_service(self):
|
||||
"""
|
||||
|
@ -193,35 +203,33 @@ class TestServiceItem(TestCase):
|
|||
|
||||
# This test is copied from service_item.py, but is changed since to conform to
|
||||
# new layout of service item. The layout use in serviceitem_image_2.osd is actually invalid now.
|
||||
self.assertTrue(service_item.is_valid, 'The first service item should be valid')
|
||||
self.assertTrue(service_item2.is_valid, 'The second service item should be valid')
|
||||
assert service_item.is_valid is True, 'The first service item should be valid'
|
||||
assert service_item2.is_valid is True, 'The second service item should be valid'
|
||||
# These test will fail on windows due to the difference in folder seperators
|
||||
if os.name != 'nt':
|
||||
self.assertEqual(test_file1, service_item.get_rendered_frame(0),
|
||||
'The first frame should match the path to the image')
|
||||
self.assertEqual(test_file2, service_item2.get_rendered_frame(0),
|
||||
'The Second frame should match the path to the image')
|
||||
self.assertEqual(frame_array1, service_item.get_frames()[0], 'The return should match the frame array1')
|
||||
self.assertEqual(frame_array2, service_item2.get_frames()[0], 'The return should match the frame array2')
|
||||
self.assertEqual(test_file1, service_item.get_frame_path(0),
|
||||
'The frame path should match the full path to the image')
|
||||
self.assertEqual(test_file2, service_item2.get_frame_path(0),
|
||||
'The frame path should match the full path to the image')
|
||||
self.assertEqual(image_name1, service_item.get_frame_title(0),
|
||||
'The 1st frame title should match the image name')
|
||||
self.assertEqual(image_name2, service_item2.get_frame_title(0),
|
||||
'The 2nd frame title should match the image name')
|
||||
self.assertEqual(service_item.name, service_item.title.lower(),
|
||||
'The plugin name should match the display title, as there are > 1 Images')
|
||||
self.assertTrue(service_item.is_image(), 'This service item should be of an "image" type')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanMaintain),
|
||||
'This service item should be able to be Maintained')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanPreview),
|
||||
'This service item should be able to be be Previewed')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanLoop),
|
||||
'This service item should be able to be run in a can be made to Loop')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanAppend),
|
||||
'This service item should be able to have new items added to it')
|
||||
assert test_file1 == service_item.get_rendered_frame(0), \
|
||||
'The first frame should match the path to the image'
|
||||
assert test_file2 == service_item2.get_rendered_frame(0), \
|
||||
'The Second frame should match the path to the image'
|
||||
assert frame_array1 == service_item.get_frames()[0], 'The return should match the frame array1'
|
||||
assert frame_array2 == service_item2.get_frames()[0], 'The return should match the frame array2'
|
||||
assert test_file1 == service_item.get_frame_path(0), \
|
||||
'The frame path should match the full path to the image'
|
||||
assert test_file2 == service_item2.get_frame_path(0), \
|
||||
'The frame path should match the full path to the image'
|
||||
assert image_name1 == service_item.get_frame_title(0), 'The 1st frame title should match the image name'
|
||||
assert image_name2 == service_item2.get_frame_title(0), 'The 2nd frame title should match the image name'
|
||||
assert service_item.name == service_item.title.lower(), \
|
||||
'The plugin name should match the display title, as there are > 1 Images'
|
||||
assert service_item.is_image() is True, 'This service item should be of an "image" type'
|
||||
assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, \
|
||||
'This service item should be able to be Maintained'
|
||||
assert service_item.is_capable(ItemCapabilities.CanPreview) is True, \
|
||||
'This service item should be able to be be Previewed'
|
||||
assert service_item.is_capable(ItemCapabilities.CanLoop) is True, \
|
||||
'This service item should be able to be run in a can be made to Loop'
|
||||
assert service_item.is_capable(ItemCapabilities.CanAppend) is True, \
|
||||
'This service item should be able to have new items added to it'
|
||||
|
||||
def test_add_from_command_for_a_presentation(self):
|
||||
"""
|
||||
|
@ -240,8 +248,8 @@ class TestServiceItem(TestCase):
|
|||
service_item.add_from_command(TEST_PATH, presentation_name, image, display_title, notes)
|
||||
|
||||
# THEN: verify that it is setup as a Command and that the frame data matches
|
||||
self.assertEqual(service_item.service_item_type, ServiceItemType.Command, 'It should be a Command')
|
||||
self.assertEqual(service_item.get_frames()[0], frame, 'Frames should match')
|
||||
assert service_item.service_item_type == ServiceItemType.Command, 'It should be a Command'
|
||||
assert service_item.get_frames()[0] == frame, 'Frames should match'
|
||||
|
||||
def test_add_from_comamnd_without_display_title_and_notes(self):
|
||||
"""
|
||||
|
@ -258,8 +266,8 @@ class TestServiceItem(TestCase):
|
|||
service_item.add_from_command(TEST_PATH, image_name, image)
|
||||
|
||||
# THEN: verify that it is setup as a Command and that the frame data matches
|
||||
self.assertEqual(service_item.service_item_type, ServiceItemType.Command, 'It should be a Command')
|
||||
self.assertEqual(service_item.get_frames()[0], frame, 'Frames should match')
|
||||
assert service_item.service_item_type == ServiceItemType.Command, 'It should be a Command'
|
||||
assert service_item.get_frames()[0] == frame, 'Frames should match'
|
||||
|
||||
@patch(u'openlp.core.lib.serviceitem.ServiceItem.image_manager')
|
||||
@patch('openlp.core.lib.serviceitem.AppLocation.get_section_data_path')
|
||||
|
@ -287,9 +295,9 @@ class TestServiceItem(TestCase):
|
|||
service_item.add_from_command(TEST_PATH, presentation_name, thumb, display_title, notes)
|
||||
|
||||
# THEN: verify that it is setup as a Command and that the frame data matches
|
||||
self.assertEqual(service_item.service_item_type, ServiceItemType.Command, 'It should be a Command')
|
||||
self.assertEqual(service_item.get_frames()[0], frame, 'Frames should match')
|
||||
self.assertEqual(1, mocked_image_manager.add_image.call_count, 'image_manager should be used')
|
||||
assert service_item.service_item_type == ServiceItemType.Command, 'It should be a Command'
|
||||
assert service_item.get_frames()[0] == frame, 'Frames should match'
|
||||
assert 1 == mocked_image_manager.add_image.call_count, 'image_manager should be used'
|
||||
|
||||
def test_service_item_load_optical_media_from_service(self):
|
||||
"""
|
||||
|
@ -306,11 +314,11 @@ class TestServiceItem(TestCase):
|
|||
service_item.set_from_service(line)
|
||||
|
||||
# THEN: We should get back a valid service item with optical media info
|
||||
self.assertTrue(service_item.is_valid, 'The service item should be valid')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.IsOptical), 'The item should be Optical')
|
||||
self.assertEqual(service_item.start_time, 654.375, 'Start time should be 654.375')
|
||||
self.assertEqual(service_item.end_time, 672.069, 'End time should be 672.069')
|
||||
self.assertEqual(service_item.media_length, 17.694, 'Media length should be 17.694')
|
||||
assert service_item.is_valid is True, 'The service item should be valid'
|
||||
assert service_item.is_capable(ItemCapabilities.IsOptical) is True, 'The item should be Optical'
|
||||
assert service_item.start_time == 654.375, 'Start time should be 654.375'
|
||||
assert service_item.end_time == 672.069, 'End time should be 672.069'
|
||||
assert service_item.media_length == 17.694, 'Media length should be 17.694'
|
||||
|
||||
def test_service_item_load_song_and_audio_from_service(self):
|
||||
"""
|
||||
|
@ -326,22 +334,22 @@ class TestServiceItem(TestCase):
|
|||
service_item.set_from_service(line, '/test/')
|
||||
|
||||
# THEN: We should get back a valid service item
|
||||
self.assertTrue(service_item.is_valid, 'The new service item should be valid')
|
||||
assert_length(0, service_item._display_frames, 'The service item should have no display frames')
|
||||
assert_length(7, service_item.capabilities, 'There should be 7 default custom item capabilities')
|
||||
assert service_item.is_valid is True, 'The new service item should be valid'
|
||||
assert 0 == len(service_item._display_frames), 'The service item should have no display frames'
|
||||
assert 7 == len(service_item.capabilities), 'There should be 7 default custom item capabilities'
|
||||
|
||||
# WHEN: We render the frames of the service item
|
||||
service_item.render(True)
|
||||
|
||||
# THEN: The frames should also be valid
|
||||
self.assertEqual('Amazing Grace', service_item.get_display_title(), 'The title should be "Amazing Grace"')
|
||||
self.assertEqual(CLEANED_VERSE[:-1], service_item.get_frames()[0]['text'],
|
||||
'The returned text matches the input, except the last line feed')
|
||||
self.assertEqual(RENDERED_VERSE.split('\n', 1)[0], service_item.get_rendered_frame(1),
|
||||
'The first line has been returned')
|
||||
self.assertEqual('Amazing Grace! how sweet the s', service_item.get_frame_title(0),
|
||||
'"Amazing Grace! how sweet the s" has been returned as the title')
|
||||
self.assertEqual('’Twas grace that taught my hea', service_item.get_frame_title(1),
|
||||
'"’Twas grace that taught my hea" has been returned as the title')
|
||||
self.assertEqual('/test/amazing_grace.mp3', service_item.background_audio[0],
|
||||
'"/test/amazing_grace.mp3" should be in the background_audio list')
|
||||
assert 'Amazing Grace' == service_item.get_display_title(), 'The title should be "Amazing Grace"'
|
||||
assert CLEANED_VERSE[:-1] == service_item.get_frames()[0]['text'], \
|
||||
'The returned text matches the input, except the last line feed'
|
||||
assert RENDERED_VERSE.split('\n', 1)[0] == service_item.get_rendered_frame(1), \
|
||||
'The first line has been returned'
|
||||
assert 'Amazing Grace! how sweet the s' == service_item.get_frame_title(0), \
|
||||
'"Amazing Grace! how sweet the s" has been returned as the title'
|
||||
assert '’Twas grace that taught my hea' == service_item.get_frame_title(1), \
|
||||
'"’Twas grace that taught my hea" has been returned as the title'
|
||||
assert '/test/amazing_grace.mp3' == service_item.background_audio[0], \
|
||||
'"/test/amazing_grace.mp3" should be in the background_audio list'
|
||||
|
|
|
@ -90,8 +90,8 @@ class TestTheme(TestCase):
|
|||
|
||||
# THEN: The filename of the background should be correct
|
||||
expected_filename = path / 'MyBeautifulTheme' / 'video.mp4'
|
||||
self.assertEqual(expected_filename, theme.background_filename)
|
||||
self.assertEqual('MyBeautifulTheme', theme.theme_name)
|
||||
assert expected_filename == theme.background_filename
|
||||
assert 'MyBeautifulTheme' == theme.theme_name
|
||||
|
||||
def test_save_retrieve(self):
|
||||
"""
|
||||
|
@ -107,9 +107,9 @@ class TestTheme(TestCase):
|
|||
self.check_theme(lt)
|
||||
|
||||
def check_theme(self, theme):
|
||||
self.assertEqual('#000000', theme.background_border_color, 'background_border_color should be "#000000"')
|
||||
self.assertEqual('solid', theme.background_type, 'background_type should be "solid"')
|
||||
self.assertEqual(0, theme.display_vertical_align, 'display_vertical_align should be 0')
|
||||
self.assertFalse(theme.font_footer_bold, 'font_footer_bold should be False')
|
||||
self.assertEqual('Arial', theme.font_main_name, 'font_main_name should be "Arial"')
|
||||
self.assertEqual(47, len(theme.__dict__), 'The theme should have 47 attributes')
|
||||
assert '#000000' == theme.background_border_color, 'background_border_color should be "#000000"'
|
||||
assert 'solid' == theme.background_type, 'background_type should be "solid"'
|
||||
assert 0 == theme.display_vertical_align, 'display_vertical_align should be 0'
|
||||
assert theme.font_footer_bold is False, 'font_footer_bold should be False'
|
||||
assert 'Arial' == theme.font_main_name, 'font_main_name should be "Arial"'
|
||||
assert 47 == len(theme.__dict__), 'The theme should have 47 attributes'
|
||||
|
|
|
@ -49,8 +49,8 @@ class TestUi(TestCase):
|
|||
add_welcome_page(wizard, ':/wizards/wizard_firsttime.bmp')
|
||||
|
||||
# THEN: The wizard should have one page with a pixmap.
|
||||
self.assertEqual(1, len(wizard.pageIds()), 'The wizard should have one page.')
|
||||
self.assertIsInstance(wizard.page(0).pixmap(QtWidgets.QWizard.WatermarkPixmap), QtGui.QPixmap)
|
||||
assert 1 == len(wizard.pageIds()), 'The wizard should have one page.'
|
||||
assert isinstance(wizard.page(0).pixmap(QtWidgets.QWizard.WatermarkPixmap), QtGui.QPixmap)
|
||||
|
||||
def test_create_button_box(self):
|
||||
"""
|
||||
|
@ -63,22 +63,22 @@ class TestUi(TestCase):
|
|||
btnbox = create_button_box(dialog, 'my_btns', ['ok', 'save', 'cancel', 'close', 'defaults'])
|
||||
|
||||
# THEN: We should get a QDialogButtonBox with five buttons
|
||||
self.assertIsInstance(btnbox, QtWidgets.QDialogButtonBox)
|
||||
self.assertEqual(5, len(btnbox.buttons()))
|
||||
assert isinstance(btnbox, QtWidgets.QDialogButtonBox)
|
||||
assert 5 == len(btnbox.buttons())
|
||||
|
||||
# WHEN: We create the button box with a custom button
|
||||
btnbox = create_button_box(dialog, 'my_btns', None, [QtWidgets.QPushButton('Custom')])
|
||||
# THEN: We should get a QDialogButtonBox with one button
|
||||
self.assertIsInstance(btnbox, QtWidgets.QDialogButtonBox)
|
||||
self.assertEqual(1, len(btnbox.buttons()))
|
||||
assert isinstance(btnbox, QtWidgets.QDialogButtonBox)
|
||||
assert 1 == len(btnbox.buttons())
|
||||
|
||||
# WHEN: We create the button box with a custom button and a custom role
|
||||
btnbox = create_button_box(dialog, 'my_btns', None,
|
||||
[(QtWidgets.QPushButton('Help'), QtWidgets.QDialogButtonBox.HelpRole)])
|
||||
# THEN: We should get a QDialogButtonBox with one button with a certain role
|
||||
self.assertIsInstance(btnbox, QtWidgets.QDialogButtonBox)
|
||||
self.assertEqual(1, len(btnbox.buttons()))
|
||||
self.assertEqual(QtWidgets.QDialogButtonBox.HelpRole, btnbox.buttonRole(btnbox.buttons()[0]))
|
||||
assert isinstance(btnbox, QtWidgets.QDialogButtonBox)
|
||||
assert 1 == len(btnbox.buttons())
|
||||
assert QtWidgets.QDialogButtonBox.HelpRole, btnbox.buttonRole(btnbox.buttons()[0])
|
||||
|
||||
def test_create_horizontal_adjusting_combo_box(self):
|
||||
"""
|
||||
|
@ -91,9 +91,9 @@ class TestUi(TestCase):
|
|||
combo = create_horizontal_adjusting_combo_box(dialog, 'combo1')
|
||||
|
||||
# THEN: We should get a ComboBox
|
||||
self.assertIsInstance(combo, QtWidgets.QComboBox)
|
||||
self.assertEqual('combo1', combo.objectName())
|
||||
self.assertEqual(QtWidgets.QComboBox.AdjustToMinimumContentsLength, combo.sizeAdjustPolicy())
|
||||
assert isinstance(combo, QtWidgets.QComboBox)
|
||||
assert 'combo1' == combo.objectName()
|
||||
assert QtWidgets.QComboBox.AdjustToMinimumContentsLength == combo.sizeAdjustPolicy()
|
||||
|
||||
def test_create_button(self):
|
||||
"""
|
||||
|
@ -106,26 +106,26 @@ class TestUi(TestCase):
|
|||
btn = create_button(dialog, 'my_btn')
|
||||
|
||||
# THEN: We should get a button with a name
|
||||
self.assertIsInstance(btn, QtWidgets.QPushButton)
|
||||
self.assertEqual('my_btn', btn.objectName())
|
||||
self.assertTrue(btn.isEnabled())
|
||||
assert isinstance(btn, QtWidgets.QPushButton)
|
||||
assert 'my_btn' == btn.objectName()
|
||||
assert btn.isEnabled() is True
|
||||
|
||||
# WHEN: We create a button with some attributes
|
||||
btn = create_button(dialog, 'my_btn', text='Hello', tooltip='How are you?', enabled=False)
|
||||
|
||||
# THEN: We should get a button with those attributes
|
||||
self.assertIsInstance(btn, QtWidgets.QPushButton)
|
||||
self.assertEqual('Hello', btn.text())
|
||||
self.assertEqual('How are you?', btn.toolTip())
|
||||
self.assertFalse(btn.isEnabled())
|
||||
assert isinstance(btn, QtWidgets.QPushButton)
|
||||
assert 'Hello' == btn.text()
|
||||
assert 'How are you?' == btn.toolTip()
|
||||
assert btn.isEnabled() is False
|
||||
|
||||
# WHEN: We create a toolbutton
|
||||
btn = create_button(dialog, 'my_btn', btn_class='toolbutton')
|
||||
|
||||
# THEN: We should get a toolbutton
|
||||
self.assertIsInstance(btn, QtWidgets.QToolButton)
|
||||
self.assertEqual('my_btn', btn.objectName())
|
||||
self.assertTrue(btn.isEnabled())
|
||||
assert isinstance(btn, QtWidgets.QToolButton)
|
||||
assert 'my_btn' == btn.objectName()
|
||||
assert btn.isEnabled() is True
|
||||
|
||||
def test_create_action(self):
|
||||
"""
|
||||
|
@ -138,19 +138,19 @@ class TestUi(TestCase):
|
|||
action = create_action(dialog, 'my_action')
|
||||
|
||||
# THEN: We should get a QAction
|
||||
self.assertIsInstance(action, QtWidgets.QAction)
|
||||
self.assertEqual('my_action', action.objectName())
|
||||
assert isinstance(action, QtWidgets.QAction)
|
||||
assert 'my_action' == action.objectName()
|
||||
|
||||
# WHEN: We create an action with some properties
|
||||
action = create_action(dialog, 'my_action', text='my text', icon=':/wizards/wizard_firsttime.bmp',
|
||||
tooltip='my tooltip', statustip='my statustip')
|
||||
|
||||
# THEN: These properties should be set
|
||||
self.assertIsInstance(action, QtWidgets.QAction)
|
||||
self.assertEqual('my text', action.text())
|
||||
self.assertIsInstance(action.icon(), QtGui.QIcon)
|
||||
self.assertEqual('my tooltip', action.toolTip())
|
||||
self.assertEqual('my statustip', action.statusTip())
|
||||
assert isinstance(action, QtWidgets.QAction)
|
||||
assert 'my text' == action.text()
|
||||
assert isinstance(action.icon(), QtGui.QIcon)
|
||||
assert 'my tooltip' == action.toolTip()
|
||||
assert 'my statustip' == action.statusTip()
|
||||
|
||||
def test_create_action_on_mac_osx(self):
|
||||
"""
|
||||
|
@ -186,8 +186,8 @@ class TestUi(TestCase):
|
|||
create_action(dialog, 'my_action')
|
||||
|
||||
# THEN: setIconVisibleInMenu should not be called
|
||||
self.assertEqual(0, mocked_action.setIconVisibleInMenu.call_count,
|
||||
'setIconVisibleInMenu should not have been called')
|
||||
assert 0 == mocked_action.setIconVisibleInMenu.call_count, \
|
||||
'setIconVisibleInMenu should not have been called'
|
||||
|
||||
def test_create_checked_disabled_invisible_action(self):
|
||||
"""
|
||||
|
@ -200,9 +200,9 @@ class TestUi(TestCase):
|
|||
action = create_action(dialog, 'my_action', checked=True, enabled=False, visible=False)
|
||||
|
||||
# THEN: These properties should be set
|
||||
self.assertTrue(action.isChecked(), 'The action should be checked')
|
||||
self.assertFalse(action.isEnabled(), 'The action should be disabled')
|
||||
self.assertFalse(action.isVisible(), 'The action should be invisble')
|
||||
assert action.isChecked() is True, 'The action should be checked'
|
||||
assert action.isEnabled() is False, 'The action should be disabled'
|
||||
assert action.isVisible() is False, 'The action should be invisble'
|
||||
|
||||
def test_create_action_separator(self):
|
||||
"""
|
||||
|
@ -215,7 +215,7 @@ class TestUi(TestCase):
|
|||
action = create_action(dialog, 'my_action', separator=True)
|
||||
|
||||
# THEN: The action should be a separator
|
||||
self.assertTrue(action.isSeparator(), 'The action should be a separator')
|
||||
assert action.isSeparator() is True, 'The action should be a separator'
|
||||
|
||||
def test_create_valign_selection_widgets(self):
|
||||
"""
|
||||
|
@ -228,11 +228,11 @@ class TestUi(TestCase):
|
|||
label, combo = create_valign_selection_widgets(dialog)
|
||||
|
||||
# THEN: We should get a label and a combobox.
|
||||
self.assertEqual(translate('OpenLP.Ui', '&Vertical Align:'), label.text())
|
||||
self.assertIsInstance(combo, QtWidgets.QComboBox)
|
||||
self.assertEqual(combo, label.buddy())
|
||||
assert translate('OpenLP.Ui', '&Vertical Align:') == label.text()
|
||||
assert isinstance(combo, QtWidgets.QComboBox)
|
||||
assert combo == label.buddy()
|
||||
for text in [UiStrings().Top, UiStrings().Middle, UiStrings().Bottom]:
|
||||
self.assertTrue(combo.findText(text) >= 0)
|
||||
assert combo.findText(text) >= 0
|
||||
|
||||
def test_find_and_set_in_combo_box(self):
|
||||
"""
|
||||
|
@ -247,19 +247,19 @@ class TestUi(TestCase):
|
|||
find_and_set_in_combo_box(combo, 'Four', set_missing=False)
|
||||
|
||||
# THEN: The index should not have changed
|
||||
self.assertEqual(1, combo.currentIndex())
|
||||
assert 1 == combo.currentIndex()
|
||||
|
||||
# WHEN: We call the method with a non-existing value
|
||||
find_and_set_in_combo_box(combo, 'Four')
|
||||
|
||||
# THEN: The index should have been reset
|
||||
self.assertEqual(0, combo.currentIndex())
|
||||
assert 0 == combo.currentIndex()
|
||||
|
||||
# WHEN: We call the method with the default behavior
|
||||
find_and_set_in_combo_box(combo, 'Three')
|
||||
|
||||
# THEN: The index should have changed
|
||||
self.assertEqual(2, combo.currentIndex())
|
||||
assert 2 == combo.currentIndex()
|
||||
|
||||
def test_create_widget_action(self):
|
||||
"""
|
||||
|
@ -272,8 +272,8 @@ class TestUi(TestCase):
|
|||
action = create_widget_action(button, 'some action')
|
||||
|
||||
# THEN: The action should be returned
|
||||
self.assertIsInstance(action, QtWidgets.QAction)
|
||||
self.assertEqual(action.objectName(), 'some action')
|
||||
assert isinstance(action, QtWidgets.QAction)
|
||||
assert action.objectName() == 'some action'
|
||||
|
||||
def test_set_case_insensitive_completer(self):
|
||||
"""
|
||||
|
@ -288,5 +288,5 @@ class TestUi(TestCase):
|
|||
|
||||
# THEN: The Combobox should have a completer which is case insensitive
|
||||
completer = line_edit.completer()
|
||||
self.assertIsInstance(completer, QtWidgets.QCompleter)
|
||||
self.assertEqual(completer.caseSensitivity(), QtCore.Qt.CaseInsensitive)
|
||||
assert isinstance(completer, QtWidgets.QCompleter)
|
||||
assert completer.caseSensitivity() == QtCore.Qt.CaseInsensitive
|
||||
|
|
Loading…
Reference in New Issue