<commit_before>import json
import os
import unittest

from lib import database


class DatabaseTestCase(unittest.TestCase):
    def setUp(self):
        path = (
            os.path.join(
                os.path.abspath(
                    os.path.join(
                        os.path.dirname(os.path.realpath(__file__)),
                        os.pardir
                    )
                ),
                'config.json'
            )
        )
        settings = None
        with open(path, 'r') as file_:
            settings = json.load(file_)['options']['datasource']

        self.database = database.Database(settings)

    def test_connect(self):
        # Act
        self.database.connect()

        # Assert
        self.assertTrue(self.database._connection.is_connected())

    def test_disconnect(self):
        # Act
        self.database.connect()
        self.database.disconnect()

        # Assert
        self.assertFalse(self.database._connection.is_connected())

    def test_get_empty(self):
        # Arrange
        query = 'SELECT id, name FROM projects WHERE id = 111111111'
        expected = []

        # Act
        self.database.connect()
        actual = self.database.get(query)

        # Assert
        self.assertCountEqual(expected, actual)

    def test_get_single(self):
        # Arrange
        query = 'SELECT id, name FROM projects WHERE id = 1'
        expected = (1, 'ruote-kit')

        # Act<commit_msg>Using _connected property<commit_after>import json
import os
import unittest

from lib import database


class DatabaseTestCase(unittest.TestCase):
    def setUp(self):
        path = (
            os.path.join(
                os.path.abspath(
                    os.path.join(
                        os.path.dirname(os.path.realpath(__file__)),
                        os.pardir
                    )
                ),
                'config.json'
            )
        )
        settings = None
        with open(path, 'r') as file_:
            settings = json.load(file_)['options']['datasource']

        self.database = database.Database(settings)

    def test_connect(self):
        # Act
        self.database.connect()

        # Assert
        self.assertTrue(self.database._connected)

    def test_disconnect(self):
        # Act
        self.database.connect()
        self.database.disconnect()

        # Assert
        self.assertFalse(self.database._connected)

    def test_get_empty(self):
        # Arrange
        query = 'SELECT id, name FROM projects WHERE id = 111111111'
        expected = []

        # Act
        self.database.connect()
        actual = self.database.get(query)

        # Assert
        self.assertCountEqual(expected, actual)

    def test_get_single(self):
        # Arrange
        query = 'SELECT id, name FROM projects WHERE id = 1'
        expected = (1, 'ruote-kit')

        # Act
{'fraction_non_alphanumeric': 0.09799861973775018, 'fraction_numerical': 0.00759144237405107, 'mean_word_length': 1.6093609360936094, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '7622972', 'n_tokens_mistral': 820, 'n_tokens_neox': 763, 'n_words': 163}