<commit_before>import unittest

from . import utils


def _mock_request(*args, **kwargs):
    return {"status": "200"}, b"OK"


class MiscTests(unittest.TestCase):

    def setUp(self):
        utils.http.request = _mock_request
        pass

    def test_boundary(self):
        bound = utils._generate_boundary()
        self.assertIsNotNone(bound)

    def test_get_data(self):
        content = utils._get_data("url")
        self.assertEqual(content, "OK")

    def test_post_data(self):
        content = utils._post_data("url", "123")
        self.assertEqual(content, "OK")

    def test_delete_data(self):
        content = utils._delete_data("url")
        self.assertTrue(content)

    def test_file_encode_multipart(self):
        import os
        with open(__file__, "rb") as file_stream:
            content_type, body = utils._file_encode_multipart(
                os.path.basename(__file__),
                file_stream)
            self.assertIsNotNone(content_type)
            m = content_type.split(";")[0].strip()
            self.assertEqual(m, "multipart/form-data")<commit_msg>and another tests<commit_after>import unittest

from . import utils


def _mock_request(*args, **kwargs):
    return {"status": "200"}, b"OK"


def _mock_bad_request(*args, **kwargs):
    return {"status": "400"}, b"ERROR"


def _mock_exception_request(*args, **kwargs):
    raise Exception
    return {"status": "200"}, b"OK"


class MiscTests(unittest.TestCase):

    def setUp(self):
        utils.http.request = _mock_request
        pass

    def test_boundary(self):
        bound = utils._generate_boundary()
        self.assertIsNotNone(bound)

    def test_get_data(self):
        content = utils._get_data("url")
        self.assertEqual(content, "OK")

    def test_post_data(self):
        content = utils._post_data("url", "123")
        self.assertEqual(content, "OK")

    def test_delete_data(self):
        content = utils._delete_data("url")
        self.assertTrue(content)

    def test_file_encode_multipart(self):
        import os
        with open(__file__, "rb") as file_stream:
            content_type, body = utils._file_encode_multipart(
                os.path.basename(__file__),
                file_stream)
            self.assertIsNotNone(content_type)
            m = content_type.split(";")[0].strip()
            self.assertEqual(m, "multipart/form-data")


class ExMiscTests(unittest.TestCase):

    def setUp(self):
        utils.http.request = _mock_exception_request

    def test_get_data(self):
        self.assertRaises(Exception, utils._get_data, "url")

    def test_post_data(self):
        self.assertRaises(Exception, utils._post_data, ("url", "a"))


class BadMiscTests(unittest.TestCase):

    def setUp(self):
        utils.http.request = _mock_bad_request

    def test_delete_data(self):
        content = utils._delete_data("url")
        self.assertFalse(content)
{'fraction_non_alphanumeric': 0.11943874058863792, 'fraction_numerical': 0.006844626967830253, 'mean_word_length': 2.8309305373525557, 'pattern_counts': {'":': 4, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6461995', 'n_tokens_mistral': 921, 'n_tokens_neox': 892, 'n_words': 167}