# 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)
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)