<commit_before>""" Test JSON serialization straw """

import unittest
from codejail.safe_exec import json_safe

class JsonSafeTest(unittest.TestCase):
    """ Test JSON serialization straw """

    # Unicode surrogate values
    SURROGATE_RANGE = range(55296, 57344)

    def test_unicode(self):
        """ Test that json_safe() handles non-surrogate unicode values """

        # Try a few non-ascii UTF-16 characters
        for unicode_char in [unichr(512), unichr(2**8-1), unichr(2**16-1)]:

            # Try it as a dictionary value
            result = json_safe({'test': unicode_char})
            self.assertEqual(result.get('test', None), unicode_char)

            # Try it as a dictionary key
            result = json_safe({unicode_char: 'test'})
            self.assertEqual(result.get(unicode_char, None), 'test')

    def test_surrogate_unicode_values(self):
        """ Test that json_safe() excludes surrogate unicode values """

        # Try surrogate unicode values
        for code in self.SURROGATE_RANGE:

            unicode_char = unichr(code)

            # Try it as a dictionary value
            result = json_safe({'test': unicode_char})
            self.assertFalse('test' in result)

    def test_surrogate_unicode_keys(self):
        """ Test that json_safe() excludes surrogate unicode keys """

        # Try surrogate unicode values
        for code in self.SURROGATE_RANGE:

            unicode_char = unichr(code)

            # Try it is a dictionary key
            result = json_safe({unicode_char: 'test'})
            self.assertFalse(unicode_char in result)<commit_msg>Style issue fixes<commit_after>"""
Test JSON serialization straw
"""

import unittest
from codejail.safe_exec import json_safe


class JsonSafeTest(unittest.TestCase):
    """
    Test JSON serialization straw
    """

    # Unicode surrogate values
    SURROGATE_RANGE = range(55296, 57344)

    def test_unicode(self):
        """
        Test that json_safe() handles non-surrogate unicode values
        """

        # Try a few non-ascii UTF-16 characters
        for unicode_char in [unichr(512), unichr(2**8-1), unichr(2**16-1)]:

            # Try it as a dictionary value
            result = json_safe({'test': unicode_char})
            self.assertEqual(result.get('test', None), unicode_char)

            # Try it as a dictionary key
            result = json_safe({unicode_char: 'test'})
            self.assertEqual(result.get(unicode_char, None), 'test')

    def test_surrogate_unicode_values(self):
        """
        Test that json_safe() excludes surrogate unicode values
        """

        # Try surrogate unicode values
        for code in self.SURROGATE_RANGE:

            unicode_char = unichr(code)

            # Try it as a dictionary value
            result = json_safe({'test': unicode_char})
            self.assertFalse('test' in result)

    def test_surrogate_unicode_keys(self):
        """
        Test that json_safe() excludes surrogate unicode keys
        """

        # Try surrogate unicode values
        for code in self.SURROGATE_RANGE:

            unicode_char = unichr(code)

            # Try it is a dictionary key
            result = json_safe({unicode_char: 'test'})
            self.assertFalse(unicode_char in result)
{'fraction_non_alphanumeric': 0.09419629292008508, 'fraction_numerical': 0.013369796414463689, 'mean_word_length': 2.450733752620545, 'pattern_counts': {'":': 0, '<': 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': '2740784', 'n_tokens_mistral': 1015, 'n_tokens_neox': 897, 'n_words': 261}