From 9e8fe903a7b195af3bff5281f56b0ca6f96da83f Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 14 Jan 2016 22:25:58 +0200 Subject: [PATCH 01/10] attempt to fix some tests in windows --- tests/functional/openlp_core_utils/test_db.py | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/tests/functional/openlp_core_utils/test_db.py b/tests/functional/openlp_core_utils/test_db.py index 01ed9d0d5..b46e97a80 100644 --- a/tests/functional/openlp_core_utils/test_db.py +++ b/tests/functional/openlp_core_utils/test_db.py @@ -40,11 +40,18 @@ class TestUtilsDBFunctions(TestCase): Create temp folder for keeping db file """ self.tmp_folder = mkdtemp() + db_path = os.path.join(TEST_RESOURCES_PATH, 'songs', 'songs-1.9.7.sqlite') + db_tmp_path = os.path.join(self.tmp_folder, 'songs-1.9.7.sqlite') + shutil.copyfile(db_path, db_tmp_path) + db_url = 'sqlite:///' + db_tmp_path + self.session, metadata = init_db(db_url) + self.op = get_upgrade_op(self.session) def tearDown(self): """ Clean up """ + self.session.close() shutil.rmtree(self.tmp_folder) def delete_column_test(self): @@ -52,18 +59,12 @@ class TestUtilsDBFunctions(TestCase): Test deleting a single column in a table """ # GIVEN: A temporary song db - db_path = os.path.join(TEST_RESOURCES_PATH, 'songs', 'songs-1.9.7.sqlite') - db_tmp_path = os.path.join(self.tmp_folder, 'songs-1.9.7.sqlite') - shutil.copyfile(db_path, db_tmp_path) - db_url = 'sqlite:///' + db_tmp_path - session, metadata = init_db(db_url) - op = get_upgrade_op(session) # WHEN: Deleting a columns in a table - drop_column(op, 'songs', 'song_book_id') + drop_column(self.op, 'songs', 'song_book_id') # THEN: The column should have been deleted - meta = sqlalchemy.MetaData(bind=op.get_bind()) + meta = sqlalchemy.MetaData(bind=self.op.get_bind()) meta.reflect() columns = meta.tables['songs'].columns @@ -76,21 +77,16 @@ class TestUtilsDBFunctions(TestCase): Test deleting multiple columns in a table """ # GIVEN: A temporary song db - db_path = os.path.join(TEST_RESOURCES_PATH, 'songs', 'songs-1.9.7.sqlite') - db_tmp_path = os.path.join(self.tmp_folder, 'songs-1.9.7.sqlite') - shutil.copyfile(db_path, db_tmp_path) - db_url = 'sqlite:///' + db_tmp_path - session, metadata = init_db(db_url) - op = get_upgrade_op(session) # WHEN: Deleting a columns in a table - drop_columns(op, 'songs', ['song_book_id', 'song_number']) + drop_columns(self.op, 'songs', ['song_book_id', 'song_number']) # THEN: The columns should have been deleted - meta = sqlalchemy.MetaData(bind=op.get_bind()) + meta = sqlalchemy.MetaData(bind=self.op.get_bind()) meta.reflect() columns = meta.tables['songs'].columns for column in columns: if column.name == 'song_book_id' or column.name == 'song_number': self.fail("The column '%s' should have been deleted." % column.name) + From 11b7bfd22d0325386bbe05cf59aed5f9ab467e8f Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 14 Jan 2016 22:31:37 +0200 Subject: [PATCH 02/10] See if waiting a second helps --- tests/functional/openlp_core_utils/test_db.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/functional/openlp_core_utils/test_db.py b/tests/functional/openlp_core_utils/test_db.py index b46e97a80..5968536f6 100644 --- a/tests/functional/openlp_core_utils/test_db.py +++ b/tests/functional/openlp_core_utils/test_db.py @@ -27,6 +27,7 @@ import shutil import sqlalchemy from unittest import TestCase from tempfile import mkdtemp +import time from openlp.core.utils.db import drop_column, drop_columns from openlp.core.lib.db import init_db, get_upgrade_op @@ -52,6 +53,7 @@ class TestUtilsDBFunctions(TestCase): Clean up """ self.session.close() + time.sleep(1) shutil.rmtree(self.tmp_folder) def delete_column_test(self): From 402917024bc8766d6a8f627d97b197d978243ee4 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 15 Jan 2016 19:11:02 +0200 Subject: [PATCH 03/10] Another go at this --- tests/functional/openlp_core_utils/test_db.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/functional/openlp_core_utils/test_db.py b/tests/functional/openlp_core_utils/test_db.py index 5968536f6..baeb195e0 100644 --- a/tests/functional/openlp_core_utils/test_db.py +++ b/tests/functional/openlp_core_utils/test_db.py @@ -53,6 +53,7 @@ class TestUtilsDBFunctions(TestCase): Clean up """ self.session.close() + self.session = None time.sleep(1) shutil.rmtree(self.tmp_folder) From d7b9e2cbe519d18bc08c24ab1d9e8e611604fd59 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 15 Jan 2016 19:50:57 +0200 Subject: [PATCH 04/10] Try deleting the file itself after telling Python to do garbage collection --- tests/functional/openlp_core_utils/test_db.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/functional/openlp_core_utils/test_db.py b/tests/functional/openlp_core_utils/test_db.py index baeb195e0..b3ebafd89 100644 --- a/tests/functional/openlp_core_utils/test_db.py +++ b/tests/functional/openlp_core_utils/test_db.py @@ -22,15 +22,17 @@ """ Package to test the openlp.core.utils.db package. """ +from tempfile import mkdtemp +from unittest import TestCase +import gc import os import shutil import sqlalchemy -from unittest import TestCase -from tempfile import mkdtemp import time from openlp.core.utils.db import drop_column, drop_columns from openlp.core.lib.db import init_db, get_upgrade_op + from tests.utils.constants import TEST_RESOURCES_PATH @@ -42,9 +44,9 @@ class TestUtilsDBFunctions(TestCase): """ self.tmp_folder = mkdtemp() db_path = os.path.join(TEST_RESOURCES_PATH, 'songs', 'songs-1.9.7.sqlite') - db_tmp_path = os.path.join(self.tmp_folder, 'songs-1.9.7.sqlite') - shutil.copyfile(db_path, db_tmp_path) - db_url = 'sqlite:///' + db_tmp_path + self.db_tmp_path = os.path.join(self.tmp_folder, 'songs-1.9.7.sqlite') + shutil.copyfile(db_path, self.db_tmp_path) + db_url = 'sqlite:///' + self.db_tmp_path self.session, metadata = init_db(db_url) self.op = get_upgrade_op(self.session) @@ -54,7 +56,9 @@ class TestUtilsDBFunctions(TestCase): """ self.session.close() self.session = None + gc.collect() time.sleep(1) + os.unlink(self.db_tmp_path) shutil.rmtree(self.tmp_folder) def delete_column_test(self): From b11b88f4eb4079c2f13e65c82f25c4dcc3866f57 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 15 Jan 2016 19:58:21 +0200 Subject: [PATCH 05/10] Add a retry mechanism --- tests/functional/openlp_core_utils/test_db.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/functional/openlp_core_utils/test_db.py b/tests/functional/openlp_core_utils/test_db.py index b3ebafd89..6575f4875 100644 --- a/tests/functional/openlp_core_utils/test_db.py +++ b/tests/functional/openlp_core_utils/test_db.py @@ -57,8 +57,14 @@ class TestUtilsDBFunctions(TestCase): self.session.close() self.session = None gc.collect() - time.sleep(1) - os.unlink(self.db_tmp_path) + retries = 0 + while retries < 5: + try: + os.unlink(self.db_tmp_path) + break + except: + time.sleep(1) + retries += 1 shutil.rmtree(self.tmp_folder) def delete_column_test(self): From e1ed3ab1637e8c80240c0f797ac5ee04030f509a Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 15 Jan 2016 20:10:09 +0200 Subject: [PATCH 06/10] Use rmtree in the retry mechanism --- tests/functional/openlp_core_utils/test_db.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/functional/openlp_core_utils/test_db.py b/tests/functional/openlp_core_utils/test_db.py index 6575f4875..1e84325e3 100644 --- a/tests/functional/openlp_core_utils/test_db.py +++ b/tests/functional/openlp_core_utils/test_db.py @@ -60,12 +60,13 @@ class TestUtilsDBFunctions(TestCase): retries = 0 while retries < 5: try: - os.unlink(self.db_tmp_path) + shutil.rmtree(self.tmp_folder) + # os.unlink(self.db_tmp_path) break - except: + except Exception as e: time.sleep(1) retries += 1 - shutil.rmtree(self.tmp_folder) + print(e) def delete_column_test(self): """ From 5d21aab53959228ead11c84196e60bf3dc437520 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 15 Jan 2016 20:31:05 +0200 Subject: [PATCH 07/10] Make pep8 happy --- openlp/plugins/songs/forms/editsongform.py | 2 +- openlp/plugins/songs/lib/mediaitem.py | 6 +++--- tests/functional/openlp_core_lib/test_htmlbuilder.py | 3 +-- tests/functional/openlp_core_ui/test_mainwindow.py | 1 - tests/functional/openlp_core_utils/test_db.py | 1 - tests/resources/projector/data.py | 1 - 6 files changed, 5 insertions(+), 9 deletions(-) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 33b106aa0..4bc77c65c 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -515,7 +515,7 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties): self.topics_list_view.addItem(topic_name) self.songbooks_list_view.clear() for songbook_entry in self.song.songbook_entries: - self.add_songbook_entry_to_list(songbook_entry.songbook.id, songbook_entry.songbook.name, + self.add_songbook_entry_to_list(songbook_entry.songbook.id, songbook_entry.songbook.name, songbook_entry.entry) self.audio_list_widget.clear() for media in self.song.media_files: diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index dfa967e22..82a2d6085 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -255,9 +255,9 @@ class SongMediaItem(MediaManagerItem): search_entry = re.sub(r'[^0-9]', '', search_keywords[2]) songbook_entries = (self.plugin.manager.session.query(SongBookEntry) - .join(Book) - .order_by(Book.name) - .order_by(SongBookEntry.entry)) + .join(Book) + .order_by(Book.name) + .order_by(SongBookEntry.entry)) for songbook_entry in songbook_entries: if songbook_entry.song.temporary: continue diff --git a/tests/functional/openlp_core_lib/test_htmlbuilder.py b/tests/functional/openlp_core_lib/test_htmlbuilder.py index 181c485f5..8ca98060d 100644 --- a/tests/functional/openlp_core_lib/test_htmlbuilder.py +++ b/tests/functional/openlp_core_lib/test_htmlbuilder.py @@ -363,9 +363,8 @@ class Htmbuilder(TestCase, TestMixin): """ Test the webkit_version() function """ - # GIVEN: Webkit + # GIVEN: Webkit webkit_ver = float(QtWebKit.qWebKitVersion()) # WHEN: Retrieving the webkit version # THEN: Webkit versions should match self.assertEquals(webkit_version(), webkit_ver, "The returned webkit version doesn't match the installed one") - diff --git a/tests/functional/openlp_core_ui/test_mainwindow.py b/tests/functional/openlp_core_ui/test_mainwindow.py index 5499a78a7..ba290b865 100644 --- a/tests/functional/openlp_core_ui/test_mainwindow.py +++ b/tests/functional/openlp_core_ui/test_mainwindow.py @@ -190,4 +190,3 @@ class TestMainWindow(TestCase, TestMixin): self.assertEqual(0, mocked_media_manager_dock.setVisible.call_count) mocked_widget.on_focus.assert_called_with() - diff --git a/tests/functional/openlp_core_utils/test_db.py b/tests/functional/openlp_core_utils/test_db.py index 1e84325e3..7ac3c1440 100644 --- a/tests/functional/openlp_core_utils/test_db.py +++ b/tests/functional/openlp_core_utils/test_db.py @@ -103,4 +103,3 @@ class TestUtilsDBFunctions(TestCase): for column in columns: if column.name == 'song_book_id' or column.name == 'song_number': self.fail("The column '%s' should have been deleted." % column.name) - diff --git a/tests/resources/projector/data.py b/tests/resources/projector/data.py index fca9c0ca0..00d150cf2 100644 --- a/tests/resources/projector/data.py +++ b/tests/resources/projector/data.py @@ -59,4 +59,3 @@ TEST3_DATA = dict(ip='333.333.333.333', name='___TEST_THREE___', location='location three', notes='notes three') - From 1e8d787b93b0a816f7d5444c4644858ac12484f8 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 15 Jan 2016 20:37:03 +0200 Subject: [PATCH 08/10] Make pep8 happy --- tests/functional/openlp_core_ui/test_mainwindow.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/functional/openlp_core_ui/test_mainwindow.py b/tests/functional/openlp_core_ui/test_mainwindow.py index ba290b865..a49ded25c 100644 --- a/tests/functional/openlp_core_ui/test_mainwindow.py +++ b/tests/functional/openlp_core_ui/test_mainwindow.py @@ -189,4 +189,3 @@ class TestMainWindow(TestCase, TestMixin): # THEN: The media manager dock is made visible self.assertEqual(0, mocked_media_manager_dock.setVisible.call_count) mocked_widget.on_focus.assert_called_with() - From 48eeb50d0291f689abd44b1820d5a406f926543b Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 15 Jan 2016 21:14:24 +0200 Subject: [PATCH 09/10] Add retries around other db removals --- tests/functional/openlp_core_lib/test_projectordb.py | 10 ++++++++-- tests/functional/openlp_core_utils/test_db.py | 7 +++---- .../openlp_core_ui/test_projectorsourceform.py | 10 ++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_projectordb.py b/tests/functional/openlp_core_lib/test_projectordb.py index 58eff13bc..8243292d0 100644 --- a/tests/functional/openlp_core_lib/test_projectordb.py +++ b/tests/functional/openlp_core_lib/test_projectordb.py @@ -87,8 +87,6 @@ class TestProjectorDB(TestCase): Set up anything necessary for all tests """ with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url: - if os.path.exists(TEST_DB): - os.unlink(TEST_DB) mocked_init_url.return_value = 'sqlite:///%s' % TEST_DB self.projector = ProjectorDB() @@ -98,6 +96,14 @@ class TestProjectorDB(TestCase): """ self.projector.session.close() self.projector = None + while retries < 5: + try: + if os.path.exists(TEST_DB): + os.unlink(TEST_DB) + break + except: + time.sleep(1) + retries += 1 def find_record_by_ip_test(self): """ diff --git a/tests/functional/openlp_core_utils/test_db.py b/tests/functional/openlp_core_utils/test_db.py index 7ac3c1440..f2c3d264a 100644 --- a/tests/functional/openlp_core_utils/test_db.py +++ b/tests/functional/openlp_core_utils/test_db.py @@ -60,13 +60,12 @@ class TestUtilsDBFunctions(TestCase): retries = 0 while retries < 5: try: - shutil.rmtree(self.tmp_folder) - # os.unlink(self.db_tmp_path) + if os.path.exists(self.tmp_folder): + shutil.rmtree(self.tmp_folder) break - except Exception as e: + except: time.sleep(1) retries += 1 - print(e) def delete_column_test(self): """ diff --git a/tests/interfaces/openlp_core_ui/test_projectorsourceform.py b/tests/interfaces/openlp_core_ui/test_projectorsourceform.py index b4951e910..3b08db149 100644 --- a/tests/interfaces/openlp_core_ui/test_projectorsourceform.py +++ b/tests/interfaces/openlp_core_ui/test_projectorsourceform.py @@ -65,8 +65,6 @@ class ProjectorSourceFormTest(TestCase, TestMixin): """ Set up anything necessary for all tests """ - if os.path.exists(TEST_DB): - os.unlink(TEST_DB) mocked_init_url.return_value = 'sqlite:///{}'.format(TEST_DB) self.build_settings() self.setup_application() @@ -90,6 +88,14 @@ class ProjectorSourceFormTest(TestCase, TestMixin): self.projectordb.session.close() del(self.projectordb) del(self.projector) + while retries < 5: + try: + if os.path.exists(TEST_DB): + os.unlink(TEST_DB) + break + except: + time.sleep(1) + retries += 1 self.destroy_settings() def source_dict_test(self): From 478d356d2e0ba21aa586537df2d537c82ea52f83 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 15 Jan 2016 21:41:14 +0200 Subject: [PATCH 10/10] Oops, forgot a variable --- tests/functional/openlp_core_lib/test_projectordb.py | 1 + tests/interfaces/openlp_core_ui/test_projectorsourceform.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/functional/openlp_core_lib/test_projectordb.py b/tests/functional/openlp_core_lib/test_projectordb.py index 8243292d0..7a8a57d19 100644 --- a/tests/functional/openlp_core_lib/test_projectordb.py +++ b/tests/functional/openlp_core_lib/test_projectordb.py @@ -96,6 +96,7 @@ class TestProjectorDB(TestCase): """ self.projector.session.close() self.projector = None + retries = 0 while retries < 5: try: if os.path.exists(TEST_DB): diff --git a/tests/interfaces/openlp_core_ui/test_projectorsourceform.py b/tests/interfaces/openlp_core_ui/test_projectorsourceform.py index 3b08db149..93aeb4c0a 100644 --- a/tests/interfaces/openlp_core_ui/test_projectorsourceform.py +++ b/tests/interfaces/openlp_core_ui/test_projectorsourceform.py @@ -88,6 +88,7 @@ class ProjectorSourceFormTest(TestCase, TestMixin): self.projectordb.session.close() del(self.projectordb) del(self.projector) + retries = 0 while retries < 5: try: if os.path.exists(TEST_DB):