<commit_before>import unittest

from draftjs_exporter.engines.string_compat import DOMStringCompat

S = DOMStringCompat


class TestDOMStringCompat(unittest.TestCase):
    def test_create_tag(self):
        self.assertEqual(
            S.render_debug(S.create_tag("p", {"class": "intro"})),
            '<p class="intro"></p>',
        )

    def test_create_tag_empty(self):
        self.assertEqual(S.render_debug(S.create_tag("p")), "<p></p>")

    def test_parse_html(self):
        self.assertEqual(
            S.render(S.parse_html("<p><span>Test text</span></p>")),
            "<p><span>Test text</span></p>",
        )

    def test_append_child(self):
        parent = S.create_tag("p")
        S.append_child(parent, S.create_tag("span", {}))
        self.assertEqual(S.render_debug(parent), "<p><span></span></p>")

    def test_append_child_identical_text(self):
        parent = S.create_tag("p")
        S.append_child(parent, S.parse_html("test"))
        S.append_child(parent, S.parse_html("test"))
        self.assertEqual(S.render_debug(parent), "<p>testtest</p>")

    def test_append_child_identical_elements(self):
        parent = S.create_tag("p")
        S.append_child(parent, S.create_tag("br"))
        S.append_child(parent, S.create_tag("br"))
        self.assertEqual(S.render_debug(parent), "<p><br/><br/></p>")

    def test_render_attrs_escaping(self):
        self.assertEqual(
            S.render_attrs(
                {"alt": "img's alt", "class": 'intro " text', "src": "src.png"}
            ),
            ' alt="img&#x27;s alt" class="intro &quot; text" src="src.png"',
        )

    def test_render_attrs_sorting(self):
        self.assertEqual(
            S.render_attrs(
                {
                    "class": 'intro " text',
                    "src": "src.png",
                    "alt": "img's alt",
                }
            ),
            ' alt="img&#x27;s alt" class="intro &quot; text" src="src.png"',
        )

    def test_render_children(self):
        self.assertEqual(
            S.render_children(
                [
                    "single ' quote",
                    S.create_tag("p", {"class": "intro"}),
                    'double " quote',
                ]
            ),
            'single &#x27; quote<p class="intro"></p>double &quot; quote',
        )

    def test_render(self):
        self.assertEqual(
            S.render_debug(S.create_tag("p", {"class": "intro"})),
            '<p class="intro"></p>',
        )

    def test_render_debug(self):
        self.assertEqual(
            S.render_debug(S.create_tag("p", {"class": "intro"})),
            '<p class="intro"></p>',
        )<commit_msg>Fix test coverage<commit_after>import unittest

from draftjs_exporter.engines.string_compat import DOMStringCompat

S = DOMStringCompat


class TestDOMStringCompat(unittest.TestCase):
    def test_create_tag(self):
        self.assertEqual(
            S.render_debug(S.create_tag("p", {"class": "intro"})),
            '<p class="intro"></p>',
        )

    def test_create_tag_empty(self):
        self.assertEqual(S.render_debug(S.create_tag("p")), "<p></p>")

    def test_parse_html(self):
        self.assertEqual(
            S.render(S.parse_html("<p><span>Test text</span></p>")),
            "<p><span>Test text</span></p>",
        )
        # There for test coverage only.
        self.assertEqual(
            S.render_debug(S.parse_html("<p><span>Test text</span></p>")),
            "<p><span>Test text</span></p>",
        )

    def test_append_child(self):
        parent = S.create_tag("p")
        S.append_child(parent, S.create_tag("span", {}))
        self.assertEqual(S.render_debug(parent), "<p><span></span></p>")

    def test_append_child_identical_text(self):
        parent = S.create_tag("p")
        S.append_child(parent, S.parse_html("test"))
        S.append_child(parent, S.parse_html("test"))
        self.assertEqual(S.render_debug(parent), "<p>testtest</p>")

    def test_append_child_identical_elements(self):
        parent = S.create_tag("p")
        S.append_child(parent, S.create_tag("br"))
        S.append_child(parent, S.create_tag("br"))
        self.assertEqual(S.render_debug(parent), "<p><br/><br/></p>")

    def test_render_attrs_escaping(self):
        self.assertEqual(
            S.render_attrs(
                {"alt": "img's alt", "class": 'intro " text', "src": "src.png"}
            ),
            ' alt="img&#x27;s alt" class="intro &quot; text" src="src.png"',
        )

    def test_render_attrs_sorting(self):
        self.assertEqual(
            S.render_attrs(
                {
                    "class": 'intro " text',
                    "src": "src.png",
                    "alt": "img's alt",
                }
            ),
            ' alt="img&#x27;s alt" class="intro &quot; text" src="src.png"',
        )

    def test_render_children(self):
        self.assertEqual(
            S.render_children(
                [
                    "single ' quote",
                    S.create_tag("p", {"class": "intro"}),
                    'double " quote',
                ]
            ),
            'single &#x27; quote<p class="intro"></p>double &quot; quote',
        )

    def test_render(self):
        self.assertEqual(
            S.render_debug(S.create_tag("p", {"class": "intro"})),
            '<p class="intro"></p>',
        )

    def test_render_debug(self):
        self.assertEqual(
            S.render_debug(S.create_tag("p", {"class": "intro"})),
            '<p class="intro"></p>',
        )
        # There for test coverage only.
        self.assertEqual(
            S.render_debug(S.create_tag("img", {"class": "intro"})),
            '<img class="intro"/>',
        )
{'fraction_non_alphanumeric': 0.1677330105481584, 'fraction_numerical': 0.0020750475531730937, 'mean_word_length': 2.0394114555964267, 'pattern_counts': {'":': 21, '<': 68, '<?xml version=': 0, '>': 68, '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': '5385467', 'n_tokens_mistral': 1844, 'n_tokens_neox': 1778, 'n_words': 275}