<commit_before>from testcontainers_python import config
from testcontainers_python.docker_client import DockerClient


class MySqlContainer(object):
    def __init__(self, image='mysql:latest'):
        self._docker = DockerClient()
        self.image = image
        self._containers = []

    def __enter__(self):
        return self.start()

    def __exit__(self, type, value, traceback):
        self.stop()

    def start(self):
        """
        Start my sql container and wait to be ready
        :return:
        """
        mysql = self._docker.run(self.image, bind_ports={3306: 3306},
                                 env={"MYSQL_ROOT_PASSWORD": config.my_sql_root_password})
        self._containers.append(mysql)

    def stop(self):
        """
        Stop all spawned containers
        :return:
        """
        for cont in self._containers:
            self._docker.remove(cont, True)<commit_msg> MySql container added<commit_after>from time import sleep

from testcontainers_python import config
from testcontainers_python.brogress_bar import ConsoleProgressBar
from testcontainers_python.docker_client import DockerClient
import MySQLdb

from testcontainers_python.exceptions import TimeoutException


class MySqlContainer(object):
    def __init__(self, image='mysql:latest'):
        self._docker = DockerClient()
        self.image = image
        self._containers = []
        self._connection = None

    def __enter__(self):
        return self.start()

    def __exit__(self, type, value, traceback):
        self.stop()

    def start(self):
        """
        Start my sql container and wait to be ready
        :return:
        """
        mysql = self._docker.run(self.image, bind_ports={3306: 3306},
                                 env={"MYSQL_ROOT_PASSWORD": config.my_sql_root_password})
        self._containers.append(mysql)
        self._connection = self._wait_for_container_to_start(mysql)
        return self

    def _wait_for_container_to_start(self, container):
        hub_info = self._docker.port(container, 3306)[0]
        bar = ConsoleProgressBar().bar
        for _ in bar(range(0, config.max_tries)):
            try:
                return MySQLdb.connect(host=hub_info['HostIp'],  # your host, usually localhost
                                       user="root",  # your username
                                       passwd=config.my_sql_root_password,  # your password
                                       db="test")
            except Exception:
                sleep(config.sleep_time)
        raise TimeoutException("Wait time exceeded {} sec.".format(config.max_tries))

    def stop(self):
        """
        Stop all spawned containers
        :return:
        """
        self._connection.close()
        for cont in self._containers:
            self._docker.remove(cont, True)

    def get_connection(self):
        return self._connection
{'fraction_non_alphanumeric': 0.09025394646533974, 'fraction_numerical': 0.0075497597803706245, 'mean_word_length': 2.1892778993435447, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4377090', 'n_tokens_mistral': 810, 'n_tokens_neox': 763, 'n_words': 181}