From d4cf29317b71a8b905226b6dd9a26db560ea7f98 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Mon, 22 Aug 2011 10:09:17 +0300 Subject: [PATCH] ppf: Run creation script for SQLite tests. --- ppf/new/tests/test_storage.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ppf/new/tests/test_storage.py b/ppf/new/tests/test_storage.py index e4ac937..45f6cc4 100644 --- a/ppf/new/tests/test_storage.py +++ b/ppf/new/tests/test_storage.py @@ -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): -- 2.20.1