← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~raoul-snyman/openlp/fix-windows-tests into lp:openlp

 

Raoul Snyman has proposed merging lp:~raoul-snyman/openlp/fix-windows-tests into lp:openlp.

Commit message:
Fix the tests on Windows

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~raoul-snyman/openlp/fix-windows-tests/+merge/282811

Fix up the tests for Windows by retrying deleting the databases.

Add this to your merge proposal:
--------------------------------
lp:~raoul-snyman/openlp/fix-windows-tests (revision 2616)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1257/
[SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1181/
[SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1120/
[SUCCESS] https://ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/956/
[SUCCESS] https://ci.openlp.io/job/Branch-04b-Windows_Interface_Tests/548/
[SUCCESS] https://ci.openlp.io/job/Branch-05a-Code_Analysis/624/
[FAILURE] https://ci.openlp.io/job/Branch-05b-Test_Coverage/495/
-- 
Your team OpenLP Core is requested to review the proposed merge of lp:~raoul-snyman/openlp/fix-windows-tests into lp:openlp.
=== modified file 'tests/functional/openlp_core_lib/test_projectordb.py'
--- tests/functional/openlp_core_lib/test_projectordb.py	2016-01-09 16:50:08 +0000
+++ tests/functional/openlp_core_lib/test_projectordb.py	2016-01-15 20:27:15 +0000
@@ -87,8 +87,6 @@
         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,15 @@
         """
         self.projector.session.close()
         self.projector = None
+        retries = 0
+        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):
         """

=== modified file 'tests/functional/openlp_core_utils/test_db.py'
--- tests/functional/openlp_core_utils/test_db.py	2016-01-05 15:14:58 +0000
+++ tests/functional/openlp_core_utils/test_db.py	2016-01-15 20:27:15 +0000
@@ -22,14 +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
 
 
@@ -40,30 +43,41 @@
         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')
+        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)
 
     def tearDown(self):
         """
         Clean up
         """
-        shutil.rmtree(self.tmp_folder)
+        self.session.close()
+        self.session = None
+        gc.collect()
+        retries = 0
+        while retries < 5:
+            try:
+                if os.path.exists(self.tmp_folder):
+                    shutil.rmtree(self.tmp_folder)
+                break
+            except:
+                time.sleep(1)
+                retries += 1
 
     def delete_column_test(self):
         """
         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,18 +90,12 @@
         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
 

=== modified file 'tests/interfaces/openlp_core_ui/test_projectorsourceform.py'
--- tests/interfaces/openlp_core_ui/test_projectorsourceform.py	2016-01-07 21:36:43 +0000
+++ tests/interfaces/openlp_core_ui/test_projectorsourceform.py	2016-01-15 20:27:15 +0000
@@ -65,8 +65,6 @@
         """
         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,15 @@
         self.projectordb.session.close()
         del(self.projectordb)
         del(self.projector)
+        retries = 0
+        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):


References