This commit is contained in:
Phill Ridout 2017-12-24 07:40:07 +00:00
commit cb53a266ce
74 changed files with 819 additions and 868 deletions

View File

@ -73,13 +73,13 @@ class TestImageManager(TestCase, TestMixin):
image = self.image_manager.get_image(full_path, 'church.jpg')
# THEN returned record is a type of 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: The image bytes are requested.
byte_array = self.image_manager.get_image_bytes(full_path, 'church.jpg')
# THEN: Type should be a str.
self.assertEqual(isinstance(byte_array, str), True, 'The returned object should be a str')
assert isinstance(byte_array, str), 'The returned object should be a str'
# WHEN the image is retrieved has not been loaded
# THEN a KeyError is thrown
@ -105,14 +105,14 @@ class TestImageManager(TestCase, TestMixin):
self.image_manager.add_image(full_path, 'church.jpg', None, 100, 100)
# THEN: the cache should contain two pictures
self.assertEqual(len(self.image_manager._cache), 2,
'Image manager should consider two dimensions of the same picture as different')
assert len(self.image_manager._cache) == 2, \
'Image manager should consider two dimensions of the same picture as different'
# WHEN: adding the same image with first dimensions
self.image_manager.add_image(full_path, 'church.jpg', None, 80, 80)
# THEN: the cache should still contain only two pictures
self.assertEqual(len(self.image_manager._cache), 2, 'Same dimensions should not be added again')
assert len(self.image_manager._cache) == 2, 'Same dimensions should not be added again'
# WHEN: calling with correct image, but wrong dimensions
with self.assertRaises(KeyError) as context:

View File

@ -289,7 +289,7 @@ class TestLib(TestCase):
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')
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 thumb_size == QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size'
@ -323,7 +323,7 @@ class TestLib(TestCase):
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')
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'
@ -428,7 +428,7 @@ class TestLib(TestCase):
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')
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'
@ -466,7 +466,7 @@ class TestLib(TestCase):
icon = create_thumb(image_path, thumb_path, size=None)
# 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')
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_1 == QtGui.QImageReader(str(thumb_path)).size(), 'The thumb should have the given size'
@ -787,7 +787,7 @@ class TestLib(TestCase):
ret = compare_chord_lyric(chord, lyrics)
# THEN: The returned value should 0 because the lyric is longer than the chord
self.assertEquals(0, ret, 'The returned value should 0 because the lyric is longer than the chord')
assert 0 == ret, 'The returned value should 0 because the lyric is longer than the chord'
def test_compare_chord_lyric_long_chord(self):
"""

View File

@ -52,7 +52,7 @@ class TestPath(TestCase):
result = path_to_str(None)
# THEN: `path_to_str` should return an empty string
self.assertEqual(result, '')
assert result == ''
def test_path_to_str_path_object(self):
"""
@ -63,7 +63,7 @@ class TestPath(TestCase):
result = path_to_str(Path('test/path'))
# THEN: `path_to_str` should return a string representation of the Path object
self.assertEqual(result, os.path.join('test', 'path'))
assert result == os.path.join('test', 'path')
def test_str_to_path_type_error(self):
"""
@ -84,4 +84,4 @@ class TestPath(TestCase):
result = str_to_path('')
# THEN: `path_to_str` should return None
self.assertEqual(result, None)
assert result is None

View File

@ -310,7 +310,7 @@ class TestOpenLP(TestCase):
# THEN:
assert result is True, "The method should have returned True."
# self.assertFalse(self.openlp.main_window.isMinimized())
# assert self.openlp.main_window.isMinimized() is False
@patch('openlp.core.app.get_version')
@patch('openlp.core.app.QtWidgets.QMessageBox.question')

View File

@ -117,8 +117,8 @@ class TestMainWindow(TestCase, TestMixin):
# WHEN no changes are made to the service
# THEN the main window's title shoud be the same as the OpenLP string in the UiStrings class
self.assertEqual(self.main_window.windowTitle(), UiStrings().OpenLP,
'The main window\'s title should be the same as the OpenLP string in UiStrings class')
assert self.main_window.windowTitle() == UiStrings().OpenLP, \
'The main window\'s title should be the same as the OpenLP string in UiStrings class'
def test_set_service_modifed(self):
"""
@ -204,7 +204,7 @@ class TestMainWindow(TestCase, TestMixin):
self.main_window.on_search_shortcut_triggered()
# THEN: The media manager dock is made visible
self.assertEqual(0, mocked_media_manager_dock.setVisible.call_count)
assert 0 == mocked_media_manager_dock.setVisible.call_count
mocked_widget.on_focus.assert_called_with()
@patch('openlp.core.ui.mainwindow.FirstTimeForm')

View File

@ -51,7 +51,7 @@ class TestAlertManager(TestCase):
alert_manager.alert_text('')
# THEN: the display should not have been triggered
self.assertFalse(alert_manager.display_alert.called, 'The Alert should not have been called')
assert alert_manager.display_alert.called is False, 'The Alert should not have been called'
def test_trigger_message_text(self):
"""
@ -65,7 +65,7 @@ class TestAlertManager(TestCase):
alert_manager.alert_text(['This is a string'])
# THEN: the display should have been triggered
self.assertTrue(alert_manager.display_alert.called, 'The Alert should have been called')
assert alert_manager.display_alert.called is True, 'The Alert should have been called'
def test_line_break_message_text(self):
"""
@ -79,5 +79,5 @@ class TestAlertManager(TestCase):
alert_manager.alert_text(['This is \n a string'])
# THEN: the display should have been triggered
self.assertTrue(alert_manager.display_alert.called, 'The Alert should have been called')
assert alert_manager.display_alert.called is True, 'The Alert should have been called'
alert_manager.display_alert.assert_called_once_with('This is a string')

View File

@ -75,9 +75,8 @@ class TestBSExtract(TestCase):
self.mock_urllib.parse.quote.assert_called_once_with(b'NIV')
self.mock_get_soup_for_bible_ref.assert_called_once_with(
'http://m.bibleserver.com/overlay/selectBook?translation=NIV')
self.assertIsNone(result,
'BSExtract.get_books_from_http should return None when get_soup_for_bible_ref returns a '
'false value')
assert result is None, \
'BSExtract.get_books_from_http should return None when get_soup_for_bible_ref returns a false value'
def test_get_books_from_http_no_content(self):
"""
@ -106,9 +105,8 @@ class TestBSExtract(TestCase):
self.mock_soup.find.assert_called_once_with('ul')
self.mock_log.error.assert_called_once_with('No books found in the Bibleserver response.')
self.mock_send_error_message.assert_called_once_with('parse')
self.assertIsNone(result,
'BSExtract.get_books_from_http should return None when get_soup_for_bible_ref returns a '
'false value')
assert result is None, \
'BSExtract.get_books_from_http should return None when get_soup_for_bible_ref returns a false value'
def test_get_books_from_http_content(self):
"""
@ -138,6 +136,6 @@ class TestBSExtract(TestCase):
self.mock_urllib.parse.quote.assert_called_once_with(b'NIV')
self.mock_get_soup_for_bible_ref.assert_called_once_with(
'http://m.bibleserver.com/overlay/selectBook?translation=NIV')
self.assertFalse(self.mock_log.error.called, 'log.error should not have been called')
self.assertFalse(self.mock_send_error_message.called, 'send_error_message should not have been called')
self.assertEqual(result, ['Genesis', 'Leviticus'])
assert self.mock_log.error.called is False, 'log.error should not have been called'
assert self.mock_send_error_message.called is False, 'send_error_message should not have been called'
assert result == ['Genesis', 'Leviticus']

View File

@ -63,9 +63,9 @@ class TestCSVImport(TestCase):
CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'), verse_path=Path('verse.csv'))
# THEN: The importer should be an instance of BibleImport
self.assertIsInstance(importer, BibleImport)
self.assertEqual(importer.books_path, Path('books.csv'))
self.assertEqual(importer.verses_path, Path('verse.csv'))
assert isinstance(importer, BibleImport)
assert importer.books_path == Path('books.csv')
assert importer.verses_path == Path('verse.csv')
def test_book_namedtuple(self):
"""
@ -76,10 +76,10 @@ class TestCSVImport(TestCase):
result = Book('id', 'testament_id', 'name', 'abbreviation')
# THEN: The attributes should match up with the data we used
self.assertEqual(result.id, 'id')
self.assertEqual(result.testament_id, 'testament_id')
self.assertEqual(result.name, 'name')
self.assertEqual(result.abbreviation, 'abbreviation')
assert result.id == 'id'
assert result.testament_id == 'testament_id'
assert result.name == 'name'
assert result.abbreviation == 'abbreviation'
def test_verse_namedtuple(self):
"""
@ -90,10 +90,10 @@ class TestCSVImport(TestCase):
result = Verse('book_id_name', 'chapter_number', 'number', 'text')
# THEN: The attributes should match up with the data we used
self.assertEqual(result.book_id_name, 'book_id_name')
self.assertEqual(result.chapter_number, 'chapter_number')
self.assertEqual(result.number, 'number')
self.assertEqual(result.text, 'text')
assert result.book_id_name == 'book_id_name'
assert result.chapter_number == 'chapter_number'
assert result.number == 'number'
assert result.text == 'text'
def test_get_book_name_id(self):
"""
@ -108,7 +108,7 @@ class TestCSVImport(TestCase):
actual_result = CSVBible.get_book_name(name, books)
# THEN: get_book_name() should return the book name associated with that id from the books dictionary
self.assertEqual(actual_result, expected_result)
assert actual_result == expected_result
def test_get_book_name(self):
"""
@ -123,7 +123,7 @@ class TestCSVImport(TestCase):
actual_result = CSVBible.get_book_name(name, books)
# THEN: get_book_name() should return the input
self.assertEqual(actual_result, expected_result)
assert actual_result == expected_result
def test_parse_csv_file(self):
"""
@ -143,8 +143,8 @@ class TestCSVImport(TestCase):
result = CSVBible.parse_csv_file(Path('file.csv'), TestTuple)
# THEN: A list of TestTuple instances with the parsed data should be returned
self.assertEqual(result, [TestTuple('1', 'Line 1', 'Data 1'), TestTuple('2', 'Line 2', 'Data 2'),
TestTuple('3', 'Line 3', 'Data 3')])
assert result == [TestTuple('1', 'Line 1', 'Data 1'), TestTuple('2', 'Line 2', 'Data 2'),
TestTuple('3', 'Line 3', 'Data 3')]
mocked_open.assert_called_once_with('r', encoding='utf-8', newline='')
mocked_reader.assert_called_once_with(ANY, delimiter=',', quotechar='"')
@ -161,7 +161,7 @@ class TestCSVImport(TestCase):
# THEN: A ValidationError should be raised
with self.assertRaises(ValidationError) as context:
CSVBible.parse_csv_file(Path('file.csv'), None)
self.assertEqual(context.exception.msg, 'Parsing "file.csv" failed')
assert context.exception.msg == 'Parsing "file.csv" failed'
def test_parse_csv_file_csverror(self):
"""
@ -177,7 +177,7 @@ class TestCSVImport(TestCase):
# THEN: A ValidationError should be raised
with self.assertRaises(ValidationError) as context:
CSVBible.parse_csv_file(Path('file.csv'), None)
self.assertEqual(context.exception.msg, 'Parsing "file.csv" failed')
assert context.exception.msg == 'Parsing "file.csv" failed'
def test_process_books_stopped_import(self):
"""
@ -196,8 +196,8 @@ class TestCSVImport(TestCase):
result = importer.process_books(['Book 1'])
# THEN: increment_progress_bar should not be called and the return value should be an empty dictionary
self.assertFalse(importer.wizard.increment_progress_bar.called)
self.assertEqual(result, {})
assert importer.wizard.increment_progress_bar.called is False
assert result == {}
def test_process_books(self):
"""
@ -221,9 +221,9 @@ class TestCSVImport(TestCase):
# THEN: translate and find_and_create_book should have been called with both book names.
# The returned data should be a dictionary with both song's id and names.
self.assertEqual(importer.find_and_create_book.mock_calls,
[call('1. Mosebog', 2, 10), call('2. Mosebog', 2, 10)])
self.assertDictEqual(result, {1: '1. Mosebog', 2: '2. Mosebog'})
assert importer.find_and_create_book.mock_calls == \
[call('1. Mosebog', 2, 10), call('2. Mosebog', 2, 10)]
assert result == {1: '1. Mosebog', 2: '2. Mosebog'}
def test_process_verses_stopped_import(self):
"""
@ -243,8 +243,8 @@ class TestCSVImport(TestCase):
result = importer.process_verses(['Dummy Verse'], [])
# THEN: get_book_name should not be called and the return value should be None
self.assertFalse(importer.get_book_name.called)
self.assertIsNone(result)
assert importer.get_book_name.called is False
assert result is None
def test_process_verses_successful(self):
"""
@ -271,13 +271,13 @@ class TestCSVImport(TestCase):
importer.process_verses(verses, books)
# THEN: create_verse is called with the test data
self.assertEqual(importer.get_book_name.mock_calls, [call(1, books), call(1, books)])
assert importer.get_book_name.mock_calls == [call(1, books), call(1, books)]
importer.get_book.assert_called_once_with('1. Mosebog')
self.assertEqual(importer.session.commit.call_count, 2)
self.assertEqual(importer.create_verse.mock_calls,
[call('1', 1, 1, 'I Begyndelsen skabte Gud Himmelen og Jorden.'),
call('1', 1, 2, 'Og Jorden var øde og tom, og der var Mørke over Verdensdybet. '
'Men Guds Ånd svævede over Vandene.')])
assert importer.session.commit.call_count == 2
assert importer.create_verse.mock_calls == \
[call('1', 1, 1, 'I Begyndelsen skabte Gud Himmelen og Jorden.'),
call('1', 1, 2, 'Og Jorden var øde og tom, og der var Mørke over Verdensdybet. '
'Men Guds Ånd svævede over Vandene.')]
def test_do_import_invalid_language_id(self):
"""
@ -295,7 +295,7 @@ class TestCSVImport(TestCase):
# THEN: The False should be returned.
importer.get_language.assert_called_once_with('Bible Name')
self.assertFalse(result)
assert result is False
def test_do_import_success(self):
"""
@ -319,11 +319,11 @@ class TestCSVImport(TestCase):
# THEN: parse_csv_file should be called twice,
# and True should be returned.
self.assertEqual(importer.parse_csv_file.mock_calls,
[call(Path('books.csv'), Book), call(Path('verses.csv'), Verse)])
assert importer.parse_csv_file.mock_calls == \
[call(Path('books.csv'), Book), call(Path('verses.csv'), Verse)]
importer.process_books.assert_called_once_with(['Book 1'])
importer.process_verses.assert_called_once_with(['Verse 1'], ['Book 1'])
self.assertTrue(result)
assert result is True
def test_file_import(self):
"""
@ -351,7 +351,7 @@ class TestCSVImport(TestCase):
importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file.
self.assertTrue(importer.create_verse.called)
assert importer.create_verse.called is True
for verse_tag, verse_text in test_data['verses']:
importer.create_verse.assert_any_call(importer.get_book().id, 1, verse_tag, verse_text)
importer.create_book.assert_any_call('1. Mosebog', importer.get_book_ref_id_by_name(), 1)

View File

@ -59,7 +59,7 @@ class TestLib(TestCase, TestMixin):
_ = lib.get_reference_separator(key)
# THEN: get_reference_separator should return the correct separator
self.assertEqual(separators[key], value)
assert separators[key] == value
mocked_update_reference_separators.assert_called_once_with()
def test_reference_matched_full(self):
@ -116,13 +116,13 @@ class TestLib(TestCase, TestMixin):
# THEN: A match should be returned, and the book and reference should match the
# expected result
self.assertIsNotNone(match, '{text} should provide a match'.format(text=reference_text))
self.assertEqual(book_result, match.group('book'),
'{text} does not provide the expected result for the book group.'
.format(text=reference_text))
self.assertEqual(ranges_result, match.group('ranges'),
'{text} does not provide the expected result for the ranges group.'
.format(text=reference_text))
assert match is not None, '{text} should provide a match'.format(text=reference_text)
assert book_result == match.group('book'), \
'{text} does not provide the expected result for the book group.'\
.format(text=reference_text)
assert ranges_result == match.group('ranges'), \
'{text} does not provide the expected result for the ranges group.' \
.format(text=reference_text)
def test_reference_matched_range(self):
"""
@ -158,12 +158,12 @@ class TestLib(TestCase, TestMixin):
# THEN: A match should be returned, and the to/from chapter/verses should match as
# expected
self.assertIsNotNone(match, '{text} should provide a match'.format(text=reference_text))
self.assertEqual(match.group('from_chapter'), from_chapter)
self.assertEqual(match.group('from_verse'), from_verse)
self.assertEqual(match.group('range_to'), range_to)
self.assertEqual(match.group('to_chapter'), to_chapter)
self.assertEqual(match.group('to_verse'), to_verse)
assert match is not None, '{text} should provide a match'.format(text=reference_text)
assert match.group('from_chapter') == from_chapter
assert match.group('from_verse') == from_verse
assert match.group('range_to') == range_to
assert match.group('to_chapter') == to_chapter
assert match.group('to_verse') == to_verse
def test_reference_matched_range_separator(self):
# GIVEN: Some test data which contains different references to parse, with the expected results.
@ -199,7 +199,7 @@ class TestLib(TestCase, TestMixin):
references = full_reference_match.split(reference_text)
# THEN: The list of references should be as the expected results
self.assertEqual(references, ranges)
assert references == ranges
def test_search_results_creation(self):
"""
@ -218,10 +218,10 @@ class TestLib(TestCase, TestMixin):
search_results = SearchResults(book, chapter, verse_list)
# THEN: It should have a book, a chapter and a verse list
self.assertIsNotNone(search_results, 'The search_results object should not be None')
self.assertEqual(search_results.book, book, 'The book should be "Genesis"')
self.assertEqual(search_results.chapter, chapter, 'The chapter should be 1')
self.assertDictEqual(search_results.verse_list, verse_list, 'The verse lists should be identical')
assert search_results is not None, 'The search_results object should not be None'
assert search_results.book == book, 'The book should be "Genesis"'
assert search_results.chapter == chapter, 'The chapter should be 1'
assert search_results.verse_list == verse_list, 'The verse lists should be identical'
def test_search_results_has_verse_list(self):
"""
@ -234,7 +234,7 @@ class TestLib(TestCase, TestMixin):
has_verse_list = search_results.has_verse_list()
# THEN: It should be True
self.assertTrue(has_verse_list, 'The SearchResults object should have a verse list')
assert has_verse_list is True, 'The SearchResults object should have a verse list'
def test_search_results_has_no_verse_list(self):
"""
@ -247,4 +247,4 @@ class TestLib(TestCase, TestMixin):
has_verse_list = search_results.has_verse_list()
# THEN: It should be False
self.assertFalse(has_verse_list, 'The SearchResults object should have a verse list')
assert has_verse_list is False, 'The SearchResults object should have a verse list'

View File

@ -63,7 +63,7 @@ class TestManager(TestCase):
# THEN: The session should have been closed and set to None, the bible should be deleted, and the result of
# the deletion returned.
self.assertTrue(result)
assert result is True
mocked_close_all.assert_called_once_with()
self.assertIsNone(mocked_bible.session)
assert mocked_bible.session is None
mocked_delete_file.assert_called_once_with(Path('bibles', 'KJV.sqlite'))

View File

@ -53,9 +53,9 @@ class TestBibleMediaItemModulefunctions(TestCase):
# THEN: The expected result should be returned
if expected_result is None:
self.assertIsNone(result, expected_result)
assert result is None, expected_result
else:
self.assertEqual(result.regs, expected_result)
assert result.regs == expected_result
def test_get_reference_separators(self):
"""
@ -69,7 +69,7 @@ class TestBibleMediaItemModulefunctions(TestCase):
# THEN: The result should contain the 'verse', 'range', 'list' keys and get_reference_separator should have
# been called with the expected values.
self.assertTrue(all(key in result for key in ('verse', 'range', 'list')))
assert all(key in result for key in ('verse', 'range', 'list')) is True
mocked_get_reference_separator.assert_has_calls(
[call('sep_v_display'), call('sep_r_display'), call('sep_l_display')])
@ -80,9 +80,9 @@ class TestBibleMediaItemModulefunctions(TestCase):
# GIVEN: The BibleSearch class
# WHEN: Testing its attributes
# THEN: The BibleSearch class should have the following enumrations
self.assertTrue(hasattr(BibleSearch, 'Combined'))
self.assertTrue(hasattr(BibleSearch, 'Reference'))
self.assertTrue(hasattr(BibleSearch, 'Text'))
assert hasattr(BibleSearch, 'Combined')
assert hasattr(BibleSearch, 'Reference')
assert hasattr(BibleSearch, 'Text')
def test_bible_media_item_subclass(self):
"""
@ -91,7 +91,7 @@ class TestBibleMediaItemModulefunctions(TestCase):
# GIVEN: The :class:`BibleMediaItem`
# WHEN: Checking if it is a subclass of MediaManagerItem
# THEN: BibleMediaItem should be a subclass of MediaManagerItem
self.assertTrue(issubclass(BibleMediaItem, MediaManagerItem))
assert issubclass(BibleMediaItem, MediaManagerItem)
def test_bible_media_item_signals(self):
"""
@ -99,10 +99,10 @@ class TestBibleMediaItemModulefunctions(TestCase):
"""
# GIVEN: The :class:`BibleMediaItem`
# THEN: The :class:`BibleMediaItem` should contain the following pyqtSignal's
self.assertTrue(hasattr(BibleMediaItem, 'bibles_go_live'))
self.assertTrue(hasattr(BibleMediaItem, 'bibles_add_to_service'))
self.assertTrue(isinstance(BibleMediaItem.bibles_go_live, QtCore.pyqtSignal))
self.assertTrue(isinstance(BibleMediaItem.bibles_add_to_service, QtCore.pyqtSignal))
assert hasattr(BibleMediaItem, 'bibles_go_live')
assert hasattr(BibleMediaItem, 'bibles_add_to_service')
assert isinstance(BibleMediaItem.bibles_go_live, QtCore.pyqtSignal)
assert isinstance(BibleMediaItem.bibles_add_to_service, QtCore.pyqtSignal)
class TestMediaItem(TestCase, TestMixin):
@ -166,7 +166,7 @@ class TestMediaItem(TestCase, TestMixin):
# GIVEN: An instance of :class:`BibleMediaItem`
# WEHN: Checking its class
# THEN: It should be a subclass of :class:`MediaManagerItem`
self.assertTrue(isinstance(self.media_item, MediaManagerItem))
assert isinstance(self.media_item, MediaManagerItem)
def test_steup_item(self):
"""
@ -193,11 +193,11 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.required_icons()
# THEN: The correct icons should be set
self.assertTrue(self.media_item.has_import_icon, 'Check that the icon is as True.')
self.assertFalse(self.media_item.has_new_icon, 'Check that the icon is called as False.')
self.assertTrue(self.media_item.has_edit_icon, 'Check that the icon is called as True.')
self.assertTrue(self.media_item.has_delete_icon, 'Check that the icon is called as True.')
self.assertFalse(self.media_item.add_to_service_item, 'Check that the icon is called as False')
assert self.media_item.has_import_icon is True, 'Check that the icon is as True.'
assert self.media_item.has_new_icon is False, 'Check that the icon is called as False.'
assert self.media_item.has_edit_icon is True, 'Check that the icon is called as True.'
assert self.media_item.has_delete_icon is True, 'Check that the icon is called as True.'
assert self.media_item.add_to_service_item is False, 'Check that the icon is called as False'
def test_on_focus_search_tab_visible(self):
"""
@ -305,8 +305,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.initialise()
# THEN: The search_edit search types should have been set.
self.assertTrue(self.media_item.search_edit.set_search_types.called)
self.assertFalse(self.media_item.search_edit.set_current_search_type.called)
assert self.media_item.search_edit.set_search_types.called is True
assert self.media_item.search_edit.set_current_search_type.called is False
def test_initalise_reset_search_type(self):
"""
@ -323,7 +323,7 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The search_edit search types should have been set and that the current search type should be set to
# 'Combined'
self.assertTrue(self.media_item.search_edit.set_search_types.called)
assert self.media_item.search_edit.set_search_types.called is True
self.media_item.search_edit.set_current_search_type.assert_called_once_with(BibleSearch.Combined)
def test_populate_bible_combo_boxes(self):
@ -373,7 +373,7 @@ class TestMediaItem(TestCase, TestMixin):
result = self.media_item.get_common_books(self.mocked_bible_1)
# THEN: The book of the bible should be returned
self.assertEqual(result, self.book_list_1)
assert result == self.book_list_1
def test_get_common_books_second_book(self):
"""
@ -384,7 +384,7 @@ class TestMediaItem(TestCase, TestMixin):
result = self.media_item.get_common_books(self.mocked_bible_1, self.mocked_bible_2)
# THEN: Only the books contained in both bibles should be returned
self.assertEqual(result, [self.mocked_book_2, self.mocked_book_3])
assert result == [self.mocked_book_2, self.mocked_book_3]
def test_initialise_advanced_bible_no_bible(self):
"""
@ -399,7 +399,7 @@ class TestMediaItem(TestCase, TestMixin):
result = self.media_item.initialise_advanced_bible()
# THEN: initialise_advanced_bible should return with put calling get_common_books
self.assertIsNone(result)
assert result is None
mocked_get_common_books.assert_not_called()
def test_initialise_advanced_bible_add_books_with_last_id_found(self):
@ -515,8 +515,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_import_click()
# THEN: BibleImport wizard should have been instianted and reload_bibles should not have been called
self.assertTrue(mocked_bible_import_form.called)
self.assertFalse(mocked_reload_bibles.called)
assert mocked_bible_import_form.called is True
assert mocked_reload_bibles.called is False
def test_on_import_click_wizard_not_canceled(self):
"""
@ -532,8 +532,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_import_click()
# THEN: BibleImport wizard should have been instianted and reload_bibles should not have been called
self.assertFalse(mocked_import_wizard.called)
self.assertTrue(mocked_reload_bibles.called)
assert mocked_import_wizard.called is False
assert mocked_reload_bibles.called is True
def test_on_edit_click_no_bible(self):
"""
@ -547,7 +547,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_edit_click()
# THEN: EditBibleForm should not have been instianted
self.assertFalse(mocked_edit_bible_form.called)
assert mocked_edit_bible_form.called is False
def test_on_edit_click_user_cancel_edit_form(self):
"""
@ -565,8 +565,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_edit_click()
# THEN: EditBibleForm should have been been instianted but reload_bibles should not have been called
self.assertTrue(mocked_edit_bible_form.called)
self.assertFalse(mocked_reload_bibles.called)
assert mocked_edit_bible_form.called is True
assert mocked_reload_bibles.called is False
def test_on_edit_click_user_accepts_edit_form(self):
"""
@ -585,8 +585,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_edit_click()
# THEN: EditBibleForm should have been been instianted and reload_bibles should have been called
self.assertTrue(mocked_edit_bible_form.called)
self.assertTrue(mocked_reload_bibles.called)
assert mocked_edit_bible_form.called is True
assert mocked_reload_bibles.called is True
def test_on_delete_click_no_bible(self):
"""
@ -600,7 +600,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_delete_click()
# THEN: QMessageBox.question should not have been called
self.assertFalse(mocked_qmessage_box.question.called)
assert mocked_qmessage_box.question.called is False
def test_on_delete_click_response_no(self):
"""
@ -615,8 +615,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_delete_click()
# THEN: QMessageBox.question should have been called, but the delete_bible should not have been called
self.assertTrue(mocked_qmessage_box.called)
self.assertFalse(self.mocked_plugin.manager.delete_bible.called)
assert mocked_qmessage_box.called is True
assert self.mocked_plugin.manager.delete_bible.called is False
def test_on_delete_click_response_yes(self):
"""
@ -632,8 +632,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_delete_click()
# THEN: QMessageBox.question should and delete_bible should not have been called
self.assertTrue(mocked_qmessage_box.called)
self.assertTrue(self.mocked_plugin.manager.delete_bible.called)
assert mocked_qmessage_box.called is True
assert self.mocked_plugin.manager.delete_bible.called is True
def test_on_search_tab_bar_current_changed_search_tab_selected(self):
"""
@ -711,8 +711,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_clear_button_clicked()
# THEN: The list_view and the search_edit should be cleared
self.assertEqual(self.media_item.current_results, [])
self.assertEqual(self.media_item.list_view.takeItem.call_count, 2)
assert self.media_item.current_results == []
assert self.media_item.list_view.takeItem.call_count == 2
self.media_item.list_view.row.assert_has_calls([call('Some'), call('Results')])
def test_on_save_results_button_clicked(self):
@ -733,7 +733,7 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The selected results in the list_view should be added to the 'saved_results' list. And the saved_tab
# total should be updated.
self.assertEqual(self.media_item.saved_results, ['R1', 'R2', 'R3'])
assert self.media_item.saved_results == ['R1', 'R2', 'R3']
mocked_on_results_view_tab_total_update.assert_called_once_with(ResultsTab.Saved)
def test_on_style_combo_box_changed(self):
@ -746,8 +746,8 @@ class TestMediaItem(TestCase, TestMixin):
# WHEN: Calling on_style_combo_box_index_changed
self.media_item.on_style_combo_box_index_changed(2)
# THEN: The layput_style settimg should have been set
self.assertEqual(self.media_item.settings.layout_style, 2)
# THEN: The layout_style setting should have been set
assert self.media_item.settings.layout_style == 2
self.media_item.settings.layout_style_combo_box.setCurrentIndex.assert_called_once_with(2)
self.mocked_settings_instance.setValue.assert_called_once_with('bibles/verse layout style', 2)
@ -763,9 +763,9 @@ class TestMediaItem(TestCase, TestMixin):
# WHEN: Calling on_version_combo_box_index_changed
self.media_item.on_version_combo_box_index_changed()
# THEN: The vesion should be saved to settings and the 'select tab' should be initialised
self.assertFalse(self.mocked_settings_instance.setValue.called)
self.assertTrue(self.media_item.initialise_advanced_bible.called)
# THEN: The version should be saved to settings and the 'select tab' should be initialised
assert self.mocked_settings_instance.setValue.called is False
assert self.media_item.initialise_advanced_bible.called is True
def test_on_version_combo_box_index_changed_bible_selected(self):
"""
@ -781,9 +781,9 @@ class TestMediaItem(TestCase, TestMixin):
# WHEN: Calling on_version_combo_box_index_changed
self.media_item.on_version_combo_box_index_changed()
# THEN: The vesion should be saved to settings and the 'select tab' should be initialised
# THEN: The version should be saved to settings and the 'select tab' should be initialised
self.mocked_settings_instance.setValue.assert_called_once_with('bibles/primary bible', 'ABC')
self.assertTrue(self.media_item.initialise_advanced_bible.called)
assert self.media_item.initialise_advanced_bible.called is True
def test_on_second_combo_box_index_changed_mode_not_changed(self):
"""
@ -798,15 +798,15 @@ class TestMediaItem(TestCase, TestMixin):
patch('openlp.plugins.bibles.lib.mediaitem.critical_error_message_box') \
as mocked_critical_error_message_box:
# WHEN: The previously selected bible is one bible and the new selection is annother bible
# WHEN: The previously selected bible is one bible and the new selection is another bible
self.media_item.second_bible = self.mocked_bible_1
self.media_item.second_combo_box = MagicMock(**{'currentData.return_value': self.mocked_bible_2})
self.media_item.on_second_combo_box_index_changed(5)
# THEN: The new bible should now be the current bible
self.assertFalse(mocked_critical_error_message_box.called)
assert mocked_critical_error_message_box.called is False
self.media_item.style_combo_box.setEnabled.assert_called_once_with(False)
self.assertEqual(self.media_item.second_bible, self.mocked_bible_2)
assert self.media_item.second_bible == self.mocked_bible_2
def test_on_second_combo_box_index_changed_single_to_dual_user_abort(self):
"""
@ -828,11 +828,11 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.saved_results = ['saved_results']
self.media_item.on_second_combo_box_index_changed(5)
# THEN: The list_view should be cleared and the currently selected bible should not be channged
self.assertTrue(mocked_critical_error_message_box.called)
self.assertTrue(self.media_item.second_combo_box.setCurrentIndex.called)
self.assertFalse(self.media_item.style_combo_box.setEnabled.called)
self.assertEqual(self.media_item.second_bible, None)
# THEN: The list_view should be cleared and the currently selected bible should not be changed
assert mocked_critical_error_message_box.called is True
assert self.media_item.second_combo_box.setCurrentIndex.called is True
assert self.media_item.style_combo_box.setEnabled.called is False
assert self.media_item.second_bible is None
def test_on_second_combo_box_index_changed_single_to_dual(self):
"""
@ -857,10 +857,10 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_second_combo_box_index_changed(5)
# THEN: The selected bible should be set as the current bible
self.assertTrue(mocked_critical_error_message_box.called)
assert mocked_critical_error_message_box.called is True
self.media_item.style_combo_box.setEnabled.assert_called_once_with(False)
self.assertTrue(mocked_initialise_advanced_bible.called)
self.assertEqual(self.media_item.second_bible, self.mocked_bible_1)
assert mocked_initialise_advanced_bible.called is True
assert self.media_item.second_bible == self.mocked_bible_1
def test_on_second_combo_box_index_changed_dual_to_single(self):
"""
@ -884,10 +884,10 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_second_combo_box_index_changed(0)
# THEN: The selected bible should be set as the current bible
self.assertTrue(mocked_critical_error_message_box.called)
assert mocked_critical_error_message_box.called is True
self.media_item.style_combo_box.setEnabled.assert_called_once_with(True)
self.assertFalse(mocked_initialise_advanced_bible.called)
self.assertEqual(self.media_item.second_bible, None)
assert mocked_initialise_advanced_bible.called is False
assert self.media_item.second_bible is None
def test_on_advanced_book_combo_box(self):
"""
@ -907,7 +907,7 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The user should be informed that the bible cannot be used and the search button should be disabled
self.mocked_plugin.manager.get_book_by_id.assert_called_once_with('Bible 1', 2)
self.media_item.search_button.setEnabled.assert_called_once_with(False)
self.assertTrue(mocked_critical_error_message_box.called)
assert mocked_critical_error_message_box.called is True
def test_on_advanced_book_combo_box_set_up_comboboxes(self):
"""
@ -930,7 +930,7 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The verse selection combobox's should be set up
self.mocked_plugin.manager.get_book_by_id.assert_called_once_with('Bible 1', 2)
self.media_item.search_button.setEnabled.assert_called_once_with(True)
self.assertEqual(mocked_adjust_combo_box.call_count, 4)
assert mocked_adjust_combo_box.call_count == 4
def test_on_from_chapter_activated_invalid_to_chapter(self):
"""
@ -951,9 +951,9 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_from_chapter_activated()
# THEN: The to_verse and to_chapter comboboxes should be updated appropriately
self.assertEqual(mocked_adjust_combo_box.call_args_list, [
assert mocked_adjust_combo_box.call_args_list == [
call(1, 20, self.media_item.from_verse), call(1, 20, self.media_item.to_verse, False),
call(10, 25, self.media_item.to_chapter, False)])
call(10, 25, self.media_item.to_chapter, False)]
def test_on_from_chapter_activated_same_chapter(self):
"""
@ -974,9 +974,9 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_from_chapter_activated()
# THEN: The to_verse and to_chapter comboboxes should be updated appropriately
self.assertEqual(mocked_adjust_combo_box.call_args_list, [
assert mocked_adjust_combo_box.call_args_list == [
call(1, 20, self.media_item.from_verse), call(1, 20, self.media_item.to_verse, True),
call(5, 25, self.media_item.to_chapter, False)])
call(5, 25, self.media_item.to_chapter, False)]
def test_on_from_chapter_activated_lower_chapter(self):
"""
@ -996,8 +996,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_from_chapter_activated()
# THEN: The to_verse and to_chapter comboboxes should be updated appropriately
self.assertEqual(mocked_adjust_combo_box.call_args_list, [
call(1, 20, self.media_item.from_verse), call(5, 25, self.media_item.to_chapter, True)])
assert mocked_adjust_combo_box.call_args_list == [
call(1, 20, self.media_item.from_verse), call(5, 25, self.media_item.to_chapter, True)]
def test_on_from_verse(self):
"""
@ -1012,7 +1012,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_from_verse()
# THEN: select_book_combo_box.currentData should nto be called
self.assertFalse(self.media_item.select_book_combo_box.currentData.called)
assert self.media_item.select_book_combo_box.currentData.called is False
def test_on_from_verse_equal(self):
"""
@ -1107,8 +1107,8 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The combo_box should be cleared, and new items added
mocked_combo_box.clear.assert_called_once_with()
self.assertEqual(mocked_combo_box.addItem.call_args_list,
[call('10', 10), call('11', 11), call('12', 12), call('13', 13)])
assert mocked_combo_box.addItem.call_args_list == \
[call('10', 10), call('11', 11), call('12', 12), call('13', 13)]
def test_adjust_combo_box_restore_found(self):
"""
@ -1123,8 +1123,8 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The combo_box should be cleared, and new items added. Finally the previously selected item should be
# reselected
mocked_combo_box.clear.assert_called_once_with()
self.assertEqual(mocked_combo_box.addItem.call_args_list,
[call('10', 10), call('11', 11), call('12', 12), call('13', 13)])
assert mocked_combo_box.addItem.call_args_list == \
[call('10', 10), call('11', 11), call('12', 12), call('13', 13)]
mocked_combo_box.setCurrentIndex.assert_called_once_with(2)
def test_adjust_combo_box_restore_not_found(self):
@ -1140,8 +1140,8 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The combo_box should be cleared, and new items added. Finally the first item should be selected
mocked_combo_box.clear.assert_called_once_with()
self.assertEqual(mocked_combo_box.addItem.call_args_list,
[call('10', 10), call('11', 11), call('12', 12), call('13', 13)])
assert mocked_combo_box.addItem.call_args_list == \
[call('10', 10), call('11', 11), call('12', 12), call('13', 13)]
mocked_combo_box.setCurrentIndex.assert_called_once_with(0)
def test_on_search_button_no_bible(self):
@ -1154,7 +1154,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_search_button_clicked()
# THEN: The user should be informed that there are no bibles selected
self.assertEqual(self.mocked_main_window.information_message.call_count, 1)
assert self.mocked_main_window.information_message.call_count == 1
def test_on_search_button_search_tab(self):
"""
@ -1207,7 +1207,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.select_search()
# THEN: reference_search should only be called once
self.assertEqual(self.mocked_plugin.manager.get_verses.call_count, 1)
assert self.mocked_plugin.manager.get_verses.call_count == 1
mocked_display_results.assert_called_once_with()
def test_select_search_dual_bibles(self):
@ -1228,7 +1228,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.select_search()
# THEN: reference_search should be called twice
self.assertEqual(self.mocked_plugin.manager.get_verses.call_count, 2)
assert self.mocked_plugin.manager.get_verses.call_count == 2
mocked_display_results.assert_called_once_with()
def test_text_reference_search_single_bible(self):
@ -1244,7 +1244,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.text_reference_search('Search Text')
# THEN: reference_search should only be called once
self.assertEqual(self.mocked_plugin.manager.get_verses.call_count, 1)
assert self.mocked_plugin.manager.get_verses.call_count == 1
mocked_display_results.assert_called_once_with()
def text_reference_search(self, search_text, search_while_type=False):
@ -1272,7 +1272,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.text_reference_search('Search Text')
# THEN: reference_search should only be called once
self.assertEqual(self.mocked_plugin.manager.get_verses.call_count, 1)
assert self.mocked_plugin.manager.get_verses.call_count == 1
mocked_display_results.assert_called_once_with()
def test_text_reference_search_dual_bible(self):
@ -1288,7 +1288,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.text_reference_search('Search Text')
# THEN: reference_search should be called twice
self.assertEqual(self.mocked_plugin.manager.get_verses.call_count, 2)
assert self.mocked_plugin.manager.get_verses.call_count == 2
mocked_display_results.assert_called_once_with()
def test_on_text_search_single_bible(self):
@ -1305,7 +1305,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_text_search('Search Text')
# THEN: The search results should be the same as those returned by plugin.manager.verse_search
self.assertEqual(self.media_item.search_results, ['results', 'list'])
assert self.media_item.search_results == ['results', 'list']
mocked_display_results.assert_called_once_with()
def test_on_text_search_no_results(self):
@ -1322,7 +1322,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_text_search('Search Text')
# THEN: The search results should be an empty list
self.assertEqual(self.media_item.search_results, [])
assert self.media_item.search_results == []
mocked_display_results.assert_called_once_with()
def test_on_text_search_all_results_in_both_books(self):
@ -1345,10 +1345,10 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_text_search('Search Text')
# THEN: The search results for both bibles should be returned
self.assertEqual(self.media_item.search_results, [mocked_verse_1, mocked_verse_2])
self.assertEqual(self.media_item.second_search_results, [mocked_verse_1a, mocked_verse_2a])
self.assertFalse(self.mocked_log.debug.called)
self.assertFalse(self.mocked_main_window.information_message.called)
assert self.media_item.search_results == [mocked_verse_1, mocked_verse_2]
assert self.media_item.second_search_results == [mocked_verse_1a, mocked_verse_2a]
assert self.mocked_log.debug.called is False
assert self.mocked_main_window.information_message.called is False
mocked_display_results.assert_called_once_with()
def test_on_text_search_not_all_results_in_both_books(self):
@ -1372,10 +1372,10 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The search results included in both bibles should be returned and the user should be notified of
# the missing verses
self.assertEqual(self.media_item.search_results, [mocked_verse_1])
self.assertEqual(self.media_item.second_search_results, [mocked_verse_1a])
self.assertEqual(self.mocked_log.debug.call_count, 2)
self.assertTrue(self.mocked_main_window.information_message.called)
assert self.media_item.search_results == [mocked_verse_1]
assert self.media_item.second_search_results == [mocked_verse_1a]
assert self.mocked_log.debug.call_count == 2
assert self.mocked_main_window.information_message.called is True
mocked_display_results.assert_called_once_with()
def test_on_search_edit_text_changed_search_while_typing_disabled(self):
@ -1391,7 +1391,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_search_edit_text_changed()
# THEN: The method should not have checked if the timer is active
self.assertFalse(self.media_item.search_timer.isActive.called)
assert self.media_item.search_timer.isActive.called is False
def test_on_search_edit_text_changed_search_while_typing_enabled(self):
"""
@ -1422,7 +1422,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_search_timer_timeout()
# THEN: The search_status should be set to SearchAsYouType and text_search should have been called
self.assertEqual(self.media_item.search_status, SearchStatus.SearchAsYouType)
assert self.media_item.search_status == SearchStatus.SearchAsYouType
mocked_text_search.assert_called_once_with()
def test_display_results_no_results(self):
@ -1441,7 +1441,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.display_results()
# THEN: No items should be added to the list
self.assertFalse(self.media_item.list_view.addItem.called)
assert self.media_item.list_view.addItem.called is False
def test_display_results_results(self):
"""

View File

@ -66,7 +66,7 @@ class TestOpenSongImport(TestCase, TestMixin):
importer = OpenSongBible(mocked_manager, path='.', name='.', file_path=None)
# THEN: The importer should be an instance of BibleDB
self.assertIsInstance(importer, BibleImport)
assert isinstance(importer, BibleImport)
def test_get_text_no_text(self):
"""
@ -79,7 +79,7 @@ class TestOpenSongImport(TestCase, TestMixin):
result = get_text(test_data)
# THEN: A blank string should be returned
self.assertEqual(result, '')
assert result == ''
def test_get_text_text(self):
"""
@ -96,7 +96,7 @@ class TestOpenSongImport(TestCase, TestMixin):
result = get_text(test_data)
# THEN: The text returned should be as expected
self.assertEqual(result, 'Element text sub_text_tail text sub_text_tail tail sub_text text sub_tail tail')
assert result == 'Element text sub_text_tail text sub_text_tail tail sub_text text sub_tail tail'
def test_parse_chapter_number(self):
"""
@ -107,7 +107,7 @@ class TestOpenSongImport(TestCase, TestMixin):
result = parse_chapter_number('10', 0)
# THEN: The 10 should be returned as an Int
self.assertEqual(result, 10)
assert result == 10
def test_parse_chapter_number_empty_attribute(self):
"""
@ -118,7 +118,7 @@ class TestOpenSongImport(TestCase, TestMixin):
result = parse_chapter_number('', 12)
# THEN: parse_chapter_number should increment the previous verse number
self.assertEqual(result, 13)
assert result == 13
def test_parse_verse_number_valid_verse_no(self):
"""
@ -131,7 +131,7 @@ class TestOpenSongImport(TestCase, TestMixin):
result = importer.parse_verse_number('15', 0)
# THEN: parse_verse_number should return the verse number
self.assertEqual(result, 15)
assert result == 15
def test_parse_verse_number_verse_range(self):
"""
@ -144,7 +144,7 @@ class TestOpenSongImport(TestCase, TestMixin):
result = importer.parse_verse_number('24-26', 0)
# THEN: parse_verse_number should return the first verse number in the range
self.assertEqual(result, 24)
assert result == 24
def test_parse_verse_number_invalid_verse_no(self):
"""
@ -157,7 +157,7 @@ class TestOpenSongImport(TestCase, TestMixin):
result = importer.parse_verse_number('invalid', 41)
# THEN: parse_verse_number should increment the previous verse number
self.assertEqual(result, 42)
assert result == 42
def test_parse_verse_number_empty_attribute(self):
"""
@ -169,7 +169,7 @@ class TestOpenSongImport(TestCase, TestMixin):
result = importer.parse_verse_number('', 14)
# THEN: parse_verse_number should increment the previous verse number
self.assertEqual(result, 15)
assert result == 15
def test_parse_verse_number_invalid_type(self):
"""
@ -185,7 +185,7 @@ class TestOpenSongImport(TestCase, TestMixin):
# THEN: parse_verse_number should log the verse number it was called with increment the previous verse
# number
mocked_log_warning.assert_called_once_with('Illegal verse number: (1, 2, 3)')
self.assertEqual(result, 13)
assert result == 13
def test_process_books_stop_import(self):
"""
@ -199,7 +199,7 @@ class TestOpenSongImport(TestCase, TestMixin):
importer.process_books(['Book'])
# THEN: find_and_create_book should not have been called
self.assertFalse(self.mocked_find_and_create_book.called)
assert self.mocked_find_and_create_book.called is False
def test_process_books_completes(self):
"""
@ -224,11 +224,10 @@ class TestOpenSongImport(TestCase, TestMixin):
importer.process_books([book1, book2])
# THEN: find_and_create_book and process_books should be called with the details from the mocked books
self.assertEqual(self.mocked_find_and_create_book.call_args_list,
[call('Name1', 2, 10), call('Name2', 2, 10)])
self.assertEqual(mocked_process_chapters.call_args_list,
[call('db_book1', 'Chapter1'), call('db_book2', 'Chapter2')])
self.assertEqual(importer.session.commit.call_count, 2)
assert self.mocked_find_and_create_book.call_args_list == [call('Name1', 2, 10), call('Name2', 2, 10)]
assert mocked_process_chapters.call_args_list == \
[call('db_book1', 'Chapter1'), call('db_book2', 'Chapter2')]
assert importer.session.commit.call_count == 2
def test_process_chapters_stop_import(self):
"""
@ -243,7 +242,7 @@ class TestOpenSongImport(TestCase, TestMixin):
importer.process_chapters('Book', ['Chapter1'])
# THEN: importer.parse_chapter_number not have been called
self.assertFalse(importer.parse_chapter_number.called)
assert importer.parse_chapter_number.called is False
@patch('openlp.plugins.bibles.lib.importers.opensong.parse_chapter_number', **{'side_effect': [1, 2]})
def test_process_chapters_completes(self, mocked_parse_chapter_number):
@ -271,12 +270,11 @@ class TestOpenSongImport(TestCase, TestMixin):
importer.process_chapters(book, [chapter1, chapter2])
# THEN: parse_chapter_number, process_verses and increment_process_bar should have been called
self.assertEqual(mocked_parse_chapter_number.call_args_list, [call('1', 0), call('2', 1)])
self.assertEqual(
importer.process_verses.call_args_list,
[call(book, 1, ['Chapter1 Verses']), call(book, 2, ['Chapter2 Verses'])])
self.assertEqual(importer.wizard.increment_progress_bar.call_args_list,
[call('Importing Book 1...'), call('Importing Book 2...')])
assert mocked_parse_chapter_number.call_args_list == [call('1', 0), call('2', 1)]
assert importer.process_verses.call_args_list == \
[call(book, 1, ['Chapter1 Verses']), call(book, 2, ['Chapter2 Verses'])]
assert importer.wizard.increment_progress_bar.call_args_list == [call('Importing Book 1...'),
call('Importing Book 2...')]
def test_process_verses_stop_import(self):
"""
@ -291,7 +289,7 @@ class TestOpenSongImport(TestCase, TestMixin):
importer.process_verses('Book', 1, 'Verses')
# THEN: importer.parse_verse_number not have been called
self.assertFalse(importer.parse_verse_number.called)
assert importer.parse_verse_number.called is False
def test_process_verses_completes(self):
"""
@ -322,11 +320,10 @@ class TestOpenSongImport(TestCase, TestMixin):
importer.process_verses(book, 1, [verse1, verse2])
# THEN: parse_chapter_number, process_verses and increment_process_bar should have been called
self.assertEqual(mocked_parse_verse_number.call_args_list, [call('1', 0), call('2', 1)])
self.assertEqual(mocked_get_text.call_args_list, [call(verse1), call(verse2)])
self.assertEqual(
importer.create_verse.call_args_list,
[call(1, 1, 1, 'Verse1 Text'), call(1, 1, 2, 'Verse2 Text')])
assert mocked_parse_verse_number.call_args_list == [call('1', 0), call('2', 1)]
assert mocked_get_text.call_args_list == [call(verse1), call(verse2)]
assert importer.create_verse.call_args_list == \
[call(1, 1, 1, 'Verse1 Text'), call(1, 1, 2, 'Verse2 Text')]
def test_do_import_parse_xml_fails(self):
"""
@ -343,8 +340,8 @@ class TestOpenSongImport(TestCase, TestMixin):
result = importer.do_import()
# THEN: do_import should return False and get_language_id should have not been called
self.assertFalse(result)
self.assertFalse(mocked_language_id.called)
assert result is False
assert mocked_language_id.called is False
def test_do_import_no_language(self):
"""
@ -362,8 +359,8 @@ class TestOpenSongImport(TestCase, TestMixin):
result = importer.do_import()
# THEN: do_import should return False and process_books should have not been called
self.assertFalse(result)
self.assertFalse(mocked_process_books.called)
assert result is False
assert mocked_process_books.called is False
def test_do_import_completes(self):
"""
@ -381,7 +378,7 @@ class TestOpenSongImport(TestCase, TestMixin):
result = importer.do_import()
# THEN: do_import should return True
self.assertTrue(result)
assert result is True
class TestOpenSongImportFileImports(TestCase, TestMixin):
@ -418,6 +415,6 @@ class TestOpenSongImportFileImports(TestCase, TestMixin):
importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file.
self.assertTrue(importer.create_verse.called)
assert importer.create_verse.called is True
for verse_tag, verse_text in test_data['verses']:
importer.create_verse.assert_any_call(importer.create_book().id, 1, int(verse_tag), verse_text)

View File

@ -67,7 +67,7 @@ class TestOsisImport(TestCase):
importer = OSISBible(mocked_manager, path='.', name='.', file_path=None)
# THEN: The importer should be an instance of BibleDB
self.assertIsInstance(importer, BibleDB)
assert isinstance(importer, BibleDB)
def test_process_books_stop_import(self):
"""
@ -82,7 +82,7 @@ class TestOsisImport(TestCase):
importer.process_books(mocked_data)
# THEN: find_and_create_book should not have been called
self.assertFalse(self.mocked_find_and_create_book.called)
assert self.mocked_find_and_create_book.called is False
def test_process_books_completes(self):
"""
@ -106,11 +106,9 @@ class TestOsisImport(TestCase):
importer.process_books(mocked_data)
# THEN: find_and_create_book and process_books should be called with the details from the mocked books
self.assertEqual(self.mocked_find_and_create_book.call_args_list,
[call('Name1', 2, 10), call('Name2', 2, 10)])
self.assertEqual(mocked_process_chapters.call_args_list,
[call('db_book1', book1), call('db_book2', book2)])
self.assertEqual(importer.session.commit.call_count, 2)
assert self.mocked_find_and_create_book.call_args_list == [call('Name1', 2, 10), call('Name2', 2, 10)]
assert mocked_process_chapters.call_args_list == [call('db_book1', book1), call('db_book2', book2)]
assert importer.session.commit.call_count == 2
def test_process_chapters_verse_in_chapter_verse_text(self):
"""
@ -185,8 +183,8 @@ class TestOsisImport(TestCase):
importer.process_chapters(test_book, [test_chapter])
# THEN: neither set_current_chapter or process_verse should have been called
self.assertFalse(mocked_set_current_chapter.called)
self.assertFalse(mocked_process_verse.called)
assert mocked_set_current_chapter.called is False
assert mocked_process_verse.called is False
def test_process_chapters_milestones_chapter_sid(self):
"""
@ -209,7 +207,7 @@ class TestOsisImport(TestCase):
# THEN: set_current_chapter should have been called with the test data
mocked_set_current_chapter.assert_called_once_with(test_book.name, 2)
self.assertFalse(mocked_process_verse.called)
assert mocked_process_verse.called is False
def test_process_chapters_milestones_verse_tag(self):
"""
@ -233,7 +231,7 @@ class TestOsisImport(TestCase):
importer.process_chapters(test_book, [test_verse])
# THEN: process_verse should have been called with the test data
self.assertFalse(mocked_set_current_chapter.called)
assert mocked_set_current_chapter.called is False
mocked_process_verse.assert_called_once_with(test_book, 0, test_verse, use_milestones=True)
def test_process_verse_no_osis_id(self):
@ -252,7 +250,7 @@ class TestOsisImport(TestCase):
importer.process_verse(test_book, 2, test_verse)
# THEN: create_verse should not have been called
self.assertFalse(self.mocked_create_verse.called)
assert self.mocked_create_verse.called is False
def test_process_verse_use_milestones_no_s_id(self):
"""
@ -271,7 +269,7 @@ class TestOsisImport(TestCase):
importer.process_verse(test_book, 2, test_verse)
# THEN: create_verse should not have been called
self.assertFalse(self.mocked_create_verse.called)
assert self.mocked_create_verse.called is False
def test_process_verse_use_milestones_no_tail(self):
"""
@ -289,7 +287,7 @@ class TestOsisImport(TestCase):
importer.process_verse(test_book, 2, test_verse, use_milestones=True)
# THEN: create_verse should not have been called
self.assertFalse(self.mocked_create_verse.called)
assert self.mocked_create_verse.called is False
def test_process_verse_use_milestones_success(self):
"""
@ -327,7 +325,7 @@ class TestOsisImport(TestCase):
importer.process_verse(test_book, 2, test_verse)
# THEN: create_verse should not have been called
self.assertFalse(self.mocked_create_verse.called)
assert self.mocked_create_verse.called is False
def test_process_verse_success(self):
"""
@ -363,8 +361,8 @@ class TestOsisImport(TestCase):
result = importer.do_import()
# THEN: do_import should return False and get_language_id should have not been called
self.assertFalse(result)
self.assertFalse(mocked_language_id.called)
assert result is False
assert mocked_language_id.called is False
def test_do_import_no_language(self):
"""
@ -382,8 +380,8 @@ class TestOsisImport(TestCase):
result = importer.do_import()
# THEN: do_import should return False and process_books should have not been called
self.assertFalse(result)
self.assertFalse(mocked_process_books.called)
assert result is False
assert mocked_process_books.called is False
def test_do_import_completes(self):
"""
@ -401,7 +399,7 @@ class TestOsisImport(TestCase):
result = importer.do_import()
# THEN: do_import should return True
self.assertTrue(result)
assert result is True
class TestOsisImportFileImports(TestCase):
@ -441,7 +439,7 @@ class TestOsisImportFileImports(TestCase):
importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file.
self.assertTrue(importer.create_verse.called)
assert importer.create_verse.called is True
for verse_tag, verse_text in test_data['verses']:
importer.create_verse.assert_any_call(importer.create_book().id, 1, verse_tag, verse_text)
@ -470,7 +468,7 @@ class TestOsisImportFileImports(TestCase):
importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file.
self.assertTrue(importer.create_verse.called)
assert importer.create_verse.called is True
for verse_tag, verse_text in test_data['verses']:
importer.create_verse.assert_any_call(importer.create_book().id, 1, verse_tag, verse_text)
@ -499,7 +497,7 @@ class TestOsisImportFileImports(TestCase):
importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file.
self.assertTrue(importer.create_verse.called)
assert importer.create_verse.called
for verse_tag, verse_text in test_data['verses']:
importer.create_verse.assert_any_call(importer.create_book().id, 1, verse_tag, verse_text)
@ -528,6 +526,6 @@ class TestOsisImportFileImports(TestCase):
importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file.
self.assertTrue(importer.create_verse.called)
assert importer.create_verse.called is True
for verse_tag, verse_text in test_data['verses']:
importer.create_verse.assert_any_call(importer.create_book().id, 1, verse_tag, verse_text)

View File

@ -66,7 +66,7 @@ class TestSwordImport(TestCase):
importer = SwordBible(mocked_manager, path='.', name='.', file_path=None, sword_key='', sword_path='')
# THEN: The importer should be an instance of BibleDB
self.assertIsInstance(importer, BibleDB)
assert isinstance(importer, BibleDB)
@patch('openlp.plugins.bibles.lib.importers.sword.SwordBible.application')
@patch('openlp.plugins.bibles.lib.importers.sword.modules')
@ -104,6 +104,6 @@ class TestSwordImport(TestCase):
importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file.
self.assertTrue(importer.create_verse.called)
assert importer.create_verse.called is True
for verse_tag, verse_text in test_data['verses']:
importer.create_verse.assert_any_call(importer.create_book().id, 1, int(verse_tag), verse_text)

View File

@ -48,14 +48,12 @@ class TestVerseReferenceList(TestCase):
reference_list.add(book, chapter, verse, version, copyright_, permission)
# THEN: The entries should be in the first entry of the list
self.assertEqual(reference_list.current_index, 0, 'The current index should be 0')
self.assertEqual(reference_list.verse_list[0]['book'], book, 'The book in first entry should be %s' % book)
self.assertEqual(reference_list.verse_list[0]['chapter'], chapter, 'The chapter in first entry should be %u' %
chapter)
self.assertEqual(reference_list.verse_list[0]['start'], verse, 'The start in first entry should be %u' % verse)
self.assertEqual(reference_list.verse_list[0]['version'], version, 'The version in first entry should be %s' %
version)
self.assertEqual(reference_list.verse_list[0]['end'], verse, 'The end in first entry should be %u' % verse)
assert reference_list.current_index == 0, 'The current index should be 0'
assert reference_list.verse_list[0]['book'] == book, 'The book in first entry should be %s' % book
assert reference_list.verse_list[0]['chapter'] == chapter, 'The chapter in first entry should be %u' % chapter
assert reference_list.verse_list[0]['start'] == verse, 'The start in first entry should be %u' % verse
assert reference_list.verse_list[0]['version'] == version, 'The version in first entry should be %s' % version
assert reference_list.verse_list[0]['end'] == verse, 'The end in first entry should be %u' % verse
def test_add_next_verse(self):
"""
@ -76,9 +74,8 @@ class TestVerseReferenceList(TestCase):
reference_list.add(book, chapter, next_verse, version, copyright_, permission)
# THEN: The current index should be 0 and the end pointer of the entry should be '2'
self.assertEqual(reference_list.current_index, 0, 'The current index should be 0')
self.assertEqual(reference_list.verse_list[0]['end'], next_verse,
'The end in first entry should be %u' % next_verse)
assert reference_list.current_index == 0, 'The current index should be 0'
assert reference_list.verse_list[0]['end'] == next_verse, 'The end in first entry should be %u' % next_verse
def test_add_another_verse(self):
"""
@ -101,7 +98,7 @@ class TestVerseReferenceList(TestCase):
reference_list.add(another_book, another_chapter, another_verse, version, copyright_, permission)
# THEN: the current index should be 1
self.assertEqual(reference_list.current_index, 1, 'The current index should be 1')
assert reference_list.current_index == 1, 'The current index should be 1'
def test_add_version(self):
"""
@ -117,10 +114,10 @@ class TestVerseReferenceList(TestCase):
reference_list.add_version(version, copyright_, permission)
# THEN: the data will be appended to the list
self.assertEqual(len(reference_list.version_list), 1, 'The version data should be appended')
self.assertEqual(reference_list.version_list[0],
{'version': version, 'copyright': copyright_, 'permission': permission},
'The version data should be appended')
assert len(reference_list.version_list) == 1, 'The version data should be appended'
assert reference_list.version_list[0] == \
{'version': version, 'copyright': copyright_, 'permission': permission}, \
'The version data should be appended'
def test_add_existing_version(self):
"""
@ -137,4 +134,4 @@ class TestVerseReferenceList(TestCase):
reference_list.add_version(version, copyright_, permission)
# THEN: the data will not be appended to the list
self.assertEqual(len(reference_list.version_list), 1, 'The version data should not be appended')
assert len(reference_list.version_list) == 1, 'The version data should not be appended'

View File

@ -58,7 +58,7 @@ class TestZefaniaImport(TestCase):
importer = ZefaniaBible(mocked_manager, path='.', name='.', file_path=None)
# THEN: The importer should be an instance of BibleDB
self.assertIsInstance(importer, BibleDB)
assert isinstance(importer, BibleDB)
def test_file_import(self):
"""
@ -84,7 +84,7 @@ class TestZefaniaImport(TestCase):
importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file.
self.assertTrue(importer.create_verse.called)
assert importer.create_verse.called is True
for verse_tag, verse_text in test_data['verses']:
importer.create_verse.assert_any_call(importer.create_book().id, 1, verse_tag, verse_text)
importer.create_book.assert_any_call('Genesis', 1, 1)
@ -113,7 +113,7 @@ class TestZefaniaImport(TestCase):
importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file.
self.assertTrue(importer.create_verse.called)
assert importer.create_verse.called is True
for verse_tag, verse_text in test_data['verses']:
importer.create_verse.assert_any_call(importer.create_book().id, 1, verse_tag, verse_text)
importer.create_book.assert_any_call('Exodus', 2, 1)

View File

@ -73,7 +73,7 @@ class TestMediaItem(TestCase, TestMixin):
item = self.media_item.service_load(service_item)
# THEN: the processing should be ignored
self.assertEqual(item, None, 'The Service item is inactive so processing should be bypassed')
assert item is None, 'The Service item is inactive so processing should be bypassed'
def test_service_load_basic_custom_false(self):
"""
@ -95,8 +95,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.service_load(service_item)
# THEN: the item should not be added to the database.
self.assertEqual(self.media_item.create_from_service_item.call_count, 0,
'The item should not have been added to the database')
assert self.media_item.create_from_service_item.call_count == 0, \
'The item should not have been added to the database'
def test_service_load_basic_custom_true(self):
"""
@ -118,5 +118,5 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.service_load(service_item)
# THEN: the item should not be added to the database.
self.assertEqual(self.media_item.create_from_service_item.call_count, 1,
'The item should have been added to the database')
assert self.media_item.create_from_service_item.call_count == 1, \
'The item should have been added to the database'

View File

@ -74,8 +74,8 @@ class TestImageMediaItem(TestCase, TestMixin):
# WHEN: the save is invoked
self.form.save()
# THEN: the post process should not be requested
self.assertEqual(0, self.form.settings_form.register_post_process.call_count,
'Image Post processing should not have been requested')
assert 0 == self.form.settings_form.register_post_process.call_count, \
'Image Post processing should not have been requested'
def test_save_tab_change(self):
"""
@ -86,7 +86,7 @@ class TestImageMediaItem(TestCase, TestMixin):
# WHEN: the save is invoked
self.form.save()
# THEN: the post process should be requested
self.assertEqual(1, self.form.settings_form.register_post_process.call_count,
'Image Post processing should have been requested')
assert 1 == self.form.settings_form.register_post_process.call_count, \
'Image Post processing should have been requested'
# THEN: The color should be set
self.assertEqual(self.form.background_color, '#999999', 'The updated color should have been saved')
assert self.form.background_color == '#999999', 'The updated color should have been saved'

View File

@ -98,8 +98,8 @@ class TestImageMediaItem(TestCase):
self.media_item.save_new_images_list(image_list)
# THEN: The save_object() method should not have been called
self.assertEquals(self.media_item.manager.save_object.call_count, 0,
'The save_object() method should not have been called')
assert self.media_item.manager.save_object.call_count == 0, \
'The save_object() method should not have been called'
@patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.load_full_list')
def test_save_new_images_list_single_image_with_reload(self, mocked_load_full_list):
@ -115,7 +115,7 @@ class TestImageMediaItem(TestCase):
self.media_item.save_new_images_list(image_list, reload_list=True)
# THEN: load_full_list() should have been called
self.assertEquals(mocked_load_full_list.call_count, 1, 'load_full_list() should have been called')
assert mocked_load_full_list.call_count == 1, 'load_full_list() should have been called'
# CLEANUP: Remove added attribute from ImageFilenames
delattr(ImageFilenames, 'file_path')
@ -133,7 +133,7 @@ class TestImageMediaItem(TestCase):
self.media_item.save_new_images_list(image_list, reload_list=False)
# THEN: load_full_list() should not have been called
self.assertEquals(mocked_load_full_list.call_count, 0, 'load_full_list() should not have been called')
assert mocked_load_full_list.call_count == 0, 'load_full_list() should not have been called'
@patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.load_full_list')
def test_save_new_images_list_multiple_images(self, mocked_load_full_list):
@ -148,8 +148,8 @@ class TestImageMediaItem(TestCase):
self.media_item.save_new_images_list(image_list, reload_list=False)
# THEN: load_full_list() should not have been called
self.assertEquals(self.media_item.manager.save_object.call_count, 3,
'load_full_list() should have been called three times')
assert self.media_item.manager.save_object.call_count == 3, \
'load_full_list() should have been called three times'
@patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.load_full_list')
def test_save_new_images_list_other_objects_in_list(self, mocked_load_full_list):
@ -164,8 +164,7 @@ class TestImageMediaItem(TestCase):
self.media_item.save_new_images_list(image_list, reload_list=False)
# THEN: load_full_list() should not have been called
self.assertEquals(self.media_item.manager.save_object.call_count, 2,
'load_full_list() should have been called only once')
assert self.media_item.manager.save_object.call_count == 2, 'load_full_list() should have been called only once'
def test_on_reset_click(self):
"""
@ -201,9 +200,9 @@ class TestImageMediaItem(TestCase):
self.media_item.recursively_delete_group(test_group)
# THEN: delete_file() should have been called 12 times and manager.delete_object() 7 times.
self.assertEquals(mocked_delete_file.call_count, 12, 'delete_file() should have been called 12 times')
self.assertEquals(self.media_item.manager.delete_object.call_count, 7,
'manager.delete_object() should be called exactly 7 times')
assert mocked_delete_file.call_count == 12, 'delete_file() should have been called 12 times'
assert self.media_item.manager.delete_object.call_count == 7, \
'manager.delete_object() should be called exactly 7 times'
# CLEANUP: Remove added attribute from Image Filenames and ImageGroups
delattr(ImageFilenames, 'group_id')
@ -258,7 +257,7 @@ class TestImageMediaItem(TestCase):
self.media_item.on_delete_click()
# THEN: delete_file should have been called twice
self.assertEquals(mocked_delete_file.call_count, 2, 'delete_file() should have been called twice')
assert mocked_delete_file.call_count == 2, 'delete_file() should have been called twice'
def test_create_item_from_id(self):
"""
@ -276,9 +275,9 @@ class TestImageMediaItem(TestCase):
item = self.media_item.create_item_from_id('1')
# THEN: A QTreeWidgetItem should be created with the above model object as it's data
self.assertIsInstance(item, QtWidgets.QTreeWidgetItem)
self.assertEqual('test_file_1.jpg', item.text(0))
assert isinstance(item, QtWidgets.QTreeWidgetItem)
assert 'test_file_1.jpg' == item.text(0)
item_data = item.data(0, QtCore.Qt.UserRole)
self.assertIsInstance(item_data, ImageFilenames)
self.assertEqual(1, item_data.id)
self.assertEqual(Path('/', 'tmp', 'test_file_1.jpg'), item_data.file_path)
assert isinstance(item_data, ImageFilenames)
assert 1 == item_data.id
assert Path('/', 'tmp', 'test_file_1.jpg') == item_data.file_path

View File

@ -80,6 +80,6 @@ class TestImageDBUpgrade(TestCase, TestMixin):
2: Path('/', 'test', 'dir', 'image2.jpg'),
3: Path('/', 'test', 'dir', 'subdir', 'image3.jpg')}
self.assertEqual(len(upgraded_results), 3)
assert len(upgraded_results) == 3
for result in upgraded_results:
self.assertEqual(expected_result_data[result.id], result.file_path)
assert expected_result_data[result.id] == result.file_path

View File

@ -71,7 +71,7 @@ class MediaItemTest(TestCase, TestMixin):
# WHEN: Retrieving the test file
result = self.media_item.search('test.mp4', False)
# THEN: a file should be found
self.assertEqual(result, [['test.mp4', 'test.mp4']], 'The result file contain the file name')
assert result == [['test.mp4', 'test.mp4']], 'The result file contain the file name'
def test_search_not_found(self):
"""
@ -82,4 +82,4 @@ class MediaItemTest(TestCase, TestMixin):
# WHEN: Retrieving the test file
result = self.media_item.search('test.mpx', False)
# THEN: a file should be found
self.assertEqual(result, [], 'The result file should be empty')
assert result == [], 'The result file should be empty'

View File

@ -56,9 +56,9 @@ class MediaPluginTest(TestCase, TestMixin):
# GIVEN: The MediaPlugin
# WHEN: Retrieving the about text
# THEN: about() should return a string object
self.assertIsInstance(MediaPlugin.about(), str)
assert isinstance(MediaPlugin.about(), str)
# THEN: about() should return a non-empty string
self.assertNotEquals(len(MediaPlugin.about()), 0)
assert len(MediaPlugin.about()) is not 0
@patch('openlp.plugins.media.mediaplugin.check_binary_exists')
def test_process_check_binary_pass(self, mocked_checked_binary_exists):
@ -71,7 +71,7 @@ class MediaPluginTest(TestCase, TestMixin):
result = process_check_binary('MediaInfo')
# THEN: The the result should be True
self.assertTrue(result, 'Mediainfo should have been found')
assert result is True, 'Mediainfo should have been found'
@patch('openlp.plugins.media.mediaplugin.check_binary_exists')
def test_process_check_binary_fail(self, mocked_checked_binary_exists):
@ -84,4 +84,4 @@ class MediaPluginTest(TestCase, TestMixin):
result = process_check_binary("MediaInfo1")
# THEN: The the result should be True
self.assertFalse(result, "Mediainfo should not have been found")
assert result is False, "Mediainfo should not have been found"

View File

@ -69,8 +69,7 @@ class TestImpressController(TestCase, TestMixin):
controller = ImpressController(plugin=self.mock_plugin)
# THEN: The name of the presentation controller should be correct
self.assertEqual('Impress', controller.name,
'The name of the presentation controller should be correct')
assert 'Impress' == controller.name, 'The name of the presentation controller should be correct'
@patch('openlp.plugins.presentations.lib.impresscontroller.log')
def test_check_available(self, mocked_log):
@ -179,22 +178,21 @@ class TestImpressDocument(TestCase):
result = self.doc._ImpressDocument__get_text_from_page(0, TextType.Notes)
# THEN: the result should be an empty string
self.assertEqual(result, '', 'Result should be an empty string')
assert result == '', 'Result should be an empty string'
# WHEN: regardless of the type of text, index 0x00 is out of bounds
result = self.doc._ImpressDocument__get_text_from_page(0, TextType.Title)
# THEN: result should be an empty string
self.assertEqual(result, '', 'Result should be an empty string')
assert result == '', 'Result should be an empty string'
# WHEN: when called with 2, it should also be out of bounds
result = self.doc._ImpressDocument__get_text_from_page(2, TextType.SlideText)
# THEN: result should be an empty string ... and, getByIndex should
# have never been called
self.assertEqual(result, '', 'Result should be an empty string')
self.assertEqual(self.doc.document.getDrawPages().getByIndex.call_count, 0,
'There should be no call to getByIndex')
assert result == '', 'Result should be an empty string'
assert self.doc.document.getDrawPages().getByIndex.call_count == 0, 'There should be no call to getByIndex'
def test_get_text_from_page_wrong_type(self):
"""
@ -208,9 +206,8 @@ class TestImpressDocument(TestCase):
result = self.doc._ImpressDocument__get_text_from_page(1, 3)
# THEN: result should be an empty string
self.assertEqual(result, '', 'Result should be and empty string')
self.assertEqual(self.doc.document.getDrawPages().getByIndex.call_count, 0,
'There should be no call to getByIndex')
assert result == '', 'Result should be and empty string'
assert self.doc.document.getDrawPages().getByIndex.call_count == 0, 'There should be no call to getByIndex'
def test_get_text_from_page_valid_params(self):
"""
@ -224,19 +221,19 @@ class TestImpressDocument(TestCase):
result = self.doc._ImpressDocument__get_text_from_page(1, TextType.Notes)
# THEN: result should be 'Note\nNote\n'
self.assertEqual(result, 'Note\nNote\n', 'Result should be \'Note\\n\' times the count of notes in the page')
assert result == 'Note\nNote\n', 'Result should be \'Note\\n\' times the count of notes in the page'
# WHEN: get the Title
result = self.doc._ImpressDocument__get_text_from_page(1, TextType.Title)
# THEN: result should be 'Title\n'
self.assertEqual(result, 'Title\n', 'Result should be exactly \'Title\\n\'')
assert result == 'Title\n', 'Result should be exactly \'Title\\n\''
# WHEN: get all text
result = self.doc._ImpressDocument__get_text_from_page(1, TextType.SlideText)
# THEN: result should be 'Title\nString\nString\n'
self.assertEqual(result, 'Title\nString\nString\n', 'Result should be exactly \'Title\\nString\\nString\\n\'')
assert result == 'Title\nString\nString\n', 'Result should be exactly \'Title\\nString\\nString\\n\''
def _mock_a_LibreOffice_document(self, page_count, note_count, text_count):
"""

View File

@ -81,11 +81,11 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.build_file_mask_string()
# THEN: The file mask should be generated correctly
self.assertIn('*.odp', self.media_item.on_new_file_masks, 'The file mask should contain the odp extension')
self.assertIn('*.ppt', self.media_item.on_new_file_masks, 'The file mask should contain the ppt extension')
self.assertIn('*.pdf', self.media_item.on_new_file_masks, 'The file mask should contain the pdf extension')
self.assertIn('*.xps', self.media_item.on_new_file_masks, 'The file mask should contain the xps extension')
self.assertIn('*.oxps', self.media_item.on_new_file_masks, 'The file mask should contain the oxps extension')
assert '*.odp' in self.media_item.on_new_file_masks, 'The file mask should contain the odp extension'
assert '*.ppt' in self.media_item.on_new_file_masks, 'The file mask should contain the ppt extension'
assert '*.pdf' in self.media_item.on_new_file_masks, 'The file mask should contain the pdf extension'
assert '*.xps' in self.media_item.on_new_file_masks, 'The file mask should contain the xps extension'
assert '*.oxps' in self.media_item.on_new_file_masks, 'The file mask should contain the oxps extension'
def test_clean_up_thumbnails(self):
"""

View File

@ -73,7 +73,7 @@ class TestMessageListener(TestCase, TestMixin):
ml.startup([mock_item, False, False, False])
# THEN: The controllers will be setup.
self.assertTrue(len(controllers), 'We have loaded a controller')
assert len(controllers) > 0, 'We have loaded a controller'
@patch('openlp.plugins.presentations.lib.mediaitem.MessageListener._setup')
def test_start_presentation_with_no_player(self, media_mock):
@ -105,7 +105,7 @@ class TestMessageListener(TestCase, TestMixin):
ml.startup([mock_item, False, False, False])
# THEN: The controllers will be setup.
self.assertTrue(len(controllers), 'We have loaded a controller')
assert len(controllers) > 0, 'We have loaded a controller'
@patch('openlp.plugins.presentations.lib.mediaitem.MessageListener._setup')
def test_start_pdf_presentation(self, media_mock):
@ -125,7 +125,7 @@ class TestMessageListener(TestCase, TestMixin):
ml.startup([mock_item, False, False, False])
# THEN: The handler should be set to None
self.assertIsNone(ml.handler, 'The handler should be None')
assert ml.handler is None, 'The handler should be None'
class TestController(TestCase, TestMixin):
@ -148,4 +148,4 @@ class TestController(TestCase, TestMixin):
controller.add_handler(mocked_doc_controller, MagicMock(), True, 0)
# THEN: slidenumber should be 0
self.assertEqual(controller.doc.slidenumber, 0, 'doc.slidenumber should be 0')
assert controller.doc.slidenumber == 0, 'doc.slidenumber should be 0'

View File

@ -92,7 +92,7 @@ class TestPdfController(TestCase, TestMixin):
controller = PdfController(plugin=self.mock_plugin)
# THEN: The name of the presentation controller should be correct
self.assertEqual('Pdf', controller.name, 'The name of the presentation controller should be correct')
assert 'Pdf' == controller.name, 'The name of the presentation controller should be correct'
def test_load_pdf(self):
"""
@ -111,8 +111,8 @@ class TestPdfController(TestCase, TestMixin):
loaded = document.load_presentation()
# THEN: The load should succeed and we should be able to get a pagecount
self.assertTrue(loaded, 'The loading of the PDF should succeed.')
self.assertEqual(3, document.get_slide_count(), 'The pagecount of the PDF should be 3.')
assert loaded is True, 'The loading of the PDF should succeed.'
assert 3 == document.get_slide_count(), 'The pagecount of the PDF should be 3.'
def test_load_pdf_pictures(self):
"""
@ -131,15 +131,15 @@ class TestPdfController(TestCase, TestMixin):
loaded = document.load_presentation()
# THEN: The load should succeed and pictures should be created and have been scales to fit the screen
self.assertTrue(loaded, 'The loading of the PDF should succeed.')
assert loaded is True, 'The loading of the PDF should succeed.'
image = QtGui.QImage(os.path.join(str(self.temp_folder_path), 'pdf_test1.pdf', 'mainslide001.png'))
# Based on the converter used the resolution will differ a bit
if controller.gsbin:
self.assertEqual(760, image.height(), 'The height should be 760')
self.assertEqual(537, image.width(), 'The width should be 537')
assert 760 == image.height(), 'The height should be 760'
assert 537 == image.width(), 'The width should be 537'
else:
self.assertEqual(768, image.height(), 'The height should be 768')
self.assertEqual(543, image.width(), 'The width should be 543')
assert 768 == image.height(), 'The height should be 768'
assert 543 == image.width(), 'The width should be 543'
@patch('openlp.plugins.presentations.lib.pdfcontroller.check_binary_exists')
def test_process_check_binary_mudraw(self, mocked_check_binary_exists):
@ -157,7 +157,7 @@ class TestPdfController(TestCase, TestMixin):
ret = PdfController.process_check_binary('test')
# THEN: mudraw should be detected
self.assertEqual('mudraw', ret, 'mudraw should have been detected')
assert 'mudraw' == ret, 'mudraw should have been detected'
@patch('openlp.plugins.presentations.lib.pdfcontroller.check_binary_exists')
def test_process_check_binary_new_motool(self, mocked_check_binary_exists):
@ -177,7 +177,7 @@ class TestPdfController(TestCase, TestMixin):
ret = PdfController.process_check_binary('test')
# THEN: mutool should be detected
self.assertEqual('mutool', ret, 'mutool should have been detected')
assert 'mutool' == ret, 'mutool should have been detected'
@patch('openlp.plugins.presentations.lib.pdfcontroller.check_binary_exists')
def test_process_check_binary_old_motool(self, mocked_check_binary_exists):
@ -194,7 +194,7 @@ class TestPdfController(TestCase, TestMixin):
ret = PdfController.process_check_binary('test')
# THEN: mutool should be detected
self.assertIsNone(ret, 'old mutool should not be accepted!')
assert ret is None, 'old mutool should not be accepted!'
@patch('openlp.plugins.presentations.lib.pdfcontroller.check_binary_exists')
def test_process_check_binary_gs(self, mocked_check_binary_exists):
@ -210,4 +210,4 @@ class TestPdfController(TestCase, TestMixin):
ret = PdfController.process_check_binary('test')
# THEN: mutool should be detected
self.assertEqual('gs', ret, 'mutool should have been detected')
assert 'gs' == ret, 'mutool should have been detected'

View File

@ -77,8 +77,7 @@ class TestPowerpointController(TestCase, TestMixin):
controller = PowerpointController(plugin=self.mock_plugin)
# THEN: The name of the presentation controller should be correct
self.assertEqual('Powerpoint', controller.name,
'The name of the presentation controller should be correct')
assert 'Powerpoint' == controller.name, 'The name of the presentation controller should be correct'
class TestPowerpointDocument(TestCase, TestMixin):
@ -157,7 +156,7 @@ class TestPowerpointDocument(TestCase, TestMixin):
result = doc.is_loaded()
# THEN: result should be true
self.assertEqual(result, True, 'The result should be True')
assert result is True, 'The result should be True'
else:
self.skipTest('Powerpoint not available, skipping test.')
@ -217,7 +216,7 @@ class TestPowerpointDocument(TestCase, TestMixin):
result = _get_text_from_shapes(shapes)
# THEN: it should return the text
self.assertEqual(result, 'slideText\nslideText\n', 'result should match \'slideText\nslideText\n\'')
assert result == 'slideText\nslideText\n', 'result should match \'slideText\nslideText\n\''
def test_get_text_from_shapes_with_no_shapes(self):
"""
@ -230,7 +229,7 @@ class TestPowerpointDocument(TestCase, TestMixin):
result = _get_text_from_shapes(shapes)
# THEN: it should not fail but return empty string
self.assertEqual(result, '', 'result should be empty')
assert result == '', 'result should be empty'
def test_goto_slide(self):
"""
@ -250,7 +249,7 @@ class TestPowerpointDocument(TestCase, TestMixin):
doc.goto_slide(1)
# THEN: next_step() should be call to try to advance to the next effect.
self.assertTrue(doc.next_step.called, 'next_step() should have been called!')
assert doc.next_step.called is True, 'next_step() should have been called!'
def test_blank_screen(self):
"""
@ -268,9 +267,9 @@ class TestPowerpointDocument(TestCase, TestMixin):
doc.blank_screen()
# THEN: The view state, doc.blank_slide and doc.blank_click should have new values
self.assertEquals(doc.presentation.SlideShowWindow.View.State, 3, 'The View State should be 3')
self.assertEquals(doc.blank_slide, 2, 'doc.blank_slide should be 2 because of the PowerPoint version')
self.assertEquals(doc.blank_click, 3, 'doc.blank_click should be 3 because of the PowerPoint version')
assert doc.presentation.SlideShowWindow.View.State == 3, 'The View State should be 3'
assert doc.blank_slide == 2, 'doc.blank_slide should be 2 because of the PowerPoint version'
assert doc.blank_click == 3, 'doc.blank_click should be 3 because of the PowerPoint version'
def test_unblank_screen(self):
"""
@ -295,10 +294,10 @@ class TestPowerpointDocument(TestCase, TestMixin):
doc.unblank_screen()
# THEN: The view state have new value, and several function should have been called
self.assertEquals(doc.presentation.SlideShowWindow.View.State, 1, 'The View State should be 1')
self.assertEquals(doc.presentation.SlideShowWindow.Activate.called, True,
'SlideShowWindow.Activate should have been called')
self.assertEquals(doc.presentation.SlideShowWindow.View.GotoSlide.called, True,
'View.GotoSlide should have been called because of the PowerPoint version')
self.assertEquals(doc.presentation.SlideShowWindow.View.GotoClick.called, True,
'View.GotoClick should have been called because of the PowerPoint version')
assert doc.presentation.SlideShowWindow.View.State == 1, 'The View State should be 1'
assert doc.presentation.SlideShowWindow.Activate.called is True, \
'SlideShowWindow.Activate should have been called'
assert doc.presentation.SlideShowWindow.View.GotoSlide.called is True, \
'View.GotoSlide should have been called because of the PowerPoint version'
assert doc.presentation.SlideShowWindow.View.GotoClick.called is True, \
'View.GotoClick should have been called because of the PowerPoint version'

View File

@ -67,8 +67,7 @@ class TestPptviewController(TestCase, TestMixin):
controller = PptviewController(plugin=self.mock_plugin)
# THEN: The name of the presentation controller should be correct
self.assertEqual('Powerpoint Viewer', controller.name,
'The name of the presentation controller should be correct')
assert 'Powerpoint Viewer' == controller.name, 'The name of the presentation controller should be correct'
def test_check_available(self):
"""
@ -86,9 +85,9 @@ class TestPptviewController(TestCase, TestMixin):
# THEN: On windows it should return True, on other platforms False
if is_win():
self.assertTrue(available, 'check_available should return True on windows.')
assert available is True, 'check_available should return True on windows.'
else:
self.assertFalse(available, 'check_available should return False when not on windows.')
assert available is False, 'check_available should return False when not on windows.'
class TestPptviewDocument(TestCase):
@ -165,7 +164,7 @@ class TestPptviewDocument(TestCase):
result = instance.load_presentation()
# THEN: The temp folder should be created and PptviewDocument.load_presentation should return False
self.assertFalse(result)
assert result is False
def test_create_titles_and_notes(self):
"""
@ -205,7 +204,7 @@ class TestPptviewDocument(TestCase):
# THEN: File existens should have been checked, and not have been opened.
doc.save_titles_and_notes.assert_called_once_with(None, None)
mocked_path_exists.assert_called_with()
self.assertEqual(mocked_open.call_count, 0, 'There should be no calls to open a file.')
assert mocked_open.call_count == 0, 'There should be no calls to open a file.'
def test_create_titles_and_notes_invalid_file(self):
"""
@ -225,4 +224,4 @@ class TestPptviewDocument(TestCase):
# THEN:
doc.save_titles_and_notes.assert_called_once_with(None, None)
self.assertEqual(mocked_is_zf.call_count, 1, 'is_zipfile should have been called once')
assert mocked_is_zf.call_count == 1, 'is_zipfile should have been called once'

View File

@ -58,8 +58,8 @@ class TestPresentationController(TestCase):
# WHEN: The PresentationController is created
# THEN: The name of the presentation controller should be correct
self.assertEqual('PresentationController', self.presentation.name,
'The name of the presentation controller should be correct')
assert 'PresentationController' == self.presentation.name, \
'The name of the presentation controller should be correct'
def test_save_titles_and_notes(self):
"""
@ -76,7 +76,7 @@ class TestPresentationController(TestCase):
self.document.save_titles_and_notes(titles, notes)
# THEN: the last call to open should have been for slideNotes2.txt
self.assertEqual(mocked_write_text.call_count, 3, 'There should be exactly three files written')
assert mocked_write_text.call_count == 3, 'There should be exactly three files written'
mocked_write_text.assert_has_calls([call('uno\ndos'), call('one'), call('two')])
def test_save_titles_and_notes_with_None(self):
@ -93,7 +93,7 @@ class TestPresentationController(TestCase):
self.document.save_titles_and_notes(titles, notes)
# THEN: No file should have been created
self.assertEqual(mocked_open.call_count, 0, 'No file should be created')
assert mocked_open.call_count == 0, 'No file should be created'
def test_get_titles_and_notes(self):
"""
@ -112,11 +112,11 @@ class TestPresentationController(TestCase):
result_titles, result_notes = self.document.get_titles_and_notes()
# THEN: it should return two items for the titles and two empty strings for the notes
self.assertIs(type(result_titles), list, 'result_titles should be of type list')
self.assertEqual(len(result_titles), 2, 'There should be two items in the titles')
self.assertIs(type(result_notes), list, 'result_notes should be of type list')
self.assertEqual(len(result_notes), 2, 'There should be two items in the notes')
self.assertEqual(mocked_read_text.call_count, 3, 'Three files should be read')
assert type(result_titles) is list, 'result_titles should be of type list'
assert len(result_titles) == 2, 'There should be two items in the titles'
assert type(result_notes) is list, 'result_notes should be of type list'
assert len(result_notes) == 2, 'There should be two items in the notes'
assert mocked_read_text.call_count == 3, 'Three files should be read'
def test_get_titles_and_notes_with_file_not_found(self):
"""
@ -132,10 +132,10 @@ class TestPresentationController(TestCase):
result_titles, result_notes = self.document.get_titles_and_notes()
# THEN: it should return two empty lists
self.assertIsInstance(result_titles, list, 'result_titles should be of type list')
self.assertEqual(len(result_titles), 0, 'there be no titles')
self.assertIsInstance(result_notes, list, 'result_notes should be a list')
self.assertEqual(len(result_notes), 0, 'but the list should be empty')
assert isinstance(result_titles, list), 'result_titles should be of type list'
assert len(result_titles) == 0, 'there be no titles'
assert isinstance(result_notes, list), 'result_notes should be a list'
assert len(result_notes) == 0, 'but the list should be empty'
def test_get_titles_and_notes_with_file_error(self):
"""
@ -151,7 +151,7 @@ class TestPresentationController(TestCase):
result_titles, result_notes = self.document.get_titles_and_notes()
# THEN: it should return two empty lists
self.assertIs(type(result_titles), list, 'result_titles should be a list')
assert type(result_titles) is list, 'result_titles should be a list'
class TestPresentationDocument(TestCase):
@ -226,4 +226,4 @@ class TestPresentationDocument(TestCase):
result = instance.load_presentation()
# THEN: load_presentation should return false
self.assertFalse(result, "PresentationDocument.load_presentation should return false.")
assert result is False, "PresentationDocument.load_presentation should return false."

View File

@ -66,10 +66,10 @@ class TestDB(TestCase):
song.add_author(author)
# THEN: The author should have been added with author_type=None
self.assertEqual(1, len(song.authors_songs))
self.assertEqual("Max", song.authors_songs[0].author.first_name)
self.assertEqual("Mustermann", song.authors_songs[0].author.last_name)
self.assertIsNone(song.authors_songs[0].author_type)
assert 1 == len(song.authors_songs)
assert "Max" == song.authors_songs[0].author.first_name
assert "Mustermann" == song.authors_songs[0].author.last_name
assert song.authors_songs[0].author_type is None
def test_add_author_with_type(self):
"""
@ -86,10 +86,10 @@ class TestDB(TestCase):
song.add_author(author, AuthorType.Words)
# THEN: The author should have been added with author_type=None
self.assertEqual(1, len(song.authors_songs))
self.assertEqual("Max", song.authors_songs[0].author.first_name)
self.assertEqual("Mustermann", song.authors_songs[0].author.last_name)
self.assertEqual(AuthorType.Words, song.authors_songs[0].author_type)
assert 1 == len(song.authors_songs)
assert "Max" == song.authors_songs[0].author.first_name
assert "Mustermann" == song.authors_songs[0].author.last_name
assert AuthorType.Words == song.authors_songs[0].author_type
def test_remove_author(self):
"""
@ -105,7 +105,7 @@ class TestDB(TestCase):
song.remove_author(author)
# THEN: It should have been removed
self.assertEqual(0, len(song.authors_songs))
assert 0 == len(song.authors_songs)
def test_remove_author_with_type(self):
"""
@ -122,8 +122,8 @@ class TestDB(TestCase):
song.remove_author(author, AuthorType.Translation)
# THEN: It should have been removed and the other author should still be there
self.assertEqual(1, len(song.authors_songs))
self.assertEqual(None, song.authors_songs[0].author_type)
assert 1 == len(song.authors_songs)
assert song.authors_songs[0].author_type is None
def test_get_author_type_from_translated_text(self):
"""
@ -136,7 +136,7 @@ class TestDB(TestCase):
author_type = AuthorType.from_translated_text(author_type_name)
# THEN: The type should be correct
self.assertEqual(author_type, AuthorType.Words)
assert author_type == AuthorType.Words
def test_author_get_display_name(self):
"""
@ -150,7 +150,7 @@ class TestDB(TestCase):
display_name = author.get_display_name()
# THEN: It should return only the name
self.assertEqual("John Doe", display_name)
assert "John Doe" == display_name
def test_author_get_display_name_with_type_words(self):
"""
@ -164,7 +164,7 @@ class TestDB(TestCase):
display_name = author.get_display_name(AuthorType.Words)
# THEN: It should return the name with the type in brackets
self.assertEqual("John Doe (Words)", display_name)
assert "John Doe (Words)" == display_name
def test_author_get_display_name_with_type_translation(self):
"""
@ -178,7 +178,7 @@ class TestDB(TestCase):
display_name = author.get_display_name(AuthorType.Translation)
# THEN: It should return the name with the type in brackets
self.assertEqual("John Doe (Translation)", display_name)
assert "John Doe (Translation)" == display_name
def test_add_songbooks(self):
"""
@ -195,7 +195,7 @@ class TestDB(TestCase):
song.add_songbook_entry(songbook, "550A")
# THEN: The song should have two songbook entries
self.assertEqual(len(song.songbook_entries), 2, 'There should be two Songbook entries.')
assert len(song.songbook_entries) == 2, 'There should be two Songbook entries.'
def test_upgrade_old_song_db(self):
"""
@ -211,8 +211,7 @@ class TestDB(TestCase):
updated_to_version, latest_version = upgrade_db(db_url, upgrade)
# THEN: the song db should have been upgraded to the latest version
self.assertEqual(updated_to_version, latest_version,
'The song DB should have been upgrade to the latest version')
assert updated_to_version == latest_version, 'The song DB should have been upgrade to the latest version'
def test_upgrade_invalid_song_db(self):
"""
@ -228,5 +227,4 @@ class TestDB(TestCase):
updated_to_version, latest_version = upgrade_db(db_url, upgrade)
# THEN: the song db should have been upgraded to the latest version without errors
self.assertEqual(updated_to_version, latest_version,
'The song DB should have been upgrade to the latest version')
assert updated_to_version == latest_version, 'The song DB should have been upgrade to the latest version'

View File

@ -64,7 +64,7 @@ class TestEditSongForm(TestCase, TestMixin):
valid = self.edit_song_form._validate_tags(tags)
# THEN they should be valid
self.assertTrue(valid, "The tags list should be valid")
assert valid is True, "The tags list should be valid"
def test_validate_nonmatching_tags(self):
# Given a set of tags
@ -74,7 +74,7 @@ class TestEditSongForm(TestCase, TestMixin):
valid = self.edit_song_form._validate_tags(tags)
# THEN they should be valid
self.assertTrue(valid, "The tags list should be valid")
assert valid is True, "The tags list should be valid"
@patch('openlp.plugins.songs.forms.editsongform.set_case_insensitive_completer')
def test_load_objects(self, mocked_set_case_insensitive_completer):

View File

@ -71,7 +71,7 @@ class TestEditVerseForm(TestCase, TestMixin):
self.edit_verse_form.update_suggested_verse_number()
# THEN the verse number must not be changed
self.assertEqual(3, self.edit_verse_form.verse_number_box.value(), 'The verse number should be 3')
assert 3 == self.edit_verse_form.verse_number_box.value(), 'The verse number should be 3'
def test_on_divide_split_button_clicked(self):
"""
@ -84,8 +84,8 @@ class TestEditVerseForm(TestCase, TestMixin):
# WHEN the method is called
self.edit_verse_form.on_forced_split_button_clicked()
# THEN the verse number must not be changed
self.assertEqual('[--}{--]\nText\n', self.edit_verse_form.verse_text_edit.toPlainText(),
'The verse number should be [--}{--]\nText\n')
assert '[--}{--]\nText\n' == self.edit_verse_form.verse_text_edit.toPlainText(), \
'The verse number should be [--}{--]\nText\n'
def test_on_split_button_clicked(self):
"""
@ -98,5 +98,5 @@ class TestEditVerseForm(TestCase, TestMixin):
# WHEN the method is called
self.edit_verse_form.on_overflow_split_button_clicked()
# THEN the verse number must not be changed
self.assertEqual('[---]\nText\n', self.edit_verse_form.verse_text_edit.toPlainText(),
'The verse number should be [---]\nText\n')
assert '[---]\nText\n' == self.edit_verse_form.verse_text_edit.toPlainText(), \
'The verse number should be [---]\nText\n'

View File

@ -166,11 +166,10 @@ class TestEasyWorshipSongImport(TestCase):
field_desc_entry = FieldDescEntry(name, field_type, size)
# THEN:
self.assertIsNotNone(field_desc_entry, 'Import should not be none')
self.assertEqual(field_desc_entry.name, name, 'FieldDescEntry.name should be the same as the name argument')
self.assertEqual(field_desc_entry.field_type, field_type,
'FieldDescEntry.type should be the same as the type argument')
self.assertEqual(field_desc_entry.size, size, 'FieldDescEntry.size should be the same as the size argument')
assert field_desc_entry is not None, 'Import should not be none'
assert field_desc_entry.name == name, 'FieldDescEntry.name should be the same as the name argument'
assert field_desc_entry.field_type == field_type, 'FieldDescEntry.type should be the same as the type argument'
assert field_desc_entry.size == size, 'FieldDescEntry.size should be the same as the size argument'
def test_create_importer(self):
"""
@ -184,7 +183,7 @@ class TestEasyWorshipSongImport(TestCase):
importer = EasyWorshipSongImport(mocked_manager, file_paths=[])
# THEN: The importer object should not be None
self.assertIsNotNone(importer, 'Import should not be none')
assert importer is not None, 'Import should not be none'
def test_find_field_exists(self):
"""
@ -202,7 +201,7 @@ class TestEasyWorshipSongImport(TestCase):
for field_name in existing_fields:
# THEN: The item corresponding the index returned should have the same name attribute
self.assertEqual(importer.field_descriptions[importer.db_find_field(field_name)].name, field_name)
assert importer.field_descriptions[importer.db_find_field(field_name)].name == field_name
def test_find_non_existing_field(self):
"""
@ -237,7 +236,7 @@ class TestEasyWorshipSongImport(TestCase):
# THEN: db_set_record_struct should return None and Struct should be called with a value representing
# the list of field descriptions
self.assertIsNone(return_value, 'db_set_record_struct should return None')
assert return_value is None, 'db_set_record_struct should return None'
mocked_struct.Struct.assert_called_with('>50sHIB250s250s10sQ')
@patch('openlp.plugins.songs.lib.importers.easyworship.SongImport')
@ -258,9 +257,8 @@ class TestEasyWorshipSongImport(TestCase):
return_value = importer.db_get_field(field_index)
# THEN: db_get_field should return the known results
self.assertEqual(return_value, result,
'db_get_field should return "%s" when called with "%s"' %
(result, TEST_FIELDS[field_index]))
assert return_value == result, 'db_get_field should return "%s" when called with "%s"' % \
(result, TEST_FIELDS[field_index])
@patch('openlp.plugins.songs.lib.importers.easyworship.SongImport')
def test_get_memo_field(self, MockSongImport):
@ -286,7 +284,7 @@ class TestEasyWorshipSongImport(TestCase):
# THEN: db_get_field should return the appropriate value with the appropriate mocked objects being
# called
self.assertEqual(importer.db_get_field(field_index), get_field_result)
assert importer.db_get_field(field_index) == get_field_result
for call in get_field_read_calls:
mocked_memo_file.read.assert_any_call(call)
for call in get_field_seek_calls:
@ -331,7 +329,7 @@ class TestEasyWorshipSongImport(TestCase):
mocked_stat.return_value.st_size = 0x7FF
# THEN: do_import should return None having called Path.stat()
self.assertIsNone(importer.do_import(), 'do_import should return None when db_size is less than 0x800')
assert importer.do_import() is None, 'do_import should return None when db_size is less than 0x800'
mocked_stat.assert_called_once_with()
@patch('openlp.plugins.songs.lib.importers.easyworship.SongImport')
@ -354,11 +352,10 @@ class TestEasyWorshipSongImport(TestCase):
# THEN: do_import should return None having called closed the open files db and memo files.
for effect in struct_unpack_return_values:
self.assertIsNone(importer.do_import(), 'do_import should return None when db_size is less than 0x800')
self.assertEqual(mocked_open().close.call_count, 2,
'The open db and memo files should have been closed')
assert importer.do_import() is None, 'do_import should return None when db_size is less than 0x800'
assert mocked_open().close.call_count == 2, 'The open db and memo files should have been closed'
mocked_open().close.reset_mock()
self.assertIs(mocked_open().seek.called, False, 'db_file.seek should not have been called.')
assert mocked_open().seek.called is False, 'db_file.seek should not have been called.'
@patch('openlp.plugins.songs.lib.importers.easyworship.SongImport')
@patch('openlp.plugins.songs.lib.importers.easyworship.Path.is_file', return_value=True)
@ -384,7 +381,7 @@ class TestEasyWorshipSongImport(TestCase):
mocked_retrieve_windows_encoding.return_value = False
# THEN: do_import should return None having called retrieve_windows_encoding with the correct encoding.
self.assertIsNone(importer.do_import(), 'do_import should return None when db_size is less than 0x800')
assert importer.do_import() is None, 'do_import should return None when db_size is less than 0x800'
mocked_retrieve_windows_encoding.assert_any_call(encoding)
def test_db_file_import(self):
@ -427,7 +424,7 @@ class TestEasyWorshipSongImport(TestCase):
# THEN: do_import should return none, the song data should be as expected, and finish should have been
# called.
self.assertIsNone(import_result, 'do_import should return None when it has completed')
assert import_result is None, 'do_import should return None when it has completed'
for song_data in SONG_TEST_DATA:
title = song_data['title']
author_calls = song_data['authors']
@ -435,19 +432,18 @@ class TestEasyWorshipSongImport(TestCase):
ccli_number = song_data['ccli_number']
add_verse_calls = song_data['verses']
verse_order_list = song_data['verse_order_list']
self.assertIn(title, importer._title_assignment_list, 'title for %s should be "%s"' % (title, title))
assert title in importer._title_assignment_list, 'title for %s should be "%s"' % (title, title)
for author in author_calls:
mocked_add_author.assert_any_call(author)
if song_copyright:
self.assertEqual(importer.copyright, song_copyright)
assert importer.copyright == song_copyright
if ccli_number:
self.assertEqual(importer.ccli_number, ccli_number,
'ccli_number for %s should be %s' % (title, ccli_number))
assert importer.ccli_number == ccli_number, 'ccli_number for %s should be %s' % (title, ccli_number)
for verse_text, verse_tag in add_verse_calls:
mocked_add_verse.assert_any_call(verse_text, verse_tag)
if verse_order_list:
self.assertEqual(importer.verse_order_list, verse_order_list,
'verse_order_list for %s should be %s' % (title, verse_order_list))
assert importer.verse_order_list == verse_order_list, \
'verse_order_list for %s should be %s' % (title, verse_order_list)
mocked_finish.assert_called_with()
@patch('openlp.plugins.songs.lib.importers.easyworship.SongImport')
@ -483,8 +479,8 @@ class TestEasyWorshipSongImport(TestCase):
# THEN: do_import should return none, the song data should be as expected, and finish should have been
# called.
title = EWS_SONG_TEST_DATA['title']
self.assertIsNone(import_result, 'do_import should return None when it has completed')
self.assertIn(title, importer._title_assignment_list, 'title for should be "%s"' % title)
assert import_result is None, 'do_import should return None when it has completed'
assert title in importer._title_assignment_list, 'title for should be "%s"' % title
mocked_add_author.assert_any_call(EWS_SONG_TEST_DATA['authors'][0])
for verse_text, verse_tag in EWS_SONG_TEST_DATA['verses']:
mocked_add_verse.assert_any_call(verse_text, verse_tag)
@ -507,4 +503,4 @@ class TestEasyWorshipSongImport(TestCase):
importer.set_song_import_object('Test Author', b'Det som var fr\x86n begynnelsen')
# THEN: The import should fail
self.assertEquals(importer.entry_error_log, 'Unexpected data formatting.', 'Import should fail')
assert importer.entry_error_log == 'Unexpected data formatting.', 'Import should fail'

View File

@ -102,7 +102,7 @@ class TestFoilPresenter(TestCase):
foil_presenter_instance = FoilPresenter(mocked_manager, mocked_song_import)
# THEN: The instance should not be None
self.assertIsNotNone(foil_presenter_instance, 'foil_presenter instance should not be none')
assert foil_presenter_instance is not None, 'foil_presenter instance should not be none'
def test_no_xml(self):
"""
@ -118,7 +118,7 @@ class TestFoilPresenter(TestCase):
result = foil_presenter_instance.xml_to_song(arg)
# Then: xml_to_song should return False
self.assertEqual(result, None, 'xml_to_song should return None when called with %s' % arg)
assert result is None, 'xml_to_song should return None when called with %s' % arg
def test_encoding_declaration_removal(self):
"""
@ -165,6 +165,6 @@ class TestFoilPresenter(TestCase):
result = foil_presenter_instance._process_lyrics(mock_foilpresenterfolie, mocked_song)
# THEN: _process_lyrics should return None and the song_import log_error method should have been called once
self.assertIsNone(result)
assert result is None
self.mocked_song_import.log_error.assert_called_once_with('Element Text', 'Translated String')
self.process_lyrics_patcher.start()

View File

@ -63,7 +63,7 @@ class TestLib(TestCase):
result = clean_string(dirty_string)
# THEN: The string should be cleaned up and lower-cased
self.assertEqual(result, 'aint gonna find you there ', 'The string should be cleaned up properly')
assert result == 'aint gonna find you there ', 'The string should be cleaned up properly'
def test_clean_title(self):
"""
@ -76,7 +76,7 @@ class TestLib(TestCase):
result = clean_title(dirty_string)
# THEN: The string should be cleaned up
self.assertEqual(result, 'This is a dirty string', 'The title should be cleaned up properly: "%s"' % result)
assert result == 'This is a dirty string', 'The title should be cleaned up properly: "%s"' % result
def test_songs_probably_equal_same_song(self):
"""
@ -275,7 +275,7 @@ class TestLib(TestCase):
new_chord = transpose_chord(chord, 1, 'english')
# THEN: The chord should be transposed up one note
self.assertEqual(new_chord, 'C#', 'The chord should be transposed up.')
assert new_chord == 'C#', 'The chord should be transposed up.'
def test_transpose_chord_up_adv(self):
"""
@ -288,7 +288,7 @@ class TestLib(TestCase):
new_chord = transpose_chord(chord, 1, 'english')
# THEN: The chord should be transposed up one note
self.assertEqual(new_chord, '(C#/E)', 'The chord should be transposed up.')
assert new_chord == '(C#/E)', 'The chord should be transposed up.'
def test_transpose_chord_down(self):
"""
@ -301,7 +301,7 @@ class TestLib(TestCase):
new_chord = transpose_chord(chord, -1, 'english')
# THEN: The chord should be transposed down one note
self.assertEqual(new_chord, 'B', 'The chord should be transposed down.')
assert new_chord == 'B', 'The chord should be transposed down.'
def test_transpose_chord_error(self):
"""
@ -314,8 +314,8 @@ class TestLib(TestCase):
# THEN: An exception should be raised
with self.assertRaises(ValueError) as err:
new_chord = transpose_chord(chord, -1, 'english')
self.assertEqual(err.exception.args[0], '\'T\' is not in list',
'ValueError exception should have been thrown for invalid chord')
assert err.exception.args[0] == '\'T\' is not in list', \
'ValueError exception should have been thrown for invalid chord'
@patch('openlp.plugins.songs.lib.transpose_verse')
@patch('openlp.plugins.songs.lib.Settings')
@ -361,13 +361,13 @@ class TestVerseType(TestCase):
result = VerseType.translated_tag('v')
# THEN: The result should be "V"
self.assertEqual(result, 'V', 'The result should be "V"')
assert result == 'V', 'The result should be "V"'
# WHEN: We run the translated_tag() method with a "chorus"
result = VerseType.translated_tag('c')
# THEN: The result should be "C"
self.assertEqual(result, 'C', 'The result should be "C"')
assert result == 'C', 'The result should be "C"'
def test_translated_invalid_tag(self):
"""
@ -381,7 +381,7 @@ class TestVerseType(TestCase):
result = VerseType.translated_tag('z')
# THEN: The result should be "O"
self.assertEqual(result, 'O', 'The result should be "O", but was "%s"' % result)
assert result == 'O', 'The result should be "O", but was "%s"' % result
def test_translated_invalid_tag_with_specified_default(self):
"""
@ -395,7 +395,7 @@ class TestVerseType(TestCase):
result = VerseType.translated_tag('q', VerseType.Bridge)
# THEN: The result should be "B"
self.assertEqual(result, 'B', 'The result should be "B", but was "%s"' % result)
assert result == 'B', 'The result should be "B", but was "%s"' % result
def test_translated_invalid_tag_with_invalid_default(self):
"""
@ -409,7 +409,7 @@ class TestVerseType(TestCase):
result = VerseType.translated_tag('q', 29)
# THEN: The result should be "O"
self.assertEqual(result, 'O', 'The result should be "O", but was "%s"' % result)
assert result == 'O', 'The result should be "O", but was "%s"' % result
def test_translated_name(self):
"""
@ -423,13 +423,13 @@ class TestVerseType(TestCase):
result = VerseType.translated_name('v')
# THEN: The result should be "Verse"
self.assertEqual(result, 'Verse', 'The result should be "Verse"')
assert result == 'Verse', 'The result should be "Verse"'
# WHEN: We run the translated_name() method with a "chorus"
result = VerseType.translated_name('c')
# THEN: The result should be "Chorus"
self.assertEqual(result, 'Chorus', 'The result should be "Chorus"')
assert result == 'Chorus', 'The result should be "Chorus"'
def test_translated_invalid_name(self):
"""
@ -443,7 +443,7 @@ class TestVerseType(TestCase):
result = VerseType.translated_name('z')
# THEN: The result should be "Other"
self.assertEqual(result, 'Other', 'The result should be "Other", but was "%s"' % result)
assert result == 'Other', 'The result should be "Other", but was "%s"' % result
def test_translated_invalid_name_with_specified_default(self):
"""
@ -457,7 +457,7 @@ class TestVerseType(TestCase):
result = VerseType.translated_name('q', VerseType.Bridge)
# THEN: The result should be "Bridge"
self.assertEqual(result, 'Bridge', 'The result should be "Bridge", but was "%s"' % result)
assert result == 'Bridge', 'The result should be "Bridge", but was "%s"' % result
def test_translated_invalid_name_with_invalid_default(self):
"""
@ -471,7 +471,7 @@ class TestVerseType(TestCase):
result = VerseType.translated_name('q', 29)
# THEN: The result should be "Other"
self.assertEqual(result, 'Other', 'The result should be "Other", but was "%s"' % result)
assert result == 'Other', 'The result should be "Other", but was "%s"' % result
def test_from_tag(self):
"""
@ -485,7 +485,7 @@ class TestVerseType(TestCase):
result = VerseType.from_tag('v')
# THEN: The result should be VerseType.Verse
self.assertEqual(result, VerseType.Verse, 'The result should be VerseType.Verse, but was "%s"' % result)
assert result == VerseType.Verse, 'The result should be VerseType.Verse, but was "%s"' % result
def test_from_tag_with_invalid_tag(self):
"""
@ -499,7 +499,7 @@ class TestVerseType(TestCase):
result = VerseType.from_tag('w')
# THEN: The result should be VerseType.Other
self.assertEqual(result, VerseType.Other, 'The result should be VerseType.Other, but was "%s"' % result)
assert result == VerseType.Other, 'The result should be VerseType.Other, but was "%s"' % result
def test_from_tag_with_specified_default(self):
"""
@ -513,7 +513,7 @@ class TestVerseType(TestCase):
result = VerseType.from_tag('x', VerseType.Chorus)
# THEN: The result should be VerseType.Chorus
self.assertEqual(result, VerseType.Chorus, 'The result should be VerseType.Chorus, but was "%s"' % result)
assert result == VerseType.Chorus, 'The result should be VerseType.Chorus, but was "%s"' % result
def test_from_tag_with_invalid_intdefault(self):
"""
@ -527,7 +527,7 @@ class TestVerseType(TestCase):
result = VerseType.from_tag('m', 29)
# THEN: The result should be VerseType.Other
self.assertEqual(result, VerseType.Other, 'The result should be VerseType.Other, but was "%s"' % result)
assert result == VerseType.Other, 'The result should be VerseType.Other, but was "%s"' % result
def test_from_tag_with_invalid_default(self):
"""
@ -541,7 +541,7 @@ class TestVerseType(TestCase):
result = VerseType.from_tag('@', 'asdf')
# THEN: The result should be VerseType.Other
self.assertEqual(result, VerseType.Other, 'The result should be VerseType.Other, but was "%s"' % result)
assert result == VerseType.Other, 'The result should be VerseType.Other, but was "%s"' % result
def test_from_tag_with_none_default(self):
"""
@ -555,7 +555,7 @@ class TestVerseType(TestCase):
result = VerseType.from_tag('m', None)
# THEN: The result should be None
self.assertIsNone(result, 'The result should be None, but was "%s"' % result)
assert result is None, 'The result should be None, but was "%s"' % result
@patch('openlp.plugins.songs.lib.VerseType.translated_tags', new_callable=PropertyMock, return_value=['x'])
def test_from_loose_input_with_invalid_input(self, mocked_translated_tags):
@ -567,7 +567,7 @@ class TestVerseType(TestCase):
result = VerseType.from_loose_input('m', None)
# THEN: The result should be None
self.assertIsNone(result, 'The result should be None, but was "%s"' % result)
assert result is None, 'The result should be None, but was "%s"' % result
@patch('openlp.plugins.songs.lib.VerseType.translated_tags', new_callable=PropertyMock, return_value=['x'])
def test_from_loose_input_with_valid_input(self, mocked_translated_tags):
@ -579,4 +579,4 @@ class TestVerseType(TestCase):
result = VerseType.from_loose_input('v')
# THEN: The result should be a Verse
self.assertEqual(result, VerseType.Verse, 'The result should be a verse, but was "%s"' % result)
assert result == VerseType.Verse, 'The result should be a verse, but was "%s"' % result

View File

@ -324,10 +324,9 @@ class TestMediaItem(TestCase, TestMixin):
author_list = self.media_item.generate_footer(service_item, mock_song)
# THEN: I get the following Array returned
self.assertEqual(service_item.raw_footer, ['My Song', 'Written by: my author', 'My copyright'],
'The array should be returned correctly with a song, one author and copyright')
self.assertEqual(author_list, ['my author'],
'The author list should be returned correctly with one author')
assert service_item.raw_footer == ['My Song', 'Written by: my author', 'My copyright'], \
'The array should be returned correctly with a song, one author and copyright'
assert author_list == ['my author'], 'The author list should be returned correctly with one author'
@patch(u'openlp.plugins.songs.lib.mediaitem.Settings')
def test_build_song_footer_one_author_hide_written_by(self, MockedSettings):
@ -356,11 +355,10 @@ class TestMediaItem(TestCase, TestMixin):
author_list = self.media_item.generate_footer(service_item, mock_song)
# THEN: I get the following Array returned
self.assertEqual(service_item.raw_footer, ['My Song', 'my author', 'My copyright'],
'The array should be returned correctly with a song, one author and copyright,'
'text Written by should not be part of the text.')
self.assertEqual(author_list, ['my author'],
'The author list should be returned correctly with one author')
assert service_item.raw_footer == ['My Song', 'my author', 'My copyright'], \
'The array should be returned correctly with a song, one author and copyright, ' \
'text Written by should not be part of the text.'
assert author_list == ['my author'], 'The author list should be returned correctly with one author'
def test_build_song_footer_two_authors(self):
"""
@ -395,11 +393,11 @@ class TestMediaItem(TestCase, TestMixin):
author_list = self.media_item.generate_footer(service_item, mock_song)
# THEN: I get the following Array returned
self.assertEqual(service_item.raw_footer, ['My Song', 'Words: another author', 'Music: my author',
'Translation: translator', 'My copyright'],
'The array should be returned correctly with a song, two authors and copyright')
self.assertEqual(author_list, ['another author', 'my author', 'translator'],
'The author list should be returned correctly with two authors')
assert service_item.raw_footer == ['My Song', 'Words: another author', 'Music: my author',
'Translation: translator', 'My copyright'], \
'The array should be returned correctly with a song, two authors and copyright'
assert author_list == ['another author', 'my author', 'translator'], \
'The author list should be returned correctly with two authors'
def test_build_song_footer_base_ccli(self):
"""
@ -416,16 +414,16 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.generate_footer(service_item, mock_song)
# THEN: I get the following Array returned
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'CCLI License: 1234'],
'The array should be returned correctly with a song, an author, copyright and ccli')
assert service_item.raw_footer == ['My Song', 'My copyright', 'CCLI License: 1234'], \
'The array should be returned correctly with a song, an author, copyright and ccli'
# WHEN: I amend the CCLI value
Settings().setValue('core/ccli number', '4321')
self.media_item.generate_footer(service_item, mock_song)
# THEN: I would get an amended footer string
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'CCLI License: 4321'],
'The array should be returned correctly with a song, an author, copyright and amended ccli')
assert service_item.raw_footer == ['My Song', 'My copyright', 'CCLI License: 4321'], \
'The array should be returned correctly with a song, an author, copyright and amended ccli'
def test_build_song_footer_base_songbook(self):
"""
@ -451,14 +449,14 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.generate_footer(service_item, song)
# THEN: The songbook should not be in the footer
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright'])
assert service_item.raw_footer == ['My Song', 'My copyright']
# WHEN: I activate the "display songbook" option
self.media_item.display_songbook = True
self.media_item.generate_footer(service_item, song)
# THEN: The songbook should be in the footer
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'My songbook #12, Thy songbook #502A'])
assert service_item.raw_footer == ['My Song', 'My copyright', 'My songbook #12, Thy songbook #502A']
def test_build_song_footer_copyright_enabled(self):
"""
@ -475,7 +473,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.generate_footer(service_item, mock_song)
# THEN: The copyright symbol should be in the footer
self.assertEqual(service_item.raw_footer, ['My Song', '© My copyright'])
assert service_item.raw_footer == ['My Song', '© My copyright']
def test_build_song_footer_copyright_disabled(self):
"""
@ -491,7 +489,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.generate_footer(service_item, mock_song)
# THEN: The copyright symbol should not be in the footer
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright'])
assert service_item.raw_footer == ['My Song', 'My copyright']
def test_authors_match(self):
"""
@ -517,7 +515,7 @@ class TestMediaItem(TestCase, TestMixin):
result = self.media_item._authors_match(song, authors_str)
# THEN: They should match
self.assertTrue(result, "Authors should match")
assert result is True, "Authors should match"
def test_authors_dont_match(self):
# GIVEN: A song and a string with authors
@ -540,7 +538,7 @@ class TestMediaItem(TestCase, TestMixin):
result = self.media_item._authors_match(song, authors_str)
# THEN: They should not match
self.assertFalse(result, "Authors should not match")
assert result is False, "Authors should not match"
def test_build_remote_search(self):
"""
@ -559,7 +557,7 @@ class TestMediaItem(TestCase, TestMixin):
search_results = self.media_item.search('My Song', False)
# THEN: The correct formatted results are returned
self.assertEqual(search_results, [[123, 'My Song', 'My alternative']])
assert search_results == [[123, 'My Song', 'My alternative']]
@patch('openlp.plugins.songs.lib.mediaitem.Book')
@patch('openlp.plugins.songs.lib.mediaitem.SongBookEntry')
@ -590,4 +588,4 @@ class TestMediaItem(TestCase, TestMixin):
mocked_or.assert_called_once_with('%jesus%', '%jesus%', '%jesus%', '%jesus%', '%jesus%')
self.mocked_plugin.manager.session.query.assert_called_once_with(MockedSong)
self.assertEqual(self.mocked_plugin.manager.session.query.mock_calls[4][0], '().join().join().filter().all')
assert self.mocked_plugin.manager.session.query.mock_calls[4][0] == '().join().join().filter().all'

View File

@ -54,7 +54,7 @@ class TestMediaShoutImport(TestCase):
importer = MediaShoutImport(MagicMock(), file_path='mediashout.db')
# THEN: It should not be None
self.assertIsNotNone(importer)
assert importer is not None
@patch('openlp.plugins.songs.lib.importers.mediashout.pyodbc')
def test_do_import_fails_to_connect(self, mocked_pyodbc):
@ -112,7 +112,7 @@ class TestMediaShoutImport(TestCase):
call('SELECT Name FROM Groups INNER JOIN SongGroups ON SongGroups.GroupId = Groups.GroupId '
'WHERE SongGroups.Record = ?', 1.0)
]
self.assertEqual(expected_execute_calls, mocked_cursor.execute.call_args_list)
assert expected_execute_calls == mocked_cursor.execute.call_args_list
mocked_process_song.assert_called_once_with(song, [verse], [play_order], [theme, group])
@patch('openlp.plugins.songs.lib.importers.mediashout.pyodbc')
@ -172,16 +172,16 @@ class TestMediaShoutImport(TestCase):
# THEN: It should be added to the database
mocked_set_defaults.assert_called_once_with()
self.assertEqual('Amazing Grace', importer.title)
assert 'Amazing Grace' == importer.title
mocked_parse_author.assert_called_once_with('William Wilberforce')
mocked_add_copyright.assert_called_once_with('Public Domain')
self.assertEqual('Great old hymn', importer.comments)
self.assertEqual(['Grace', 'Hymns'], importer.topics)
self.assertEqual('Hymns', importer.song_book_name)
self.assertEqual('', importer.song_number)
assert 'Great old hymn' == importer.comments
assert ['Grace', 'Hymns'] == importer.topics
assert 'Hymns' == importer.song_book_name
assert '' == importer.song_number
mocked_add_verse.assert_called_once_with(
'Amazing grace, how sweet the sound\nThat saved a wretch like me', 'V1')
self.assertEqual(['V1'], importer.verse_order_list)
assert ['V1'] == importer.verse_order_list
mocked_finish.assert_called_once_with()
def test_process_song_with_song_number(self):
@ -214,14 +214,14 @@ class TestMediaShoutImport(TestCase):
# THEN: It should be added to the database
mocked_set_defaults.assert_called_once_with()
self.assertEqual('Amazing Grace', importer.title)
assert 'Amazing Grace' == importer.title
mocked_parse_author.assert_called_once_with('William Wilberforce')
mocked_add_copyright.assert_called_once_with('Public Domain')
self.assertEqual('Great old hymn', importer.comments)
self.assertEqual(['Grace', 'Hymns'], importer.topics)
self.assertEqual('Hymns', importer.song_book_name)
self.assertEqual('2', importer.song_number)
assert 'Great old hymn' == importer.comments
assert ['Grace', 'Hymns'] == importer.topics
assert 'Hymns' == importer.song_book_name
assert '2' == importer.song_number
mocked_add_verse.assert_called_once_with(
'Amazing grace, how sweet the sound\nThat saved a wretch like me', 'V1')
self.assertEqual(['V1'], importer.verse_order_list)
assert ['V1'], importer.verse_order_list
mocked_finish.assert_called_once_with()

View File

@ -51,7 +51,7 @@ class TestOpenLPImport(TestCase):
importer = OpenLPSongImport(mocked_manager, file_paths=[])
# THEN: The importer object should not be None
self.assertIsNotNone(importer, 'Import should not be none')
assert importer is not None, 'Import should not be none'
def test_invalid_import_source(self):
"""
@ -70,6 +70,6 @@ class TestOpenLPImport(TestCase):
importer.import_source = source
# THEN: do_import should return none and the progress bar maximum should not be set.
self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is not a list')
self.assertEqual(mocked_import_wizard.progress_bar.setMaximum.called, False,
'setMaximum on import_wizard.progress_bar should not have been called')
assert importer.do_import() is None, 'do_import should return None when import_source is not a list'
assert mocked_import_wizard.progress_bar.setMaximum.called is False, \
'setMaximum on import_wizard.progress_bar should not have been called'

View File

@ -72,9 +72,7 @@ class TestOpenLyricsExport(TestCase, TestMixin):
ol_export.do_export()
# THEN: The exporter should have created 2 files
self.assertTrue((self.temp_folder /
'{title} ({display_name}).xml'.format(
title=song.title, display_name=author.display_name)).exists())
self.assertTrue((self.temp_folder /
'{title} ({display_name})-1.xml'.format(
title=song.title, display_name=author.display_name)).exists())
assert (self.temp_folder / '{title} ({display_name}).xml'.format(
title=song.title, display_name=author.display_name)).exists() is True
assert (self.temp_folder / '{title} ({display_name})-1.xml'.format(
title=song.title, display_name=author.display_name)).exists() is True

View File

@ -112,7 +112,7 @@ class TestOpenLyricsImport(TestCase, TestMixin):
importer = OpenLyricsImport(mocked_manager, file_paths=[])
# THEN: The importer should be an instance of SongImport
self.assertIsInstance(importer, SongImport)
assert isinstance(importer, SongImport)
def test_file_import(self):
"""
@ -132,7 +132,7 @@ class TestOpenLyricsImport(TestCase, TestMixin):
importer.do_import()
# THEN: The xml_to_song() method should have been called
self.assertTrue(importer.open_lyrics.xml_to_song.called)
assert importer.open_lyrics.xml_to_song.called is True
def test_process_formatting_tags(self):
"""
@ -151,9 +151,8 @@ class TestOpenLyricsImport(TestCase, TestMixin):
ol._process_formatting_tags(song_xml, False)
# THEN: New tags should have been saved
self.assertListEqual(json.loads(json.dumps(result_tags)),
json.loads(str(Settings().value('formattingTags/html_tags'))),
'The formatting tags should contain both the old and the new')
assert json.loads(json.dumps(result_tags)) == json.loads(str(Settings().value('formattingTags/html_tags'))), \
'The formatting tags should contain both the old and the new'
def test_process_author(self):
"""
@ -171,8 +170,8 @@ class TestOpenLyricsImport(TestCase, TestMixin):
ol._process_authors(properties_xml, mocked_song)
# THEN: add_author should have been called twice
self.assertEquals(mocked_song.method_calls[0][1][1], 'words+music')
self.assertEquals(mocked_song.method_calls[1][1][1], 'words')
assert mocked_song.method_calls[0][1][1] == 'words+music'
assert mocked_song.method_calls[1][1][1] == 'words'
def test_process_songbooks(self):
"""
@ -190,5 +189,5 @@ class TestOpenLyricsImport(TestCase, TestMixin):
ol._process_songbooks(properties_xml, mocked_song)
# THEN: add_songbook_entry should have been called twice
self.assertEquals(mocked_song.method_calls[0][1][1], '48')
self.assertEquals(mocked_song.method_calls[1][1][1], '445 A')
assert mocked_song.method_calls[0][1][1] == '48'
assert mocked_song.method_calls[1][1][1] == '445 A'

View File

@ -59,7 +59,7 @@ class TestOpenOfficeImport(TestCase, TestMixin):
importer = OpenOfficeImport(mocked_manager, file_paths=[])
# THEN: The importer object should not be None
self.assertIsNotNone(importer, 'Import should not be none')
assert importer is not None, 'Import should not be none'
@patch('openlp.plugins.songs.lib.importers.openoffice.SongImport')
def test_close_ooo_file(self, mocked_songimport):
@ -76,4 +76,4 @@ class TestOpenOfficeImport(TestCase, TestMixin):
importer.close_ooo_file()
# THEN: The document attribute should be None even if an exception is raised')
self.assertIsNone(importer.document, 'Document should be None even if an exception is raised')
assert importer.document is None, 'Document should be None even if an exception is raised'

View File

@ -85,7 +85,7 @@ class TestOpenSongImport(TestCase):
importer = OpenSongImport(mocked_manager, file_paths=[])
# THEN: The importer object should not be None
self.assertIsNotNone(importer, 'Import should not be none')
assert importer is not None, 'Import should not be none'
def test_invalid_import_source(self):
"""
@ -104,9 +104,9 @@ class TestOpenSongImport(TestCase):
importer.import_source = source
# THEN: do_import should return none and the progress bar maximum should not be set.
self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is not a list')
self.assertEqual(mocked_import_wizard.progress_bar.setMaximum.called, False,
'setMaximum on import_wizard.progress_bar should not have been called')
assert importer.do_import() is None, 'do_import should return None when import_source is not a list'
assert mocked_import_wizard.progress_bar.setMaximum.called is False, \
'setMaximum on import_wizard.progress_bar should not have been called'
def test_valid_import_source(self):
"""
@ -125,6 +125,6 @@ class TestOpenSongImport(TestCase):
# THEN: do_import should return none and the progress bar setMaximum should be called with the length of
# import_source.
self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is a list '
'and stop_import_flag is True')
assert importer.do_import() is None, \
'do_import should return None when import_source is a list and stop_import_flag is True'
mocked_import_wizard.progress_bar.setMaximum.assert_called_with(len(importer.import_source))

View File

@ -89,7 +89,7 @@ class TestOpsProSongImport(TestCase):
importer = OPSProImport(mocked_manager, file_paths=[])
# THEN: The importer object should not be None
self.assertIsNotNone(importer, 'Import should not be none')
assert importer is not None, 'Import should not be none'
@patch('openlp.plugins.songs.lib.importers.opspro.SongImport')
def test_detect_chorus(self, mocked_songimport):
@ -107,8 +107,8 @@ class TestOpsProSongImport(TestCase):
# THEN: The imported data should look like expected
result_data = load_external_result_data(TEST_PATH / 'You are so faithful.json')
self.assertListEqual(importer.verses, _get_item(result_data, 'verses'))
self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list'))
assert importer.verses == _get_item(result_data, 'verses')
assert importer.verse_order_list_generated == _get_item(result_data, 'verse_order_list')
@patch('openlp.plugins.songs.lib.importers.opspro.SongImport')
def test_join_and_split(self, mocked_songimport):
@ -126,8 +126,8 @@ class TestOpsProSongImport(TestCase):
# THEN: The imported data should look like expected
result_data = load_external_result_data(TEST_PATH / 'Amazing Grace.json')
self.assertListEqual(importer.verses, _get_item(result_data, 'verses'))
self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list'))
assert importer.verses == _get_item(result_data, 'verses')
assert importer.verse_order_list_generated == _get_item(result_data, 'verse_order_list')
@patch('openlp.plugins.songs.lib.importers.opspro.SongImport')
def test_trans_off_tag(self, mocked_songimport):
@ -145,8 +145,8 @@ class TestOpsProSongImport(TestCase):
# THEN: The imported data should look like expected
result_data = load_external_result_data(TEST_PATH / 'Amazing Grace.json')
self.assertListEqual(importer.verses, _get_item(result_data, 'verses'))
self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list'))
assert importer.verses == _get_item(result_data, 'verses')
assert importer.verse_order_list_generated == _get_item(result_data, 'verse_order_list')
@patch('openlp.plugins.songs.lib.importers.opspro.SongImport')
def test_trans_tag(self, mocked_songimport):
@ -164,5 +164,5 @@ class TestOpsProSongImport(TestCase):
# THEN: The imported data should look like expected
result_data = load_external_result_data(TEST_PATH / 'Amazing Grace3.json')
self.assertListEqual(importer.verses, _get_item(result_data, 'verses'))
self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list'))
assert importer.verses == _get_item(result_data, 'verses')
assert importer.verse_order_list_generated == _get_item(result_data, 'verse_order_list')

View File

@ -97,7 +97,7 @@ class TestSongBeamerImport(TestCase):
importer = SongBeamerImport(mocked_manager, file_paths=[])
# THEN: The importer object should not be None
self.assertIsNotNone(importer, 'Import should not be none')
assert importer is not None, 'Import should not be none'
def test_invalid_import_source(self):
"""
@ -113,10 +113,10 @@ class TestSongBeamerImport(TestCase):
self.importer.import_source = source
# THEN: do_import should return none and the progress bar maximum should not be set.
self.assertIsNone(self.importer.do_import(),
'do_import should return None when import_source is not a list')
self.assertEqual(mocked_import_wizard.progress_bar.setMaximum.called, False,
'setMaxium on import_wizard.progress_bar should not have been called')
assert self.importer.do_import() is None, \
'do_import should return None when import_source is not a list'
assert mocked_import_wizard.progress_bar.setMaximum.called is False, \
'setMaxium on import_wizard.progress_bar should not have been called'
def test_valid_import_source(self):
"""
@ -132,8 +132,8 @@ class TestSongBeamerImport(TestCase):
# THEN: do_import should return none and the progress bar setMaximum should be called with the length of
# import_source.
self.assertIsNone(self.importer.do_import(),
'do_import should return None when import_source is a list and stop_import_flag is True')
assert self.importer.do_import() is None, \
'do_import should return None when import_source is a list and stop_import_flag is True'
mocked_import_wizard.progress_bar.setMaximum.assert_called_with(len(self.importer.import_source))
def test_check_verse_marks(self):
@ -147,8 +147,8 @@ class TestSongBeamerImport(TestCase):
# WHEN: line is being checked for verse marks
result = self.importer.check_verse_marks(line)
# THEN: we should get back true and c as self.importer.current_verse_type
self.assertTrue(result, 'Versemark for <Refrain> should be found, value true')
self.assertEqual(self.importer.current_verse_type, 'c', '<Refrain> should be interpreted as <c>')
assert result is True, 'Versemark for <Refrain> should be found, value true'
assert self.importer.current_verse_type == 'c', '<Refrain> should be interpreted as <c>'
# GIVEN: line with unnumbered verse-type and trailing space
line = 'ReFrain '
@ -156,8 +156,8 @@ class TestSongBeamerImport(TestCase):
# WHEN: line is being checked for verse marks
result = self.importer.check_verse_marks(line)
# THEN: we should get back true and c as self.importer.current_verse_type
self.assertTrue(result, 'Versemark for <ReFrain > should be found, value true')
self.assertEqual(self.importer.current_verse_type, 'c', '<ReFrain > should be interpreted as <c>')
assert result is True, 'Versemark for <ReFrain > should be found, value true'
assert self.importer.current_verse_type == 'c', '<ReFrain > should be interpreted as <c>'
# GIVEN: line with numbered verse-type
line = 'VersE 1'
@ -165,8 +165,8 @@ class TestSongBeamerImport(TestCase):
# WHEN: line is being checked for verse marks
result = self.importer.check_verse_marks(line)
# THEN: we should get back true and v1 as self.importer.current_verse_type
self.assertTrue(result, 'Versemark for <VersE 1> should be found, value true')
self.assertEqual(self.importer.current_verse_type, 'v1', u'<VersE 1> should be interpreted as <v1>')
assert result is True, 'Versemark for <VersE 1> should be found, value true'
assert self.importer.current_verse_type == 'v1', u'<VersE 1> should be interpreted as <v1>'
# GIVEN: line with special unnumbered verse-mark (used in Songbeamer to allow usage of non-supported tags)
line = '$$M=special'
@ -174,8 +174,8 @@ class TestSongBeamerImport(TestCase):
# WHEN: line is being checked for verse marks
result = self.importer.check_verse_marks(line)
# THEN: we should get back true and o as self.importer.current_verse_type
self.assertTrue(result, 'Versemark for <$$M=special> should be found, value true')
self.assertEqual(self.importer.current_verse_type, 'o', u'<$$M=special> should be interpreted as <o>')
assert result is True, 'Versemark for <$$M=special> should be found, value true'
assert self.importer.current_verse_type == 'o', u'<$$M=special> should be interpreted as <o>'
# GIVEN: line with song-text with 3 words
line = 'Jesus my saviour'
@ -183,9 +183,8 @@ class TestSongBeamerImport(TestCase):
# WHEN: line is being checked for verse marks
result = self.importer.check_verse_marks(line)
# THEN: we should get back false and none as self.importer.current_verse_type
self.assertFalse(result, 'No versemark for <Jesus my saviour> should be found, value false')
self.assertIsNone(self.importer.current_verse_type,
'<Jesus my saviour> should be interpreted as none versemark')
assert result is False, 'No versemark for <Jesus my saviour> should be found, value false'
assert self.importer.current_verse_type is None, '<Jesus my saviour> should be interpreted as none versemark'
# GIVEN: line with song-text with 2 words
line = 'Praise him'
@ -193,8 +192,8 @@ class TestSongBeamerImport(TestCase):
# WHEN: line is being checked for verse marks
result = self.importer.check_verse_marks(line)
# THEN: we should get back false and none as self.importer.current_verse_type
self.assertFalse(result, 'No versemark for <Praise him> should be found, value false')
self.assertIsNone(self.importer.current_verse_type, '<Praise him> should be interpreted as none versemark')
assert result is False, 'No versemark for <Praise him> should be found, value false'
assert self.importer.current_verse_type is None, '<Praise him> should be interpreted as none versemark'
# GIVEN: line with only a space (could occur, nothing regular)
line = ' '
@ -202,8 +201,8 @@ class TestSongBeamerImport(TestCase):
# WHEN: line is being checked for verse marks
result = self.importer.check_verse_marks(line)
# THEN: we should get back false and none as self.importer.current_verse_type
self.assertFalse(result, 'No versemark for < > should be found, value false')
self.assertIsNone(self.importer.current_verse_type, '< > should be interpreted as none versemark')
assert result is False, 'No versemark for < > should be found, value false'
assert self.importer.current_verse_type is None, '< > should be interpreted as none versemark'
# GIVEN: blank line (could occur, nothing regular)
line = ''
@ -211,8 +210,8 @@ class TestSongBeamerImport(TestCase):
# WHEN: line is being checked for verse marks
result = self.importer.check_verse_marks(line)
# THEN: we should get back false and none as self.importer.current_verse_type
self.assertFalse(result, 'No versemark for <> should be found, value false')
self.assertIsNone(self.importer.current_verse_type, '<> should be interpreted as none versemark')
assert result is False, 'No versemark for <> should be found, value false'
assert self.importer.current_verse_type is None, '<> should be interpreted as none versemark'
def test_verse_marks_defined_in_lowercase(self):
"""
@ -221,4 +220,4 @@ class TestSongBeamerImport(TestCase):
# GIVEN: SongBeamber MarkTypes
for tag in SongBeamerTypes.MarkTypes.keys():
# THEN: tag should be defined in lowercase
self.assertEquals(tag, tag.lower(), 'Tags should be defined in lowercase')
assert tag == tag.lower(), 'Tags should be defined in lowercase'

View File

@ -39,8 +39,8 @@ class TestSongFormat(TestCase):
# GIVEN: The SongFormat class
# WHEN: Retrieving the format list
# THEN: All SongFormats should be returned
self.assertEquals(len(SongFormat.get_format_list()), len(SongFormat.__attributes__),
"The returned SongFormats don't match the stored ones")
assert len(SongFormat.get_format_list()) == len(SongFormat.__attributes__), \
"The returned SongFormats don't match the stored ones"
def test_get_attributed_no_attributes(self):
"""
@ -50,8 +50,8 @@ class TestSongFormat(TestCase):
# WHEN: Retrieving all attributes of a SongFormat
for song_format in SongFormat.get_format_list():
# THEN: All attributes associated with the SongFormat should be returned
self.assertEquals(SongFormat.get(song_format), SongFormat.__attributes__[song_format],
"The returned attributes don't match the stored ones")
assert SongFormat.get(song_format) == SongFormat.__attributes__[song_format], \
"The returned attributes don't match the stored ones"
def test_get_attributed_single_attribute(self):
"""
@ -62,14 +62,14 @@ class TestSongFormat(TestCase):
# WHEN: Retrieving an attribute that overrides the default values
for attribute in SongFormat.get(song_format).keys():
# THEN: Return the attribute
self.assertEquals(SongFormat.get(song_format, attribute), SongFormat.get(song_format)[attribute],
"The returned attribute doesn't match the stored one")
assert SongFormat.get(song_format, attribute) == SongFormat.get(song_format)[attribute], \
"The returned attribute doesn't match the stored one"
# WHEN: Retrieving an attribute that was not overridden
for attribute in SongFormat.__defaults__.keys():
if attribute not in SongFormat.get(song_format).keys():
# THEN: Return the default value
self.assertEquals(SongFormat.get(song_format, attribute), SongFormat.__defaults__[attribute],
"The returned attribute does not match the default values stored")
assert SongFormat.get(song_format, attribute) == SongFormat.__defaults__[attribute], \
"The returned attribute does not match the default values stored"
def test_get_attributed_multiple_attributes(self):
"""
@ -79,9 +79,8 @@ class TestSongFormat(TestCase):
# WHEN: Retrieving multiple attributes at the same time
for song_format in SongFormat.get_format_list():
# THEN: Return all attributes that were specified
self.assertEquals(len(SongFormat.get(song_format, 'canDisable', 'availability')), 2,
"Did not return the correct number of attributes"
" when retrieving multiple attributes at once")
assert len(SongFormat.get(song_format, 'canDisable', 'availability')) == 2, \
"Did not return the correct number of attributes when retrieving multiple attributes at once"
def test_get_format_list_returns_ordered_list(self):
"""
@ -91,5 +90,5 @@ class TestSongFormat(TestCase):
# GIVEN: The SongFormat class
# WHEN: Retrieving all formats
# THEN: The returned list should be sorted according to the ordering defined in SongFormat
self.assertEquals(sorted(SongFormat.get_format_list()), SongFormat.get_format_list(),
"The list returned should be sorted according to the ordering in SongFormat")
assert sorted(SongFormat.get_format_list()) == SongFormat.get_format_list(), \
"The list returned should be sorted according to the ordering in SongFormat"

View File

@ -55,10 +55,10 @@ class TestSongSelectImport(TestCase, TestMixin):
importer = SongSelectImport(None)
# THEN: The object should have the correct properties
self.assertIsNone(importer.db_manager, 'The db_manager should be None')
self.assertIsNotNone(importer.html_parser, 'There should be a valid html_parser object')
self.assertIsNotNone(importer.opener, 'There should be a valid opener object')
self.assertEqual(1, mocked_build_opener.call_count, 'The build_opener method should have been called once')
assert importer.db_manager is None, 'The db_manager should be None'
assert importer.html_parser is not None, 'There should be a valid html_parser object'
assert importer.opener is not None, 'There should be a valid opener object'
assert 1 == mocked_build_opener.call_count, 'The build_opener method should have been called once'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -81,11 +81,11 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.login('username', 'password', mock_callback)
# THEN: callback was called 3 times, open was called twice, find was called twice, and False was returned
self.assertEqual(3, mock_callback.call_count, 'callback should have been called 3 times')
self.assertEqual(2, mocked_login_page.find.call_count, 'find should have been called twice')
self.assertEqual(1, mocked_posted_page.find.call_count, 'find should have been called once')
self.assertEqual(2, mocked_opener.open.call_count, 'opener should have been called twice')
self.assertFalse(result, 'The login method should have returned False')
assert 3 == mock_callback.call_count, 'callback should have been called 3 times'
assert 2 == mocked_login_page.find.call_count, 'find should have been called twice'
assert 1 == mocked_posted_page.find.call_count, 'find should have been called once'
assert 2 == mocked_opener.open.call_count, 'opener should have been called twice'
assert result is False, 'The login method should have returned False'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
def test_login_except(self, mocked_build_opener):
@ -101,8 +101,8 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.login('username', 'password', mock_callback)
# THEN: callback was called 1 time and False was returned
self.assertEqual(1, mock_callback.call_count, 'callback should have been called 1 times')
self.assertFalse(result, 'The login method should have returned False')
assert 1 == mock_callback.call_count, 'callback should have been called 1 times'
assert result is False, 'The login method should have returned False'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -125,11 +125,11 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.login('username', 'password', mock_callback)
# THEN: callback was called 3 times, open was called twice, find was called twice, and True was returned
self.assertEqual(3, mock_callback.call_count, 'callback should have been called 3 times')
self.assertEqual(2, mocked_login_page.find.call_count, 'find should have been called twice on the login page')
self.assertEqual(1, mocked_posted_page.find.call_count, 'find should have been called once on the posted page')
self.assertEqual(2, mocked_opener.open.call_count, 'opener should have been called twice')
self.assertTrue(result, 'The login method should have returned True')
assert 3 == mock_callback.call_count, 'callback should have been called 3 times'
assert 2 == mocked_login_page.find.call_count, 'find should have been called twice on the login page'
assert 1 == mocked_posted_page.find.call_count, 'find should have been called once on the posted page'
assert 2 == mocked_opener.open.call_count, 'opener should have been called twice'
assert result is True, 'The login method should have returned True'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -154,11 +154,11 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.login('username', 'password', mock_callback)
# THEN: callback was called 3 times, open was called twice, find was called twice, and True was returned
self.assertEqual(3, mock_callback.call_count, 'callback should have been called 3 times')
self.assertEqual(2, mocked_login_page.find.call_count, 'find should have been called twice on the login page')
self.assertEqual(1, mocked_posted_page.find.call_count, 'find should have been called once on the posted page')
self.assertEqual('https://profile.ccli.com/do/login', mocked_opener.open.call_args_list[1][0][0])
self.assertTrue(result, 'The login method should have returned True')
assert 3 == mock_callback.call_count, 'callback should have been called 3 times'
assert 2 == mocked_login_page.find.call_count, 'find should have been called twice on the login page'
assert 1 == mocked_posted_page.find.call_count, 'find should have been called once on the posted page'
assert 'https://profile.ccli.com/do/login', mocked_opener.open.call_args_list[1][0][0]
assert result is True, 'The login method should have returned True'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
def test_logout(self, mocked_build_opener):
@ -174,7 +174,7 @@ class TestSongSelectImport(TestCase, TestMixin):
importer.logout()
# THEN: The opener is called once with the logout url
self.assertEqual(1, mocked_opener.open.call_count, 'opener should have been called once')
assert 1 == mocked_opener.open.call_count, 'opener should have been called once'
mocked_opener.open.assert_called_with(LOGOUT_URL)
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@ -196,11 +196,11 @@ class TestSongSelectImport(TestCase, TestMixin):
results = importer.search('text', 1000, mock_callback)
# THEN: callback was never called, open was called once, find_all was called once, an empty list returned
self.assertEqual(0, mock_callback.call_count, 'callback should not have been called')
self.assertEqual(1, mocked_opener.open.call_count, 'open should have been called once')
self.assertEqual(1, mocked_results_page.find_all.call_count, 'find_all should have been called once')
assert 0 == mock_callback.call_count, 'callback should not have been called'
assert 1 == mocked_opener.open.call_count, 'open should have been called once'
assert 1 == mocked_results_page.find_all.call_count, 'find_all should have been called once'
mocked_results_page.find_all.assert_called_with('div', 'song-result')
self.assertEqual([], results, 'The search method should have returned an empty list')
assert [] == results, 'The search method should have returned an empty list'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -236,15 +236,15 @@ class TestSongSelectImport(TestCase, TestMixin):
results = importer.search('text', 1000, mock_callback)
# THEN: callback was never called, open was called once, find_all was called once, an empty list returned
self.assertEqual(2, mock_callback.call_count, 'callback should have been called twice')
self.assertEqual(2, mocked_opener.open.call_count, 'open should have been called twice')
self.assertEqual(2, mocked_results_page.find_all.call_count, 'find_all should have been called twice')
assert 2 == mock_callback.call_count, 'callback should have been called twice'
assert 2 == mocked_opener.open.call_count, 'open should have been called twice'
assert 2 == mocked_results_page.find_all.call_count, 'find_all should have been called twice'
mocked_results_page.find_all.assert_called_with('div', 'song-result')
expected_list = [
{'title': 'Title 1', 'authors': ['James', 'John'], 'link': BASE_URL + '/url1'},
{'title': 'Title 2', 'authors': ['Philip'], 'link': BASE_URL + '/url2'}
]
self.assertListEqual(expected_list, results, 'The search method should have returned two songs')
assert expected_list == results, 'The search method should have returned two songs'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -287,13 +287,13 @@ class TestSongSelectImport(TestCase, TestMixin):
results = importer.search('text', 2, mock_callback)
# THEN: callback was called twice, open was called twice, find_all was called twice, max results returned
self.assertEqual(2, mock_callback.call_count, 'callback should have been called twice')
self.assertEqual(2, mocked_opener.open.call_count, 'open should have been called twice')
self.assertEqual(2, mocked_results_page.find_all.call_count, 'find_all should have been called twice')
assert 2 == mock_callback.call_count, 'callback should have been called twice'
assert 2 == mocked_opener.open.call_count, 'open should have been called twice'
assert 2 == mocked_results_page.find_all.call_count, 'find_all should have been called twice'
mocked_results_page.find_all.assert_called_with('div', 'song-result')
expected_list = [{'title': 'Title 1', 'authors': ['James', 'John'], 'link': BASE_URL + '/url1'},
{'title': 'Title 2', 'authors': ['Philip'], 'link': BASE_URL + '/url2'}]
self.assertListEqual(expected_list, results, 'The search method should have returned two songs')
assert expected_list == results, 'The search method should have returned two songs'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -309,7 +309,7 @@ class TestSongSelectImport(TestCase, TestMixin):
importer.stop()
# THEN: Searching should have stopped
self.assertFalse(importer.run_search, 'Searching should have been stopped')
assert importer.run_search is False, 'Searching should have been stopped'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
def test_get_song_page_raises_exception(self, mocked_build_opener):
@ -328,7 +328,7 @@ class TestSongSelectImport(TestCase, TestMixin):
# THEN: The callback should have been called once and None should be returned
mocked_callback.assert_called_with()
self.assertIsNone(result, 'The get_song() method should have returned None')
assert result is None, 'The get_song() method should have returned None'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -345,8 +345,8 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.get_song({'link': 'link'}, callback=mocked_callback)
# THEN: The callback should have been called twice and None should be returned
self.assertEqual(2, mocked_callback.call_count, 'The callback should have been called twice')
self.assertIsNone(result, 'The get_song() method should have returned None')
assert 2 == mocked_callback.call_count, 'The callback should have been called twice'
assert result is None, 'The get_song() method should have returned None'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -382,19 +382,18 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.get_song(fake_song, callback=mocked_callback)
# THEN: The callback should have been called three times and the song should be returned
self.assertEqual(3, mocked_callback.call_count, 'The callback should have been called twice')
self.assertIsNotNone(result, 'The get_song() method should have returned a song dictionary')
self.assertEqual(2, mocked_lyrics_page.find.call_count, 'The find() method should have been called twice')
self.assertEqual(2, mocked_find_all.call_count, 'The find_all() method should have been called twice')
self.assertEqual([call('div', 'song-viewer lyrics'), call('div', 'song-viewer lyrics')],
mocked_lyrics_page.find.call_args_list,
'The find() method should have been called with the right arguments')
self.assertEqual([call('p'), call('h3')], mocked_find_all.call_args_list,
'The find_all() method should have been called with the right arguments')
self.assertIn('copyright', result, 'The returned song should have a copyright')
self.assertIn('ccli_number', result, 'The returned song should have a CCLI number')
self.assertIn('verses', result, 'The returned song should have verses')
self.assertEqual(3, len(result['verses']), 'Three verses should have been returned')
assert 3 == mocked_callback.call_count, 'The callback should have been called twice'
assert result is not None, 'The get_song() method should have returned a song dictionary'
assert 2 == mocked_lyrics_page.find.call_count, 'The find() method should have been called twice'
assert 2 == mocked_find_all.call_count, 'The find_all() method should have been called twice'
assert [call('div', 'song-viewer lyrics'), call('div', 'song-viewer lyrics')] == \
mocked_lyrics_page.find.call_args_list, 'The find() method should have been called with the right arguments'
assert [call('p'), call('h3')] == mocked_find_all.call_args_list, \
'The find_all() method should have been called with the right arguments'
assert 'copyright' in result, 'The returned song should have a copyright'
assert 'ccli_number' in result, 'The returned song should have a CCLI number'
assert 'verses' in result, 'The returned song should have verses'
assert 3 == len(result['verses']), 'Three verses should have been returned'
@patch('openlp.plugins.songs.lib.songselect.clean_song')
@patch('openlp.plugins.songs.lib.songselect.Topic')
@ -425,14 +424,13 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.save_song(song_dict)
# THEN: The return value should be a Song class and the mocked_db_manager should have been called
self.assertIsInstance(result, Song, 'The returned value should be a Song object')
assert isinstance(result, Song), 'The returned value should be a Song object'
mocked_clean_song.assert_called_with(mocked_db_manager, result)
self.assertEqual(2, mocked_db_manager.save_object.call_count,
'The save_object() method should have been called twice')
assert 2 == mocked_db_manager.save_object.call_count, \
'The save_object() method should have been called twice'
mocked_db_manager.get_object_filtered.assert_called_with(MockedAuthor, False)
MockedAuthor.populate.assert_called_with(first_name='Public', last_name='Domain',
display_name='Public Domain')
self.assertEqual(1, len(result.authors_songs), 'There should only be one author')
MockedAuthor.populate.assert_called_with(first_name='Public', last_name='Domain', display_name='Public Domain')
assert 1 == len(result.authors_songs), 'There should only be one author'
@patch('openlp.plugins.songs.lib.songselect.clean_song')
@patch('openlp.plugins.songs.lib.songselect.Author')
@ -461,13 +459,13 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.save_song(song_dict)
# THEN: The return value should be a Song class and the mocked_db_manager should have been called
self.assertIsInstance(result, Song, 'The returned value should be a Song object')
assert isinstance(result, Song), 'The returned value should be a Song object'
mocked_clean_song.assert_called_with(mocked_db_manager, result)
self.assertEqual(2, mocked_db_manager.save_object.call_count,
'The save_object() method should have been called twice')
assert 2 == mocked_db_manager.save_object.call_count, \
'The save_object() method should have been called twice'
mocked_db_manager.get_object_filtered.assert_called_with(MockedAuthor, False)
self.assertEqual(0, MockedAuthor.populate.call_count, 'A new author should not have been instantiated')
self.assertEqual(1, len(result.authors_songs), 'There should only be one author')
assert 0 == MockedAuthor.populate.call_count, 'A new author should not have been instantiated'
assert 1 == len(result.authors_songs), 'There should only be one author'
@patch('openlp.plugins.songs.lib.songselect.clean_song')
@patch('openlp.plugins.songs.lib.songselect.Author')
@ -496,14 +494,13 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.save_song(song_dict)
# THEN: The return value should be a Song class and the mocked_db_manager should have been called
self.assertIsInstance(result, Song, 'The returned value should be a Song object')
assert isinstance(result, Song), 'The returned value should be a Song object'
mocked_clean_song.assert_called_with(mocked_db_manager, result)
self.assertEqual(2, mocked_db_manager.save_object.call_count,
'The save_object() method should have been called twice')
assert 2 == mocked_db_manager.save_object.call_count, \
'The save_object() method should have been called twice'
mocked_db_manager.get_object_filtered.assert_called_with(MockedAuthor, False)
MockedAuthor.populate.assert_called_with(first_name='Unknown', last_name='',
display_name='Unknown')
self.assertEqual(1, len(result.authors_songs), 'There should only be one author')
MockedAuthor.populate.assert_called_with(first_name='Unknown', last_name='', display_name='Unknown')
assert 1 == len(result.authors_songs), 'There should only be one author'
class TestSongSelectForm(TestCase, TestMixin):
@ -532,8 +529,8 @@ class TestSongSelectForm(TestCase, TestMixin):
ssform = SongSelectForm(None, mocked_plugin, mocked_db_manager)
# THEN: The correct properties should have been assigned
self.assertEqual(mocked_plugin, ssform.plugin, 'The correct plugin should have been assigned')
self.assertEqual(mocked_db_manager, ssform.db_manager, 'The correct db_manager should have been assigned')
assert mocked_plugin == ssform.plugin, 'The correct plugin should have been assigned'
assert mocked_db_manager == ssform.db_manager, 'The correct db_manager should have been assigned'
@patch('openlp.plugins.songs.forms.songselectform.SongSelectImport')
@patch('openlp.plugins.songs.forms.songselectform.QtWidgets.QMessageBox.critical')
@ -568,23 +565,21 @@ class TestSongSelectForm(TestCase, TestMixin):
expected_login_spacer_calls = [call(False), call(True)]
expected_login_progress_visible_calls = [call(True), call(False)]
expected_login_progress_value_calls = [call(0), call(0)]
self.assertEqual(expected_username_calls, mocked_username_edit.setEnabled.call_args_list,
'The username edit should be disabled then enabled')
self.assertEqual(expected_password_calls, mocked_password_edit.setEnabled.call_args_list,
'The password edit should be disabled then enabled')
self.assertEqual(expected_save_password_calls, mocked_save_password_checkbox.setEnabled.call_args_list,
'The save password checkbox should be disabled then enabled')
self.assertEqual(expected_login_btn_calls, mocked_login_button.setEnabled.call_args_list,
'The login button should be disabled then enabled')
self.assertEqual(expected_login_spacer_calls, mocked_login_spacer.setVisible.call_args_list,
'Thee login spacer should be make invisible, then visible')
self.assertEqual(expected_login_progress_visible_calls,
mocked_login_progress_bar.setVisible.call_args_list,
'Thee login progress bar should be make visible, then invisible')
self.assertEqual(expected_login_progress_value_calls, mocked_login_progress_bar.setValue.call_args_list,
'Thee login progress bar should have the right values set')
self.assertEqual(2, mocked_process_events.call_count,
'The process_events() method should be called twice')
assert expected_username_calls == mocked_username_edit.setEnabled.call_args_list, \
'The username edit should be disabled then enabled'
assert expected_password_calls == mocked_password_edit.setEnabled.call_args_list, \
'The password edit should be disabled then enabled'
assert expected_save_password_calls == mocked_save_password_checkbox.setEnabled.call_args_list, \
'The save password checkbox should be disabled then enabled'
assert expected_login_btn_calls == mocked_login_button.setEnabled.call_args_list, \
'The login button should be disabled then enabled'
assert expected_login_spacer_calls == mocked_login_spacer.setVisible.call_args_list, \
'Thee login spacer should be make invisible, then visible'
assert expected_login_progress_visible_calls == mocked_login_progress_bar.setVisible.call_args_list, \
'Thee login progress bar should be make visible, then invisible'
assert expected_login_progress_value_calls == mocked_login_progress_bar.setValue.call_args_list, \
'Thee login progress bar should have the right values set'
assert 2 == mocked_process_events.call_count, 'The process_events() method should be called twice'
mocked_critical.assert_called_with(ssform, 'Error Logging In', 'There was a problem logging in, '
'perhaps your username or password is '
'incorrect?')
@ -613,7 +608,7 @@ class TestSongSelectForm(TestCase, TestMixin):
'Your song has been imported, would you like to import more songs?',
defaultButton=QtWidgets.QMessageBox.Yes)
mocked_on_back_button_clicked.assert_called_with()
self.assertIsNone(ssform.song)
assert ssform.song is None
@patch('openlp.plugins.songs.forms.songselectform.QtWidgets.QMessageBox.question')
@patch('openlp.plugins.songs.forms.songselectform.translate')
@ -639,7 +634,7 @@ class TestSongSelectForm(TestCase, TestMixin):
'Your song has been imported, would you like to import more songs?',
defaultButton=QtWidgets.QMessageBox.Yes)
mocked_done.assert_called_with(QtWidgets.QDialog.Accepted)
self.assertIsNone(ssform.song)
assert ssform.song is None
def test_on_back_button_clicked(self):
"""
@ -767,8 +762,8 @@ class TestSongSelectForm(TestCase, TestMixin):
# THEN: The view button, search box and search button should be enabled
mocked_song_select_importer.stop.assert_called_with()
self.assertTrue(ssform.search_button.isEnabled())
self.assertTrue(ssform.search_combobox.isEnabled())
assert ssform.search_button.isEnabled() is True
assert ssform.search_combobox.isEnabled() is True
@patch('openlp.plugins.songs.forms.songselectform.Settings')
@patch('openlp.plugins.songs.forms.songselectform.QtCore.QThread')
@ -785,8 +780,8 @@ class TestSongSelectForm(TestCase, TestMixin):
ssform.on_search_button_clicked()
# THEN: The search box and search button should be disabled
self.assertFalse(ssform.search_button.isEnabled())
self.assertFalse(ssform.search_combobox.isEnabled())
assert ssform.search_button.isEnabled() is False
assert ssform.search_combobox.isEnabled() is False
def test_on_search_finished(self):
"""
@ -800,8 +795,8 @@ class TestSongSelectForm(TestCase, TestMixin):
ssform.on_search_finished()
# THEN: The search box and search button should be enabled
self.assertTrue(ssform.search_button.isEnabled())
self.assertTrue(ssform.search_combobox.isEnabled())
assert ssform.search_button.isEnabled() is True
assert ssform.search_combobox.isEnabled() is True
class TestSongSelectFileImport(SongImportTestHelper):
@ -835,8 +830,8 @@ class TestSearchWorker(TestCase, TestMixin):
worker = SearchWorker(importer, search_text)
# THEN: The correct values should be set
self.assertIs(importer, worker.importer, 'The importer should be the right object')
self.assertEqual(search_text, worker.search_text, 'The search text should be correct')
assert importer is worker.importer, 'The importer should be the right object'
assert search_text == worker.search_text, 'The search text should be correct'
def test_start(self):
"""

View File

@ -71,7 +71,7 @@ class TestSongShowPlusImport(TestCase):
importer = SongShowPlusImport(mocked_manager, file_paths=[])
# THEN: The importer object should not be None
self.assertIsNotNone(importer, 'Import should not be none')
assert importer is not None, 'Import should not be none'
def test_invalid_import_source(self):
"""
@ -90,9 +90,9 @@ class TestSongShowPlusImport(TestCase):
importer.import_source = source
# THEN: do_import should return none and the progress bar maximum should not be set.
self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is not a list')
self.assertEqual(mocked_import_wizard.progress_bar.setMaximum.called, False,
'setMaximum on import_wizard.progress_bar should not have been called')
assert importer.do_import() is None, 'do_import should return None when import_source is not a list'
assert mocked_import_wizard.progress_bar.setMaximum.called is False, \
'setMaximum on import_wizard.progress_bar should not have been called'
def test_valid_import_source(self):
"""
@ -111,8 +111,8 @@ class TestSongShowPlusImport(TestCase):
# THEN: do_import should return none and the progress bar setMaximum should be called with the length of
# import_source.
self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is a list '
'and stop_import_flag is True')
assert importer.do_import() is None, \
'do_import should return None when import_source is a list and stop_import_flag is True'
mocked_import_wizard.progress_bar.setMaximum.assert_called_with(len(importer.import_source))
def test_to_openlp_verse_tag(self):
@ -139,9 +139,9 @@ class TestSongShowPlusImport(TestCase):
# THEN: The returned value should should correlate with the input arguments
for original_tag, openlp_tag in test_values:
self.assertEqual(importer.to_openlp_verse_tag(original_tag), openlp_tag,
'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' %
(openlp_tag, original_tag))
assert importer.to_openlp_verse_tag(original_tag) == openlp_tag, \
'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' % \
(openlp_tag, original_tag)
def test_to_openlp_verse_tag_verse_order(self):
"""
@ -168,6 +168,6 @@ class TestSongShowPlusImport(TestCase):
# THEN: The returned value should should correlate with the input arguments
for original_tag, openlp_tag in test_values:
self.assertEqual(importer.to_openlp_verse_tag(original_tag, ignore_unique=True), openlp_tag,
'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' %
(openlp_tag, original_tag))
assert importer.to_openlp_verse_tag(original_tag, ignore_unique=True) == openlp_tag, \
'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' % \
(openlp_tag, original_tag)

View File

@ -156,7 +156,7 @@ class TestWorshipCenterProSongImport(TestCase):
importer = WorshipCenterProImport(mocked_manager, file_paths=[])
# THEN: The importer object should not be None
self.assertIsNotNone(importer, 'Import should not be none')
assert importer is not None, 'Import should not be none'
def test_pyodbc_exception(self):
"""
@ -181,7 +181,7 @@ class TestWorshipCenterProSongImport(TestCase):
return_value = importer.do_import()
# THEN: do_import should return None, and pyodbc, translate & log_error are called with known calls
self.assertIsNone(return_value, 'do_import should return None when pyodbc raises an exception.')
assert return_value is None, 'do_import should return None when pyodbc raises an exception.'
mocked_pyodbc_connect.assert_called_with('DRIVER={Microsoft Access Driver (*.mdb)};DBQ=import_source')
mocked_translate.assert_called_with('SongsPlugin.WorshipCenterProImport',
'Unable to connect the WorshipCenter Pro database.')
@ -220,7 +220,7 @@ class TestWorshipCenterProSongImport(TestCase):
# THEN: do_import should return None, and pyodbc, import_wizard, importer.title and add_verse are called
# with known calls
self.assertIsNone(return_value, 'do_import should return None when pyodbc raises an exception.')
assert return_value is None, 'do_import should return None when pyodbc raises an exception.'
mocked_pyodbc.connect.assert_called_with('DRIVER={Microsoft Access Driver (*.mdb)};DBQ=import_source')
mocked_pyodbc.connect().cursor.assert_any_call()
mocked_pyodbc.connect().cursor().execute.assert_called_with('SELECT ID, Field, Value FROM __SONGDATA')
@ -229,8 +229,7 @@ class TestWorshipCenterProSongImport(TestCase):
add_verse_call_count = 0
for song_data in SONG_TEST_DATA:
title_value = song_data['title']
self.assertIn(title_value, importer._title_assignment_list,
'title should have been set to %s' % title_value)
assert title_value in importer._title_assignment_list, 'title should have been set to %s' % title_value
verse_calls = song_data['verses']
add_verse_call_count += len(verse_calls)
for call in verse_calls:
@ -241,5 +240,4 @@ class TestWorshipCenterProSongImport(TestCase):
mocked_add_comment.assert_any_call(song_data['comments'])
if 'copyright' in song_data:
mocked_add_copyright.assert_any_call(song_data['copyright'])
self.assertEqual(mocked_add_verse.call_count, add_verse_call_count,
'Incorrect number of calls made to add_verse')
assert mocked_add_verse.call_count == add_verse_call_count, 'Incorrect number of calls made to add_verse'

View File

@ -57,7 +57,7 @@ class TestZionWorxImport(TestCase):
importer = ZionWorxImport(mocked_manager, file_paths=[])
# THEN: The importer should be an instance of SongImport
self.assertIsInstance(importer, SongImport)
assert isinstance(importer, SongImport)
class TestZionWorxFileImport(SongImportTestHelper):

View File

@ -43,10 +43,10 @@ class TestSongUsage(TestCase):
# GIVEN: The SongUsagePlugin
# WHEN: Retrieving the about text
# THEN: about() should return a string object
self.assertIsInstance(SongUsagePlugin.about(), str)
assert isinstance(SongUsagePlugin.about(), str)
# THEN: about() should return a non-empty string
self.assertNotEquals(len(SongUsagePlugin.about()), 0)
self.assertNotEquals(len(SongUsagePlugin.about()), 0)
assert len(SongUsagePlugin.about()) is not 0
assert len(SongUsagePlugin.about()) is not 0
@patch('openlp.plugins.songusage.songusageplugin.Manager')
def test_song_usage_init(self, MockedManager):
@ -62,8 +62,8 @@ class TestSongUsage(TestCase):
# THEN: It should be initialised correctly
MockedManager.assert_called_with('songusage', init_schema, upgrade_mod=upgrade)
self.assertEqual(mocked_manager, song_usage.manager)
self.assertFalse(song_usage.song_usage_active)
assert mocked_manager == song_usage.manager
assert song_usage.song_usage_active is False
@patch('openlp.plugins.songusage.songusageplugin.Manager')
def test_check_pre_conditions(self, MockedManager):
@ -80,7 +80,7 @@ class TestSongUsage(TestCase):
ret = song_usage.check_pre_conditions()
# THEN: It should return True
self.assertTrue(ret)
assert ret is True
@patch('openlp.plugins.songusage.songusageplugin.Manager')
def test_toggle_song_usage_state(self, MockedManager):
@ -96,4 +96,4 @@ class TestSongUsage(TestCase):
song_usage.toggle_song_usage_state()
# THEN: song_usage_state should have been toogled
self.assertFalse(song_usage.song_usage_active)
assert song_usage.song_usage_active is False

View File

@ -108,7 +108,7 @@ class SongImportTestHelper(TestCase):
verse_order_list = self._get_data(result_data, 'verse_order_list')
# THEN: do_import should return none, the song data should be as expected, and finish should have been called.
self.assertIsNone(importer.do_import(), 'do_import should return None when it has completed')
assert importer.do_import() is None, 'do_import should return None when it has completed'
# Debug information - will be displayed when the test fails
log.debug("Title imported: %s" % importer.title)
@ -122,7 +122,7 @@ class SongImportTestHelper(TestCase):
log.debug("Song copyright imported: %s" % importer.song_number)
log.debug("Topics imported: %s" % importer.topics)
self.assertEqual(importer.title, title, 'title for %s should be "%s"' % (source_file_name, title))
assert importer.title == title, 'title for %s should be "%s"' % (source_file_name, title)
for author in author_calls:
if isinstance(author, str):
self.mocked_add_author.assert_any_call(author)
@ -131,27 +131,27 @@ class SongImportTestHelper(TestCase):
if song_copyright:
self.mocked_add_copyright.assert_called_with(song_copyright)
if ccli_number:
self.assertEqual(importer.ccli_number, ccli_number,
'ccli_number for %s should be %s' % (source_file_name, ccli_number))
assert importer.ccli_number == ccli_number, \
'ccli_number for %s should be %s' % (source_file_name, ccli_number)
expected_calls = []
for verse_text, verse_tag in add_verse_calls:
self.mocked_add_verse.assert_any_call(verse_text, verse_tag)
expected_calls.append(call(verse_text, verse_tag))
self.mocked_add_verse.assert_has_calls(expected_calls, any_order=False)
if topics:
self.assertEqual(importer.topics, topics, 'topics for %s should be %s' % (source_file_name, topics))
assert importer.topics == topics, 'topics for %s should be %s' % (source_file_name, topics)
if comments:
self.assertEqual(importer.comments, comments,
'comments for %s should be "%s"' % (source_file_name, comments))
assert importer.comments == comments, \
'comments for %s should be "%s"' % (source_file_name, comments)
if song_book_name:
self.assertEqual(importer.song_book_name, song_book_name,
'song_book_name for %s should be "%s"' % (source_file_name, song_book_name))
assert importer.song_book_name == song_book_name, \
'song_book_name for %s should be "%s"' % (source_file_name, song_book_name)
if song_number:
self.assertEqual(importer.song_number, song_number,
'song_number for %s should be %s' % (source_file_name, song_number))
assert importer.song_number == song_number, \
'song_number for %s should be %s' % (source_file_name, song_number)
if verse_order_list:
self.assertEqual(importer.verse_order_list, verse_order_list,
'verse_order_list for %s should be %s' % (source_file_name, verse_order_list))
assert importer.verse_order_list == verse_order_list, \
'verse_order_list for %s should be %s' % (source_file_name, verse_order_list)
self.mocked_finish.assert_called_with()
def _get_data(self, data, key):

View File

@ -86,11 +86,11 @@ class TestPluginManager(TestCase, TestMixin):
# THEN: We should find the "Songs", "Bibles", etc in the plugins list
plugin_names = [plugin.name for plugin in plugin_manager.plugins]
self.assertIn('songs', plugin_names, 'There should be a "songs" plugin')
self.assertIn('bibles', plugin_names, 'There should be a "bibles" plugin')
self.assertIn('presentations', plugin_names, 'There should be a "presentations" plugin')
self.assertIn('images', plugin_names, 'There should be a "images" plugin')
self.assertIn('media', plugin_names, 'There should be a "media" plugin')
self.assertIn('custom', plugin_names, 'There should be a "custom" plugin')
self.assertIn('songusage', plugin_names, 'There should be a "songusage" plugin')
self.assertIn('alerts', plugin_names, 'There should be a "alerts" plugin')
assert 'songs' in plugin_names, 'There should be a "songs" plugin'
assert 'bibles' in plugin_names, 'There should be a "bibles" plugin'
assert 'presentations' in plugin_names, 'There should be a "presentations" plugin'
assert 'images' in plugin_names, 'There should be a "images" plugin'
assert 'media' in plugin_names, 'There should be a "media" plugin'
assert 'custom' in plugin_names, 'There should be a "custom" plugin'
assert 'songusage'in plugin_names, 'There should be a "songusage" plugin'
assert 'alerts' in plugin_names, 'There should be a "alerts" plugin'

View File

@ -46,5 +46,4 @@ class TestMediainfoWrapper(TestCase):
results = MediaInfoWrapper.parse(full_path)
# THEN you can determine the run time
self.assertEqual(results.tracks[0].duration, test_data[1], 'The correct duration is returned for ' +
test_data[0])
assert results.tracks[0].duration == test_data[1], 'The correct duration is returned for ' + test_data[0]

View File

@ -63,19 +63,19 @@ class TestStartFileRenameForm(TestCase, TestMixin):
self.form.exec()
# THEN: the window title is set correctly
self.assertEqual(self.form.windowTitle(), 'File Rename', 'The window title should be "File Rename"')
assert self.form.windowTitle() == 'File Rename', 'The window title should be "File Rename"'
# WHEN: The form is executed with False arg
self.form.exec(False)
# THEN: the window title is set correctly
self.assertEqual(self.form.windowTitle(), 'File Rename', 'The window title should be "File Rename"')
assert self.form.windowTitle() == 'File Rename', 'The window title should be "File Rename"'
# WHEN: The form is executed with True arg
self.form.exec(True)
# THEN: the window title is set correctly
self.assertEqual(self.form.windowTitle(), 'File Copy', 'The window title should be "File Copy"')
assert self.form.windowTitle() == 'File Copy', 'The window title should be "File Copy"'
def test_line_edit_focus(self):
"""
@ -104,4 +104,4 @@ class TestStartFileRenameForm(TestCase, TestMixin):
# THEN: The text in the QLineEdit should be the same as the input string with the invalid characters filtered
# out.
self.assertEqual(self.form.file_name_edit.text(), 'Invalid File Name')
assert self.form.file_name_edit.text() == 'Invalid File Name'

View File

@ -70,8 +70,8 @@ class TestProjectorManager(TestCase, TestMixin):
# WHEN: we call bootstrap_initialise
self.projector_manager.bootstrap_initialise()
# THEN: ProjectorDB is setup
self.assertEqual(type(self.projector_manager.projectordb), ProjectorDB,
'Initialization should have created a ProjectorDB() instance')
assert type(self.projector_manager.projectordb) == ProjectorDB, \
'Initialization should have created a ProjectorDB() instance'
def test_bootstrap_post_set_up(self):
"""
@ -85,10 +85,9 @@ class TestProjectorManager(TestCase, TestMixin):
self.projector_manager.bootstrap_post_set_up()
# THEN: verify calls to retrieve saved projectors and edit page initialized
self.assertEqual(1, self.projector_manager._load_projectors.call_count,
'Initialization should have called load_projectors()')
self.assertEqual(type(self.projector_manager.projector_form), ProjectorEditForm,
'Initialization should have created a Projector Edit Form')
self.assertIs(self.projector_manager.projectordb,
self.projector_manager.projector_form.projectordb,
'ProjectorEditForm should be using same ProjectorDB() instance as ProjectorManager')
assert 1 == self.projector_manager._load_projectors.call_count, \
'Initialization should have called load_projectors()'
assert type(self.projector_manager.projector_form) == ProjectorEditForm, \
'Initialization should have created a Projector Edit Form'
assert self.projector_manager.projectordb is self.projector_manager.projector_form.projectordb, \
'ProjectorEditForm should be using same ProjectorDB() instance as ProjectorManager'

View File

@ -111,8 +111,7 @@ class ProjectorSourceFormTest(TestCase, TestMixin):
check = source_group(codes, PJLINK_DEFAULT_CODES)
# THEN: return dictionary should match test dictionary
self.assertEquals(check, build_source_dict(),
"Source group dictionary should match test dictionary")
assert check == build_source_dict(), "Source group dictionary should match test dictionary"
@patch.object(QDialog, 'exec')
def test_source_select_edit_button(self, mocked_qdialog):
@ -130,9 +129,8 @@ class ProjectorSourceFormTest(TestCase, TestMixin):
projector = select_form.projector
# THEN: Verify all 4 buttons are available
self.assertEquals(len(select_form.button_box.buttons()), 4,
'SourceSelect dialog box should have "OK", "Cancel" '
'"Rest", and "Revert" buttons available')
assert len(select_form.button_box.buttons()) == 4, \
'SourceSelect dialog box should have "OK", "Cancel", "Rest", and "Revert" buttons available'
@patch.object(QDialog, 'exec')
def test_source_select_noedit_button(self, mocked_qdialog):
@ -150,6 +148,5 @@ class ProjectorSourceFormTest(TestCase, TestMixin):
projector = select_form.projector
# THEN: Verify only 2 buttons are available
self.assertEquals(len(select_form.button_box.buttons()), 2,
'SourceSelect dialog box should only have "OK" '
'and "Cancel" buttons available')
assert len(select_form.button_box.buttons()) == 2, \
'SourceSelect dialog box should only have "OK" and "Cancel" buttons available'

View File

@ -79,8 +79,8 @@ class TestServiceManager(TestCase, TestMixin):
self.service_manager.setup_ui(self.service_manager)
# THEN the count of items should be zero
self.assertEqual(self.service_manager.service_manager_list.topLevelItemCount(), 0,
'The service manager list should be empty ')
assert self.service_manager.service_manager_list.topLevelItemCount() == 0, \
'The service manager list should be empty '
@patch('openlp.core.ui.servicemanager.QtWidgets.QTreeWidget.itemAt')
@patch('openlp.core.ui.servicemanager.QtWidgets.QWidget.mapToGlobal')
@ -447,8 +447,8 @@ class TestServiceManager(TestCase, TestMixin):
# THEN selection should be expanded
selected_index = self.service_manager.service_manager_list.currentIndex()
above_selected_index = self.service_manager.service_manager_list.indexAbove(selected_index)
self.assertTrue(self.service_manager.service_manager_list.isExpanded(above_selected_index),
'Item should have been expanded')
assert self.service_manager.service_manager_list.isExpanded(above_selected_index) is True, \
'Item should have been expanded'
self.service_manager.expanded.assert_called_once_with(song_item)
def test_on_collapse_selection_with_parent_selected(self):
@ -468,10 +468,10 @@ class TestServiceManager(TestCase, TestMixin):
# THEN selection should be expanded
selected_index = self.service_manager.service_manager_list.currentIndex()
self.assertFalse(self.service_manager.service_manager_list.isExpanded(selected_index),
'Item should have been collapsed')
self.assertTrue(self.service_manager.service_manager_list.currentItem() == song_item,
'Top item should have been selected')
assert self.service_manager.service_manager_list.isExpanded(selected_index) is False, \
'Item should have been collapsed'
assert self.service_manager.service_manager_list.currentItem() == song_item, \
'Top item should have been selected'
self.service_manager.collapsed.assert_called_once_with(song_item)
def test_on_collapse_selection_with_child_selected(self):
@ -491,8 +491,8 @@ class TestServiceManager(TestCase, TestMixin):
# THEN selection should be expanded
selected_index = self.service_manager.service_manager_list.currentIndex()
self.assertFalse(self.service_manager.service_manager_list.isExpanded(selected_index),
'Item should have been collapsed')
self.assertTrue(self.service_manager.service_manager_list.currentItem() == song_item,
'Top item should have been selected')
assert self.service_manager.service_manager_list.isExpanded(selected_index) is False, \
'Item should have been collapsed'
assert self.service_manager.service_manager_list.currentItem() == song_item, \
'Top item should have been selected'
self.service_manager.collapsed.assert_called_once_with(song_item)

View File

@ -66,7 +66,7 @@ class TestStartNoteDialog(TestCase, TestMixin):
QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton)
# THEN the following input text is returned
self.assertEqual(self.form.text_edit.toPlainText(), '', 'The returned text should be empty')
assert self.form.text_edit.toPlainText() == '', 'The returned text should be empty'
# WHEN displaying the UI, having set the text and pressing enter
text = 'OpenLP is the best worship software'
@ -77,7 +77,7 @@ class TestStartNoteDialog(TestCase, TestMixin):
QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton)
# THEN the following text is returned
self.assertEqual(self.form.text_edit.toPlainText(), text, 'The text originally entered should still be there')
assert self.form.text_edit.toPlainText() == text, 'The text originally entered should still be there'
# WHEN displaying the UI, having set the text and pressing enter
self.form.text_edit.setPlainText('')
@ -88,4 +88,4 @@ class TestStartNoteDialog(TestCase, TestMixin):
QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton)
# THEN the following text is returned
self.assertEqual(self.form.text_edit.toPlainText(), text, 'The new text should be returned')
assert self.form.text_edit.toPlainText() == text, 'The new text should be returned'

View File

@ -67,9 +67,9 @@ class TestShortcutform(TestCase, TestMixin):
self.form._adjust_button(button, checked, enabled, text)
# THEN: The button should be changed.
self.assertEqual(button.text(), text, 'The text should match.')
assert button.text() == text, 'The text should match.'
mocked_check_method.assert_called_once_with(True)
self.assertEqual(button.isEnabled(), enabled, 'The button should be disabled.')
assert button.isEnabled() == enabled, 'The button should be disabled.'
def test_space_key_press_event(self):
"""
@ -85,7 +85,7 @@ class TestShortcutform(TestCase, TestMixin):
# THEN: The key should be released
mocked_key_release_event.assert_called_with(mocked_event)
self.assertEqual(0, mocked_event.accept.call_count)
assert 0 == mocked_event.accept.call_count
def test_primary_push_button_checked_key_press_event(self):
"""
@ -102,7 +102,7 @@ class TestShortcutform(TestCase, TestMixin):
# THEN: The key should be released
mocked_key_release_event.assert_called_with(mocked_event)
self.assertEqual(0, mocked_event.accept.call_count)
assert 0 == mocked_event.accept.call_count
def test_alternate_push_button_checked_key_press_event(self):
"""
@ -119,7 +119,7 @@ class TestShortcutform(TestCase, TestMixin):
# THEN: The key should be released
mocked_key_release_event.assert_called_with(mocked_event)
self.assertEqual(0, mocked_event.accept.call_count)
assert 0 == mocked_event.accept.call_count
def test_escape_key_press_event(self):
"""
@ -148,7 +148,7 @@ class TestShortcutform(TestCase, TestMixin):
self.form.on_default_radio_button_clicked(False)
# THEN: The method should exit early (i.e. the rest of the methods are not called)
self.assertEqual(0, mocked_current_item_action.call_count)
assert 0 == mocked_current_item_action.call_count
def test_on_default_radio_button_clicked_no_action(self):
"""
@ -164,7 +164,7 @@ class TestShortcutform(TestCase, TestMixin):
# THEN: The method should exit early (i.e. the rest of the methods are not called)
mocked_current_item_action.assert_called_with()
self.assertEqual(0, mocked_action_shortcuts.call_count)
assert 0 == mocked_action_shortcuts.call_count
def test_on_default_radio_button_clicked(self):
"""
@ -202,7 +202,7 @@ class TestShortcutform(TestCase, TestMixin):
self.form.on_custom_radio_button_clicked(False)
# THEN: The method should exit early (i.e. the rest of the methods are not called)
self.assertEqual(0, mocked_current_item_action.call_count)
assert 0 == mocked_current_item_action.call_count
def test_on_custom_radio_button_clicked(self):
"""

View File

@ -56,28 +56,24 @@ class TestStartTimeDialog(TestCase, TestMixin):
"""
Test StartTimeDialog are defaults correct
"""
self.assertEqual(self.form.hour_spin_box.minimum(), 0, 'The minimum hour should stay the same as the dialog')
self.assertEqual(self.form.hour_spin_box.maximum(), 4, 'The maximum hour should stay the same as the dialog')
self.assertEqual(self.form.minute_spin_box.minimum(), 0,
'The minimum minute should stay the same as the dialog')
self.assertEqual(self.form.minute_spin_box.maximum(), 59,
'The maximum minute should stay the same as the dialog')
self.assertEqual(self.form.second_spin_box.minimum(), 0,
'The minimum second should stay the same as the dialog')
self.assertEqual(self.form.second_spin_box.maximum(), 59,
'The maximum second should stay the same as the dialog')
self.assertEqual(self.form.hour_finish_spin_box.minimum(), 0,
'The minimum finish hour should stay the same as the dialog')
self.assertEqual(self.form.hour_finish_spin_box.maximum(), 4,
'The maximum finish hour should stay the same as the dialog')
self.assertEqual(self.form.minute_finish_spin_box.minimum(), 0,
'The minimum finish minute should stay the same as the dialog')
self.assertEqual(self.form.minute_finish_spin_box.maximum(), 59,
'The maximum finish minute should stay the same as the dialog')
self.assertEqual(self.form.second_finish_spin_box.minimum(), 0,
'The minimum finish second should stay the same as the dialog')
self.assertEqual(self.form.second_finish_spin_box.maximum(), 59,
'The maximum finish second should stay the same as the dialog')
assert self.form.hour_spin_box.minimum() == 0, 'The minimum hour should stay the same as the dialog'
assert self.form.hour_spin_box.maximum() == 4, 'The maximum hour should stay the same as the dialog'
assert self.form.minute_spin_box.minimum() == 0, 'The minimum minute should stay the same as the dialog'
assert self.form.minute_spin_box.maximum() == 59, 'The maximum minute should stay the same as the dialog'
assert self.form.second_spin_box.minimum() == 0, 'The minimum second should stay the same as the dialog'
assert self.form.second_spin_box.maximum() == 59, 'The maximum second should stay the same as the dialog'
assert self.form.hour_finish_spin_box.minimum() == 0, \
'The minimum finish hour should stay the same as the dialog'
assert self.form.hour_finish_spin_box.maximum() == 4, \
'The maximum finish hour should stay the same as the dialog'
assert self.form.minute_finish_spin_box.minimum() == 0, \
'The minimum finish minute should stay the same as the dialog'
assert self.form.minute_finish_spin_box.maximum() == 59, \
'The maximum finish minute should stay the same as the dialog'
assert self.form.second_finish_spin_box.minimum() == 0, \
'The minimum finish second should stay the same as the dialog'
assert self.form.second_finish_spin_box.maximum() == 59, \
'The maximum finish second should stay the same as the dialog'
def test_time_display(self):
"""
@ -97,10 +93,10 @@ class TestStartTimeDialog(TestCase, TestMixin):
QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton)
# THEN the following input values are returned
self.assertEqual(self.form.hour_spin_box.value(), 0)
self.assertEqual(self.form.minute_spin_box.value(), 1)
self.assertEqual(self.form.second_spin_box.value(), 1)
self.assertEqual(self.form.item['service_item'].start_time, 61, 'The start time should stay the same')
assert self.form.hour_spin_box.value() == 0
assert self.form.minute_spin_box.value() == 1
assert self.form.second_spin_box.value() == 1
assert self.form.item['service_item'].start_time == 61, 'The start time should stay the same'
# WHEN displaying the UI, changing the time to 2min 3secs and pressing enter
self.form.item = {'service_item': mocked_serviceitem}
@ -112,7 +108,7 @@ class TestStartTimeDialog(TestCase, TestMixin):
QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton)
# THEN the following values are returned
self.assertEqual(self.form.hour_spin_box.value(), 0)
self.assertEqual(self.form.minute_spin_box.value(), 2)
self.assertEqual(self.form.second_spin_box.value(), 3)
self.assertEqual(self.form.item['service_item'].start_time, 123, 'The start time should have changed')
assert self.form.hour_spin_box.value() == 0
assert self.form.minute_spin_box.value() == 2
assert self.form.second_spin_box.value() == 3
assert self.form.item['service_item'].start_time == 123, 'The start time should have changed'

View File

@ -121,4 +121,4 @@ class TestThemeManager(TestCase, TestMixin):
self.theme_manager.bootstrap_post_set_up()
# THEN:
self.assertEqual(1, self.theme_manager.load_themes.call_count, "load_themes should have been called once")
assert 1 == self.theme_manager.load_themes.call_count, "load_themes should have been called once"

View File

@ -86,8 +86,8 @@ class TestSearchEdit(TestCase, TestMixin):
# THEN: The first search type should be the first one in the list. The selected type should be saved in the
# settings
self.assertEqual(self.search_edit.current_search_type(), SearchTypes.First,
"The first search type should be selected.")
assert self.search_edit.current_search_type() == SearchTypes.First, \
"The first search type should be selected."
self.mocked_settings().setValue.assert_called_once_with('settings_section/last used search type', 0)
def test_set_current_search_type(self):
@ -99,11 +99,11 @@ class TestSearchEdit(TestCase, TestMixin):
result = self.search_edit.set_current_search_type(SearchTypes.Second)
# THEN:
self.assertTrue(result, "The call should return success (True).")
self.assertEqual(self.search_edit.current_search_type(), SearchTypes.Second,
"The search type should be SearchTypes.Second")
self.assertEqual(self.search_edit.placeholderText(), SECOND_PLACEHOLDER_TEXT,
"The correct placeholder text should be 'Second Placeholder Text'.")
assert result is True, "The call should return success (True)."
assert self.search_edit.current_search_type() == SearchTypes.Second, \
"The search type should be SearchTypes.Second"
assert self.search_edit.placeholderText() == SECOND_PLACEHOLDER_TEXT, \
"The correct placeholder text should be 'Second Placeholder Text'."
self.mocked_settings().setValue.assert_has_calls(
[call('settings_section/last used search type', 0), call('settings_section/last used search type', 1)])
@ -166,4 +166,4 @@ class TestHistoryComboBox(TestCase, TestMixin):
self.combo.addItem('test2')
# THEN: The list of items should contain both strings.
self.assertEqual(self.combo.getItems(), ['test1', 'test2'])
assert self.combo.getItems() == ['test1', 'test2']

View File

@ -64,7 +64,7 @@ class TestListPreviewWidget(TestCase, TestMixin):
# GIVEN: A new ListPreviewWidget instance.
# WHEN: No SlideItem has been added yet.
# THEN: The count of items should be zero.
self.assertEqual(self.preview_widget.slide_count(), 0, 'The slide list should be empty.')
assert self.preview_widget.slide_count() == 0, 'The slide list should be empty.'
def test_initial_slide_number(self):
"""
@ -73,7 +73,7 @@ class TestListPreviewWidget(TestCase, TestMixin):
# GIVEN: A new ListPreviewWidget instance.
# WHEN: No SlideItem has been added yet.
# THEN: The number of the current item should be -1.
self.assertEqual(self.preview_widget.current_slide_number(), -1, 'The slide number should be -1.')
assert self.preview_widget.current_slide_number() == -1, 'The slide number should be -1.'
def test_replace_service_item(self):
"""
@ -87,8 +87,8 @@ class TestListPreviewWidget(TestCase, TestMixin):
# WHEN: Added to the preview widget.
self.preview_widget.replace_service_item(service_item, 1, 1)
# THEN: The slide count and number should fit.
self.assertEqual(self.preview_widget.slide_count(), 2, 'The slide count should be 2.')
self.assertEqual(self.preview_widget.current_slide_number(), 1, 'The current slide number should be 1.')
assert self.preview_widget.slide_count() == 2, 'The slide count should be 2.'
assert self.preview_widget.current_slide_number() == 1, 'The current slide number should be 1.'
def test_change_slide(self):
"""
@ -103,4 +103,4 @@ class TestListPreviewWidget(TestCase, TestMixin):
self.preview_widget.replace_service_item(service_item, 1, 0)
self.preview_widget.change_slide(1)
# THEN: The current_slide_number should reflect the change.
self.assertEqual(self.preview_widget.current_slide_number(), 1, 'The current slide number should be 1.')
assert self.preview_widget.current_slide_number() == 1, 'The current slide number should be 1.'

View File

@ -78,7 +78,7 @@ class TestBibleImportForm(TestCase, TestMixin):
self.form.on_web_update_button_clicked()
# THEN: The webbible list should still be empty
self.assertEqual(self.form.web_bible_list, {}, 'The webbible list should be empty')
assert self.form.web_bible_list == {}, 'The webbible list should be empty'
def test_custom_init(self):
"""

View File

@ -53,8 +53,8 @@ class TestBibleHTTP(TestCase):
books = handler.get_books_from_http('NIV')
# THEN: We should get back a valid service item
self.assertEqual(len(books), 66, 'The bible should not have had any books added or removed')
self.assertEqual(books[0], 'Genesis', 'The first bible book should be Genesis')
assert len(books) == 66, 'The bible should not have had any books added or removed'
assert books[0] == 'Genesis', 'The first bible book should be Genesis'
def test_bible_gateway_extract_books_support_redirect(self):
"""
@ -67,7 +67,7 @@ class TestBibleHTTP(TestCase):
books = handler.get_books_from_http('DN1933')
# THEN: We should get back a valid service item
self.assertEqual(len(books), 66, 'This bible should have 66 books')
assert len(books) == 66, 'This bible should have 66 books'
def test_bible_gateway_extract_verse(self):
"""
@ -80,8 +80,7 @@ class TestBibleHTTP(TestCase):
results = handler.get_bible_chapter('NIV', 'John', 3)
# THEN: We should get back a valid service item
self.assertEqual(len(results.verse_list), 36,
'The book of John should not have had any verses added or removed')
assert len(results.verse_list) == 36, 'The book of John should not have had any verses added or removed'
def test_bible_gateway_extract_verse_nkjv(self):
"""
@ -94,8 +93,7 @@ class TestBibleHTTP(TestCase):
results = handler.get_bible_chapter('NKJV', 'John', 3)
# THEN: We should get back a valid service item
self.assertEqual(len(results.verse_list), 36,
'The book of John should not have had any verses added or removed')
assert len(results.verse_list) == 36, 'The book of John should not have had any verses added or removed'
def test_crosswalk_extract_books(self):
"""
@ -108,7 +106,7 @@ class TestBibleHTTP(TestCase):
books = handler.get_books_from_http('niv')
# THEN: We should get back a valid service item
self.assertEqual(len(books), 66, 'The bible should not have had any books added or removed')
assert len(books) == 66, 'The bible should not have had any books added or removed'
def test_crosswalk_extract_verse(self):
"""
@ -121,8 +119,7 @@ class TestBibleHTTP(TestCase):
results = handler.get_bible_chapter('niv', 'john', 3)
# THEN: We should get back a valid service item
self.assertEqual(len(results.verse_list), 36,
'The book of John should not have had any verses added or removed')
assert len(results.verse_list) == 36, 'The book of John should not have had any verses added or removed'
def test_bibleserver_get_bibles(self):
"""
@ -135,9 +132,9 @@ class TestBibleHTTP(TestCase):
bibles = handler.get_bibles_from_http()
# THEN: The list should not be None, and some known bibles should be there
self.assertIsNotNone(bibles)
self.assertIn(('New Int. Readers Version', 'NIRV', 'en'), bibles)
self.assertIn(('Священное Писание, Восточный перевод', 'CARS', 'ru'), bibles)
assert bibles is not None
assert ('New Int. Readers Version', 'NIRV', 'en') in bibles
assert ('Священное Писание, Восточный перевод', 'CARS', 'ru') in bibles
def test_biblegateway_get_bibles(self):
"""
@ -150,8 +147,8 @@ class TestBibleHTTP(TestCase):
bibles = handler.get_bibles_from_http()
# THEN: The list should not be None, and some known bibles should be there
self.assertIsNotNone(bibles)
self.assertIn(('Holman Christian Standard Bible (HCSB)', 'HCSB', 'en'), bibles)
assert bibles is not None
assert ('Holman Christian Standard Bible (HCSB)', 'HCSB', 'en') in bibles
def test_crosswalk_get_bibles(self):
"""
@ -164,8 +161,8 @@ class TestBibleHTTP(TestCase):
bibles = handler.get_bibles_from_http()
# THEN: The list should not be None, and some known bibles should be there
self.assertIsNotNone(bibles)
self.assertIn(('Giovanni Diodati 1649 (Italian)', 'gdb', 'it'), bibles)
assert bibles is not None
assert ('Giovanni Diodati 1649 (Italian)', 'gdb', 'it') in bibles
def test_crosswalk_get_verse_text(self):
"""
@ -178,7 +175,6 @@ class TestBibleHTTP(TestCase):
niv_genesis_chapter_one = handler.get_bible_chapter('niv', 'Genesis', 1)
# THEN: The verse list should contain the verses
self.assertTrue(niv_genesis_chapter_one.has_verse_list())
self.assertEquals('In the beginning God created the heavens and the earth.',
niv_genesis_chapter_one.verse_list[1],
'The first chapter of genesis should have been fetched.')
assert niv_genesis_chapter_one.has_verse_list() is True
assert 'In the beginning God created the heavens and the earth.' == niv_genesis_chapter_one.verse_list[1], \
'The first chapter of genesis should have been fetched.'

View File

@ -79,7 +79,7 @@ class TestBibleManager(TestCase, TestMixin):
# WHEN asking for the books of the bible
books = self.manager.get_books('tests')
# THEN a list of books should be returned
self.assertEqual(66, len(books), 'There should be 66 books in the bible')
assert 66 == len(books), 'There should be 66 books in the bible'
def test_get_book_by_id(self):
"""
@ -89,7 +89,7 @@ class TestBibleManager(TestCase, TestMixin):
# WHEN asking for the book of the bible
book = self.manager.get_book_by_id('tests', 54)
# THEN a book should be returned
self.assertEqual('1 Timothy', book.name, '1 Timothy should have been returned from the bible')
assert '1 Timothy' == book.name, '1 Timothy should have been returned from the bible'
def test_get_chapter_count(self):
"""
@ -100,7 +100,7 @@ class TestBibleManager(TestCase, TestMixin):
book = self.manager.get_book_by_id('tests', 54)
chapter = self.manager.get_chapter_count('tests', book)
# THEN the chapter count should be returned
self.assertEqual(6, chapter, '1 Timothy should have 6 chapters returned from the bible')
assert 6 == chapter, '1 Timothy should have 6 chapters returned from the bible'
def test_get_verse_count_by_book_ref_id(self):
"""
@ -110,4 +110,4 @@ class TestBibleManager(TestCase, TestMixin):
# WHEN asking for the number of verses in a book of the bible
verses = self.manager.get_verse_count_by_book_ref_id('tests', 54, 3)
# THEN the chapter count should be returned
self.assertEqual(16, verses, '1 Timothy v3 should have 16 verses returned from the bible')
assert 16 == verses, '1 Timothy v3 should have 16 verses returned from the bible'

View File

@ -79,7 +79,7 @@ class TestBibleManager(TestCase, TestMixin):
# WHEN asking to parse the bible reference
results = parse_reference('1 Timothy 1', self.manager.db_cache['tests'], MagicMock(), 54)
# THEN a verse array should be returned
self.assertEqual([(54, 1, 1, -1)], results, "The bible verses should matches the expected results")
assert [(54, 1, 1, -1)] == results, "The bible verses should matches the expected results"
def test_parse_reference_two(self):
"""
@ -89,7 +89,7 @@ class TestBibleManager(TestCase, TestMixin):
# WHEN asking to parse the bible reference
results = parse_reference('1 Timothy 1:1-2', self.manager.db_cache['tests'], MagicMock(), 54)
# THEN a verse array should be returned
self.assertEqual([(54, 1, 1, 2)], results, "The bible verses should matches the expected results")
assert [(54, 1, 1, 2)] == results, "The bible verses should matches the expected results"
def test_parse_reference_three(self):
"""
@ -99,8 +99,8 @@ class TestBibleManager(TestCase, TestMixin):
# WHEN asking to parse the bible reference
results = parse_reference('1 Timothy 1:1-2:1', self.manager.db_cache['tests'], MagicMock(), 54)
# THEN a verse array should be returned
self.assertEqual([(54, 1, 1, -1), (54, 2, 1, 1)], results,
"The bible verses should match the expected results")
assert [(54, 1, 1, -1), (54, 2, 1, 1)] == results, \
"The bible verses should match the expected results"
def test_parse_reference_four(self):
"""
@ -110,7 +110,7 @@ class TestBibleManager(TestCase, TestMixin):
# WHEN asking to parse the bible reference
results = parse_reference('Raoul 1', self.manager.db_cache['tests'], MagicMock())
# THEN a verse array should be returned
self.assertEqual([], results, "The bible Search should return an empty list")
assert [] == results, "The bible Search should return an empty list"
def test_parse_reference_five(self):
"""
@ -120,4 +120,4 @@ class TestBibleManager(TestCase, TestMixin):
# WHEN asking to parse the bible reference
results = parse_reference('1 Timothy 1:3-end', self.manager.db_cache['tests'], MagicMock(), 54)
# THEN a verse array should be returned
self.assertEqual([(54, 1, 3, -1)], results, "The bible verses should matches the expected results")
assert [(54, 1, 3, -1)] == results, "The bible verses should matches the expected results"

View File

@ -78,8 +78,8 @@ class TestEditCustomForm(TestCase, TestMixin):
self.form.load_custom(0)
# THEN: The line edits should not contain any text.
self.assertEqual(self.form.title_edit.text(), '', 'The title edit should be empty')
self.assertEqual(self.form.credit_edit.text(), '', 'The credit edit should be empty')
assert self.form.title_edit.text() == '', 'The title edit should be empty'
assert self.form.credit_edit.text() == '', 'The credit edit should be empty'
def test_on_add_button_clicked(self):
"""

View File

@ -58,9 +58,9 @@ class TestAuthorsForm(TestCase, TestMixin):
"""
Test the AuthorForm defaults are correct
"""
self.assertEqual(self.form.first_name_edit.text(), '', 'The first name edit should be empty')
self.assertEqual(self.form.last_name_edit.text(), '', 'The last name edit should be empty')
self.assertEqual(self.form.display_edit.text(), '', 'The display name edit should be empty')
assert self.form.first_name_edit.text() == '', 'The first name edit should be empty'
assert self.form.last_name_edit.text() == '', 'The last name edit should be empty'
assert self.form.display_edit.text() == '', 'The display name edit should be empty'
def test_get_first_name_property(self):
"""
@ -73,7 +73,7 @@ class TestAuthorsForm(TestCase, TestMixin):
self.form.first_name_edit.setText(first_name)
# THEN: The first_name property should have the correct value
self.assertEqual(self.form.first_name, first_name, 'The first name property should be correct')
assert self.form.first_name == first_name, 'The first name property should be correct'
def test_set_first_name_property(self):
"""
@ -86,7 +86,7 @@ class TestAuthorsForm(TestCase, TestMixin):
self.form.first_name = first_name
# THEN: The first_name_edit should have the correct value
self.assertEqual(self.form.first_name_edit.text(), first_name, 'The first name should be set correctly')
assert self.form.first_name_edit.text() == first_name, 'The first name should be set correctly'
def test_get_last_name_property(self):
"""
@ -99,7 +99,7 @@ class TestAuthorsForm(TestCase, TestMixin):
self.form.last_name_edit.setText(last_name)
# THEN: The last_name property should have the correct value
self.assertEqual(self.form.last_name, last_name, 'The last name property should be correct')
assert self.form.last_name == last_name, 'The last name property should be correct'
def test_set_last_name_property(self):
"""
@ -112,7 +112,7 @@ class TestAuthorsForm(TestCase, TestMixin):
self.form.last_name = last_name
# THEN: The last_name_edit should have the correct value
self.assertEqual(self.form.last_name_edit.text(), last_name, 'The last name should be set correctly')
assert self.form.last_name_edit.text() == last_name, 'The last name should be set correctly'
def test_get_display_name_property(self):
"""
@ -125,7 +125,7 @@ class TestAuthorsForm(TestCase, TestMixin):
self.form.display_edit.setText(display_name)
# THEN: The display_name property should have the correct value
self.assertEqual(self.form.display_name, display_name, 'The display name property should be correct')
assert self.form.display_name == display_name, 'The display name property should be correct'
def test_set_display_name_property(self):
"""
@ -138,7 +138,7 @@ class TestAuthorsForm(TestCase, TestMixin):
self.form.display_name = display_name
# THEN: The display_name_edit should have the correct value
self.assertEqual(self.form.display_edit.text(), display_name, 'The display name should be set correctly')
assert self.form.display_edit.text() == display_name, 'The display name should be set correctly'
@patch('openlp.plugins.songs.forms.authorsform.QtWidgets.QDialog.exec')
def test_exec(self, mocked_exec):

View File

@ -69,10 +69,10 @@ class TestEditSongForm(TestCase, TestMixin):
"""
Test that the EditSongForm defaults are correct
"""
self.assertFalse(self.form.verse_edit_button.isEnabled(), 'The verse edit button should not be enabled')
self.assertFalse(self.form.verse_delete_button.isEnabled(), 'The verse delete button should not be enabled')
self.assertFalse(self.form.author_remove_button.isEnabled(), 'The author remove button should not be enabled')
self.assertFalse(self.form.topic_remove_button.isEnabled(), 'The topic remove button should not be enabled')
assert self.form.verse_edit_button.isEnabled() is False, 'The verse edit button should not be enabled'
assert self.form.verse_delete_button.isEnabled() is False, 'The verse delete button should not be enabled'
assert self.form.author_remove_button.isEnabled() is False, 'The author remove button should not be enabled'
assert self.form.topic_remove_button.isEnabled() is False, 'The topic remove button should not be enabled'
def test_is_verse_edit_form_executed(self):
pass
@ -147,10 +147,10 @@ class TestEditSongForm(TestCase, TestMixin):
# GIVEN; Mocked methods
form = self.form
# THEN: CCLI label should be CCLI song label
self.assertNotEquals(form.ccli_label.text(), UiStrings().CCLINumberLabel,
'CCLI label should not be "{}"'.format(UiStrings().CCLINumberLabel))
self.assertEquals(form.ccli_label.text(), UiStrings().CCLISongNumberLabel,
'CCLI label text should be "{}"'.format(UiStrings().CCLISongNumberLabel))
assert form.ccli_label.text() is not UiStrings().CCLINumberLabel, \
'CCLI label should not be "{}"'.format(UiStrings().CCLINumberLabel)
assert form.ccli_label.text() == UiStrings().CCLISongNumberLabel, \
'CCLI label text should be "{}"'.format(UiStrings().CCLISongNumberLabel)
def test_verse_order_lowercase(self):
"""
@ -165,4 +165,4 @@ class TestEditSongForm(TestCase, TestMixin):
form.on_verse_order_text_changed(form.verse_order_edit.text())
# THEN: The verse order should be converted to uppercase
self.assertEqual(form.verse_order_edit.text(), 'V1 V2 C1 V3 C1 V4 C1')
assert form.verse_order_edit.text() == 'V1 V2 C1 V3 C1 V4 C1'

View File

@ -68,7 +68,7 @@ class TestEditVerseForm(TestCase, TestMixin):
# GIVEN: An EditVerseForm instance
# WHEN: The form is shown
# THEN: The default value is correct
self.assertEqual(self.form.verse_text_edit.toPlainText(), '', 'The verse edit box is empty.')
assert self.form.verse_text_edit.toPlainText() == '', 'The verse edit box is empty.'
def test_type_verse_text(self):
"""
@ -81,8 +81,8 @@ class TestEditVerseForm(TestCase, TestMixin):
QtTest.QTest.keyClicks(self.form.verse_text_edit, text)
# THEN: The verse text edit should have the verse text in it
self.assertEqual(text, self.form.verse_text_edit.toPlainText(),
'The verse text edit should have the typed out verse')
assert text == self.form.verse_text_edit.toPlainText(), \
'The verse text edit should have the typed out verse'
def test_insert_verse(self):
"""
@ -93,8 +93,8 @@ class TestEditVerseForm(TestCase, TestMixin):
QtTest.QTest.mouseClick(self.form.insert_button, QtCore.Qt.LeftButton)
# THEN: The verse text edit should have a Verse:1 in it
self.assertIn('---[Verse:1]---', self.form.verse_text_edit.toPlainText(),
'The verse text edit should have a verse marker')
assert '---[Verse:1]---' in self.form.verse_text_edit.toPlainText(), \
'The verse text edit should have a verse marker'
def test_insert_verse_2(self):
"""
@ -106,8 +106,8 @@ class TestEditVerseForm(TestCase, TestMixin):
QtTest.QTest.mouseClick(self.form.insert_button, QtCore.Qt.LeftButton)
# THEN: The verse text edit should have a Verse:1 in it
self.assertIn('---[Verse:2]---', self.form.verse_text_edit.toPlainText(),
'The verse text edit should have a "Verse 2" marker')
assert '---[Verse:2]---' in self.form.verse_text_edit.toPlainText(), \
'The verse text edit should have a "Verse 2" marker'
def test_insert_chorus(self):
"""
@ -119,5 +119,5 @@ class TestEditVerseForm(TestCase, TestMixin):
QtTest.QTest.mouseClick(self.form.insert_button, QtCore.Qt.LeftButton)
# THEN: The verse text edit should have a Chorus:1 in it
self.assertIn('---[Chorus:1]---', self.form.verse_text_edit.toPlainText(),
'The verse text edit should have a "Chorus 1" marker')
assert '---[Chorus:1]---' in self.form.verse_text_edit.toPlainText(), \
'The verse text edit should have a "Chorus 1" marker'

View File

@ -57,7 +57,7 @@ class TestTopicsForm(TestCase, TestMixin):
"""
Test the TopicsForm defaults are correct
"""
self.assertEqual(self.form.name_edit.text(), '', 'The first name edit should be empty')
assert self.form.name_edit.text() == '', 'The first name edit should be empty'
def test_get_name_property(self):
"""
@ -70,7 +70,7 @@ class TestTopicsForm(TestCase, TestMixin):
self.form.name_edit.setText(topic_name)
# THEN: The name property should have the correct value
self.assertEqual(self.form.name, topic_name, 'The name property should be correct')
assert self.form.name == topic_name, 'The name property should be correct'
def test_set_name_property(self):
"""
@ -83,4 +83,4 @@ class TestTopicsForm(TestCase, TestMixin):
self.form.name = topic_name
# THEN: The name_edit should have the correct value
self.assertEqual(self.form.name_edit.text(), topic_name, 'The topic name should be set correctly')
assert self.form.name_edit.text() == topic_name, 'The topic name should be set correctly'

View File

@ -52,4 +52,4 @@ class TestBzrTags(TestCase):
count1 += 1
# THEN the tags should match the accepted tags
self.assertEqual(count, count1, 'List of tags should match')
assert count == count1, 'List of tags should match'

View File

@ -80,7 +80,7 @@ class TestPylint(TestCase):
print(stderr)
# THEN: The output should be empty
self.assertTrue(filtered_stdout == '', 'PyLint should find no errors')
assert filtered_stdout == '', 'PyLint should find no errors'
def _filter_tolerated_errors(self, pylint_output):
"""