<commit_before># coding: utf-8
		
"""
This file is a helper to create test databases 
"""		
import MySQLdb
import logging

DATABASE_NAME = "test"

# database configuration object
config_connection = {
	"host": "localhost",
	"user": "root",
	"passwd": "<PASSWORD>"
}

cursor = None

def create_test_database():
	global cursor

	logging.info("trying to connect to the database %s" %DATABASE_NAME)
	cursor = MySQLdb.connect(**config_connection)

	logging.info("trying to create the database %s" %DATABASE_NAME)
	cursor.execute("CREATE DATABASE %s" %DATABASE_NAME)

def destroy_test_database():
	global cursor

	logging.info("trying to delete the database: %s" %DATABASE_NAME)
	cursor.execute("DROP DATABASE IF EXISTS %" %DATABASE_NAME)<commit_msg>criando arquivo para inicializar databases de teste<commit_after># coding: utf-8
		
"""
This file is a helper to create test databases 
"""		
import MySQLdb
import logging

DATABASE_NAME = "test"

# database configuration object
config_connection = {
	"host": "localhost",
	"user": "root",
	"passwd": "<PASSWORD>"
}


def connect_to_database_server():
	"""
	Connect to a database server, 
	using the config_connection dict
	:Return: a cursor to the connection or None
	"""
	logging.info("trying to connect to the server")
	cursor = MySQLdb.connect(**config_connection).cursor()
	return cursor

def create_test_database(cursor, name):
	"""
	Create a test database with the connection 
	represented by cursor and name represented by
	name. If the database already exists  then 
	the database is deleted and created again
	"""
	
	logging.info("trying to create the database %s" %name)
	try:
		cursor.execute("CREATE DATABASE %s" %name)
	except ProgrammingError:
		logging.info("database %s exists!" %name)
		destroy_test_database(name)
		cursor.execute("CREATE DATABASE %s" %name)

def destroy_test_database(cursor, name):
	"""
	Destroy the test database if the 
	database exists
	"""
	logging.info("trying to delete the database: %s" %name)
	cursor.execute("DROP DATABASE IF EXISTS %" %name)


if __name__ == '__main__':
	cursor = connect_to_database(DATABASE_NAME)
	if cursor is not None:
		create_test_database(cursor, DATABASE_NAME)
{'fraction_non_alphanumeric': 0.1065686724850712, 'fraction_numerical': 0.0009186954524575103, 'mean_word_length': 5.205128205128205, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5189966', 'n_tokens_mistral': 727, 'n_tokens_neox': 685, 'n_words': 222}