def test_file_gets_created_on_connect():
    filename = absolute_filename('test.db')
    db = SQLiteDB(filename)
    db._get_connection()
    assert_true(os.path.exists(filename))
    db.close()
    delete_file(filename)
def test_connection_is_singleton():
    filename = absolute_filename('test.db')
    db = SQLiteDB(filename)
    c1 = db._get_connection()
    c2 = db._get_connection()
    assert_true(c1 is c2)
    assert_equal(c1, c2)
    db.close()
    delete_file(filename)
def test_each_thread_has_its_own_connection():
    filename = absolute_filename('test.db')
    db = SQLiteDB(filename)
    connection1 = db._get_connection()

    def other_thread():
        connection2 = db._get_connection()
        assert_true(connection1 is connection1)
        assert_false(connection2 is connection1)
        assert_equal(connection1, connection1)
        assert_not_equal(connection2, connection1)
        db.close()

    try:
        t1 = threading.Thread(target=other_thread)
        t1.start()
        t1.join()
    finally:
        db.close()
        delete_file(filename)