<commit_before>"""Tests for the templates"""
from django.test import TestCase
from django.template.loader import render_to_string


class TestTemplates(TestCase):
    """TestCase for templates"""

    def test_concept_card(self):
        """test the concept_card template"""
        # no code and no comment
        rendered_template_1 = render_to_string("concept_card.html", {}).strip()
        self.assertEqual(
            rendered_template_1,
            "<div class=\"card\">\n"
            "    <div class=\"card-body\">\n"
            "    \n"
            "    \n"
            "    </div>\n"
            "</div>"
        )

        # code (marked as safe), no comment
        rendered_template_2 = render_to_string(
            "concept_card.html", {"code": "<b>I am bold!</b>"}
        ).strip()
        self.assertEqual(
            rendered_template_2,
            "<div class=\"card\">\n"
            "    <div class=\"card-body\">\n"
            "    \n"
            "        <div class=\"syntax\"><b>I am bold!</b></div>\n"
            "    \n"
            "    \n"
            "    </div>\n"
            "</div>"
        )

        # no code, comment (with markdown format)
        rendered_template_3 = render_to_string(
            "concept_card.html", {"comment": "I am **bold** and *italic*, `let x = 1`."}
        ).strip()
        self.assertEqual(
            rendered_template_3,
            "<div class=\"card\">\n"
            "    <div class=\"card-body\">\n"
            "    \n"
            "    \n"
            "        <div>\n"
            "            I am <strong>bold</strong> and <em>italic</em>, <code>let x = 1</code>.\n"
            "        </div>\n"
            "    \n"
            "    </div>\n"
            "</div>"
        )

        # code and comment
        rendered_template_4 = render_to_string(
            "concept_card.html",
            {
                "code": "<b>I am bold!</b>",
                "comment": "I am **bold** and *italic*, `let x = 1`."
            }
        ).strip()
        self.assertEqual(
            rendered_template_4,
            "<div class=\"card\">\n"
            "    <div class=\"card-body\">\n"
            "    \n"
            "        <div class=\"syntax\"><b>I am bold!</b></div>\n"
            "    \n"
            "    \n"
            "        <div>\n"
            "            I am <strong>bold</strong> and <em>italic</em>, <code>let x = 1</code>.\n"
            "        </div>\n"
            "    \n"
            "    </div>\n"
            "</div>"
        )

        # md url in comment
        rendered_template_5 = render_to_string(
            "concept_card.html",
            {
                "comment": "I am a [url](http://url.com), I am not a url.py"
            }
        ).strip()
        self.assertEqual(
            rendered_template_5,
            "<div class=\"card\">\n"
            "    <div class=\"card-body\">\n"
            "    \n"
            "    \n"
            "        <div>\n"
            "            I am a <a href=\"http://url.com\">url</a>, I am not a url.py\n"
            "        </div>\n"
            "    \n"
            "    </div>\n"
            "</div>"<commit_msg>Fix PR #384's failing tests + merge with newer tests<commit_after>from django.test import TestCase
from django.template.loader import render_to_string


class TestTemplates(TestCase):
    """TestCase for templates"""

    def test_concept_card(self):
        """test the concept_card template"""
        # no code and no comment
        rendered_template_1 = render_to_string("concept_card.html", {}).strip()
        self.assertEqual(
            rendered_template_1,
            "<div class=\"card\">\n"
            "    <div class=\"card-body\">\n"
            "    \n"
            "    \n"
            "    </div>\n"
            "</div>"
        )

        # code (marked as safe), no comment
        rendered_template_2 = render_to_string(
            "concept_card.html", {"code": "<b>I am bold!</b>"}
        ).strip()
        self.assertEqual(
            rendered_template_2,
            "<div class=\"card\">\n"
            "    <div class=\"card-body\">\n"
            "    \n"
            "        <div class=\"syntax\"><b>I am bold!</b></div>\n"
            "    \n"
            "    \n"
            "    </div>\n"
            "</div>"
        )

        # no code, comment (with markdown format)
        rendered_template_3 = render_to_string(
            "concept_card.html", {"comment": "I am **bold** and *italic*, `let x = 1`."}
        ).strip()
        self.assertEqual(
            rendered_template_3,
            "<div class=\"card\">\n"
            "    <div class=\"card-body\">\n"
            "    \n"
            "    \n"
            "        <div>\n"
            "            I am <strong>bold</strong> and <em>italic</em>, <code>let x = 1</code>.\n"
            "        </div>\n"
            "    \n"
            "    </div>\n"
            "</div>"
        )

        # code and comment
        rendered_template_4 = render_to_string(
            "concept_card.html",
            {
                "code": "<b>I am bold!</b>",
                "comment": "I am **bold** and *italic*, `let x = 1`."
            }
        ).strip()
        self.assertEqual(
            rendered_template_4,
            "<div class=\"card\">\n"
            "    <div class=\"card-body\">\n"
            "    \n"
            "        <div class=\"syntax\"><b>I am bold!</b></div>\n"
            "    \n"
            "    \n"
            "        <div>\n"
            "            I am <strong>bold</strong> and <em>italic</em>, <code>let x = 1</code>.\n"
            "        </div>\n"
            "    \n"
            "    </div>\n"
            "</div>"
        )

        # no code and comment (multiple lines)
        rendered_template_5 = render_to_string(
            "concept_card.html",
            {
                "code": "",
                "comment": "I am a humble\nmulti-line comment in the\nform of a haiku"
            }
        ).strip()
        self.assertEquals(
            rendered_template_5,
            "<div class=\"card\">\n"
            "    <div class=\"card-body\">\n"
            "    \n"
            "    \n"
            "        <div>\n"
            "            I am a humble<br>multi-line comment in the<br>form of a haiku\n"
            "        </div>\n"
            "    \n"
            "    </div>\n"
            "</div>"
        )

        # Markdown url in comment
        rendered_template_6 = render_to_string(
            "concept_card.html",
            {
                "comment": "I am a [url](http://url.com), I am not a url.py"
            }
        ).strip()
        self.assertEqual(
            rendered_template_6,
            "<div class=\"card\">\n"
            "    <div class=\"card-body\">\n"
            "    \n"
            "    \n"
            "        <div>\n"
            "            I am a <a href=\"http://url.com\">url</a>, I am not a url.py\n"
            "        </div>\n"
            "    \n"
            "    </div>\n"
            "</div>"
{'fraction_non_alphanumeric': 0.16071930317504918, 'fraction_numerical': 0.004636133745434111, 'mean_word_length': 1.1012396694214877, 'pattern_counts': {'":': 12, '<': 115, '<?xml version=': 0, '>': 115, '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': '2239249', 'n_tokens_mistral': 2170, 'n_tokens_neox': 2151, 'n_words': 442}