From: Razvan Deaconescu Date: Mon, 22 Aug 2011 07:50:29 +0000 (+0300) Subject: ppf: Read test initialization/population script. X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=c7add1ffbcf97fc037878e911f509eea257f259b;p=cs-p2p-next.git ppf: Read test initialization/population script. --- diff --git a/ppf/new/tests/test_storage.py b/ppf/new/tests/test_storage.py index 45f6cc4..ef4b097 100644 --- a/ppf/new/tests/test_storage.py +++ b/ppf/new/tests/test_storage.py @@ -302,14 +302,15 @@ class SQLiteDatabaseAccessTest(unittest.TestCase): # Class specific variables. Initialized in setUp, used throughout tests. database = "test.db" sql_create_script = "p2p-log-sqlite.sql" + sql_init_script = "p2p-init-test.sql" expected_swarms_count = 0 - expected_btclients_count = 0 expected_sessions_count = 0 expected_statmsg_count = 0 expected_verbmsg_count = 0 def setUp(self): """ Create database file and instantiate objects. """ + # Create database file. Create tables and indices. # TODO: Check exceptions. sql_create_script_path = os.path.join(os.path.dirname(__file__), self.sql_create_script) @@ -318,20 +319,21 @@ class SQLiteDatabaseAccessTest(unittest.TestCase): ret = os.waitpid(p.pid, 0)[1] f.close() - conn = sqlite3.connect(self.database) - cursor = conn.cursor() + # Populate database. + # TODO: Check exceptions. + sql_init_script_path = os.path.join(os.path.dirname(__file__), + self.sql_init_script) + f = open(sql_init_script_path, 'r') + p = subprocess.Popen(["sqlite3", self.database], stdin=f) + ret = os.waitpid(p.pid, 0)[1] + f.close() - #cursor.executescript(sql_init_script) # Initialize to number of table entries inserted in the init script. self.expected_swarms_count = 2 - self.expected_btclients_count = 6 self.expected_sessions_count = 2 self.expected_statmsg_count = 2 self.expected_verbmsg_count = 2 - cursor.close() - conn.close() - def tearDown(self): """ Close connection and remove database file. """ os.remove(self.database)