ppf: Run creation script for SQLite tests.
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Mon, 22 Aug 2011 07:09:17 +0000 (10:09 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Mon, 22 Aug 2011 07:09:17 +0000 (10:09 +0300)
ppf/new/tests/test_storage.py

index e4ac937..45f6cc4 100644 (file)
@@ -9,6 +9,8 @@ import os
 import os.path
 import shutil
 import sqlite3
+import subprocess
+import sys
 
 import storage
 
@@ -299,9 +301,7 @@ class SQLiteDatabaseAccessTest(unittest.TestCase):
 
     # Class specific variables. Initialized in setUp, used throughout tests.
     database = "test.db"
-    dba = None
-    conn = None
-    cursor = None
+    sql_create_script = "p2p-log-sqlite.sql"
     expected_swarms_count = 0
     expected_btclients_count = 0
     expected_sessions_count = 0
@@ -310,10 +310,17 @@ class SQLiteDatabaseAccessTest(unittest.TestCase):
 
     def setUp(self):
         """ Create database file and instantiate objects. """
+        # TODO: Check exceptions.
+        sql_create_script_path = os.path.join(os.path.dirname(__file__),
+                self.sql_create_script)
+        f = open(sql_create_script_path, 'r')
+        p = subprocess.Popen(["sqlite3", self.database], stdin=f)
+        ret = os.waitpid(p.pid, 0)[1]
+        f.close()
+
         conn = sqlite3.connect(self.database)
         cursor = conn.cursor()
 
-        #cursor.executescript(sql_create_script)
         #cursor.executescript(sql_init_script)
         # Initialize to number of table entries inserted in the init script.
         self.expected_swarms_count = 2
@@ -325,12 +332,8 @@ class SQLiteDatabaseAccessTest(unittest.TestCase):
         cursor.close()
         conn.close()
 
-        self.dba = storage.SQLiteDatabaseAccess()
-        self.dba.connect(self.database)
-
     def tearDown(self):
         """ Close connection and remove database file. """
-        self.dba.disconnect()
         os.remove(self.database)
 
     def test_add_swarm_new_entry_in_table(self):