<commit_before># unit tests
try:
    import unittest2 as unittest
except ImportError:
    import unittest

import mimerender

from mimerender import _MIME_TYPES


class TestMimeRender(mimerender.MimeRenderBase):
    def __init__(self, request_parameters=None, accept_header=None,
            *args, **kwargs):
        super(TestMimeRender, self).__init__(*args, **kwargs)
        self.request_parameters = request_parameters or {}
        self.accept_header = accept_header
        self.ctx = {}
        self.headers = {}

    def _get_request_parameter(self, key, default=None):
        return self.request_parameters.get(key, default)

    def _get_accept_header(self, default=None):
        return self.accept_header

    def _set_context_var(self, key, value):
        self.ctx[key] = value

    def _clear_context_var(self, key):
        del self.ctx[key]

    def _make_response(self, content, headers, status):
        self.status = status
        for k, v in headers:
            self.headers[k] = v
        return content


class MimeRenderTests(unittest.TestCase):
    def test_single_variant(self):
        mimerender = TestMimeRender()
        result = mimerender(
                xml=lambda x: '<xml>%s</xml>' % x,
            )(lambda: dict(x='test'))()
        self.assertEqual(mimerender.headers['Content-Type'], 'text/xml')
        self.assertEqual(result, '<xml>test</xml>')

    def test_norenderers(self):<commit_msg>test both set and unknown default mime category<commit_after># unit tests
try:
    import unittest2 as unittest
except ImportError:
    import unittest

import mimerender

from mimerender import _MIME_TYPES


class TestMimeRender(mimerender.MimeRenderBase):
    def __init__(self, request_parameters=None, accept_header=None,
            *args, **kwargs):
        super(TestMimeRender, self).__init__(*args, **kwargs)
        self.request_parameters = request_parameters or {}
        self.accept_header = accept_header
        self.ctx = {}
        self.headers = {}

    def _get_request_parameter(self, key, default=None):
        return self.request_parameters.get(key, default)

    def _get_accept_header(self, default=None):
        return self.accept_header

    def _set_context_var(self, key, value):
        self.ctx[key] = value

    def _clear_context_var(self, key):
        del self.ctx[key]

    def _make_response(self, content, headers, status):
        self.status = status
        for k, v in headers:
            self.headers[k] = v
        return content


class MimeRenderTests(unittest.TestCase):
    def test_single_variant_without_default(self):
        mimerender = TestMimeRender()
        result = mimerender(
                xml=lambda x: '<xml>%s</xml>' % x,
            )(lambda: dict(x='test'))()
        self.assertEqual(mimerender.headers['Content-Type'], 'text/xml')
        self.assertEqual(result, '<xml>test</xml>')

    def test_single_variant_with_default(self):
        mimerender = TestMimeRender()
        result = mimerender(
                xml=lambda x: '<xml>%s</xml>' % x,
                default='xml'
            )(lambda: dict(x='test'))()
        self.assertEqual(mimerender.headers['Content-Type'], 'text/xml')
        self.assertEqual(result, '<xml>test</xml>')

    def test_norenderers(self):
{'fraction_non_alphanumeric': 0.11199026171637248, 'fraction_numerical': 0.0006086427267194157, 'mean_word_length': 2.9318181818181817, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 19}, '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': '5846388', 'n_tokens_mistral': 999, 'n_tokens_neox': 971, 'n_words': 213}