<commit_before>from unittest import TestCase
import json

from is_valid import Explanation


class ExplanationTest(TestCase):

    def setUp(self):
        self.explanation = Explanation(
            True, 'code', 'message', 'details'
        )

    def test_str(self):
        self.assertEqual(str(self.explanation), 'code: message')

    def test_dict(self):
        self.assertEqual(self.explanation.dict(), dict(
            code='code', message='message', details='details',
        ))

    def test_dict_including_valid(self):
        self.assertEqual(self.explanation.dict(include_valid=True), dict(
            valid=True, code='code', message='message', details='details',
        ))

    def test_json(self):
        self.assertEqual(self.explanation.json(), json.dumps(dict(
            code='code', message='message', details='details',
        )))

    def test_dict_advanced(self):
        self.maxDiff = None
        base = dict(valid=True, code='code', message='message')
        explanation = Explanation(<commit_msg>Fixed test that would sometimes fail due to dict ordering.<commit_after>from unittest import TestCase
import json

from is_valid import Explanation


class ExplanationTest(TestCase):

    def setUp(self):
        self.explanation = Explanation(
            True, 'code', 'message', 'details'
        )

    def test_str(self):
        self.assertEqual(str(self.explanation), 'code: message')

    def test_dict(self):
        self.assertEqual(self.explanation.dict(), dict(
            code='code', message='message', details='details',
        ))

    def test_dict_including_valid(self):
        self.assertEqual(self.explanation.dict(include_valid=True), dict(
            valid=True, code='code', message='message', details='details',
        ))

    def test_json(self):
        self.assertEqual(json.loads(self.explanation.json()), dict(
            code='code', message='message', details='details',
        ))

    def test_dict_advanced(self):
        self.maxDiff = None
        base = dict(valid=True, code='code', message='message')
        explanation = Explanation(
{'fraction_non_alphanumeric': 0.1282536677709418, 'fraction_numerical': 0.0, 'mean_word_length': 3.057581573896353, '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': '5799996', 'n_tokens_mistral': 607, 'n_tokens_neox': 574, 'n_words': 122}