<commit_before># Copyright (c) 2016 <NAME>
# Copyright (c) 2013-2014 <NAME> <<EMAIL>> and other
# contributors
# See LICENSE.txt for details.

import unittest

from django.conf import settings
settings.configure(INSTALLED_APPS=["django_nvd3"])
import django
django.setup()
from django.template import Context, Template
from django.test.utils import override_settings
from django_nvd3.templatetags.nvd3_tags import load_chart, include_container


HEADER = u"""\
<link media="all" href="{css}" type="text/css" rel="stylesheet" />
<script src="{d3js}" type="text/javascript" charset="utf-8"></script>
<script src="{nvd3js}" type="text/javascript" charset="utf-8"></script>

"""

CONTAINER = """\
<div id="{name}"><svg style="width:{width};height:{height};"></svg></div>

"""


def render_template(string, context=None):
    context = context or {}
    context = Context(context)
    return Template(string).render(context)


class TestIncludeTag(unittest.TestCase):
    # Not only does this test the output of the template tag,
    # but also the order of including the static files - mainly
    # d3 and nvd3 js files which should be in that order.

    @override_settings(STATIC_URL='/static/')
    def test_custom_dirs(self):
        rendered = render_template(
            "{% load nvd3_tags %}"
            "{% include_chart_jscss css_dir='css' js_dir='js' %}"
        )
        expected = HEADER.format(css="/static/css/nv.d3.min.css",
                                 d3js="/static/js/d3.v3.min.js",
                                 nvd3js="/static/js/nv.d3.min.js")
        self.assertEqual(rendered, expected)

    @override_settings(STATIC_URL='/static/')
    def test_default_dirs(self):
        rendered = render_template(
            "{% load nvd3_tags %}"
            "{% include_chart_jscss %}"
        )
        expected = HEADER.format(css="/static/nv.d3.min.css",
                                 d3js="/static/d3.v3.min.js",
                                 nvd3js="/static/nv.d3.min.js")
        self.assertEqual(rendered, expected)


class TestIncludeContainer(unittest.TestCase):

    def test_defaults(self):
        name = "chart"
        rendered = include_container(name=name)
        expected = CONTAINER.format(name=name, height="400px", width="600px")
        self.assertEqual(rendered, expected)

    def test_custom_size(self):<commit_msg>Add test for custom static dir.<commit_after># Copyright (c) 2016 <NAME>
# Copyright (c) 2013-2014 <NAME> <<EMAIL>> and other
# contributors
# See LICENSE.txt for details.

import unittest

from django.conf import settings
settings.configure(INSTALLED_APPS=["django_nvd3"])
import django
django.setup()
from django.template import Context, Template
from django.test.utils import override_settings
from django_nvd3.templatetags.nvd3_tags import load_chart, include_container


HEADER = u"""\
<link media="all" href="{css}" type="text/css" rel="stylesheet" />
<script src="{d3js}" type="text/javascript" charset="utf-8"></script>
<script src="{nvd3js}" type="text/javascript" charset="utf-8"></script>

"""

CONTAINER = """\
<div id="{name}"><svg style="width:{width};height:{height};"></svg></div>

"""


def render_template(string, context=None):
    context = context or {}
    context = Context(context)
    return Template(string).render(context)


class TestIncludeTag(unittest.TestCase):
    # Not only does this test the output of the template tag,
    # but also the order of including the static files - mainly
    # d3 and nvd3 js files which should be in that order.

    @override_settings(STATIC_URL='/static/')
    def test_custom_dirs(self):
        rendered = render_template(
            "{% load nvd3_tags %}"
            "{% include_chart_jscss css_dir='css' js_dir='js' %}"
        )
        expected = HEADER.format(css="/static/css/nv.d3.min.css",
                                 d3js="/static/js/d3.v3.min.js",
                                 nvd3js="/static/js/nv.d3.min.js")
        self.assertEqual(rendered, expected)

    @override_settings(STATIC_URL='/static/')
    def test_default_dirs(self):
        rendered = render_template(
            "{% load nvd3_tags %}"
            "{% include_chart_jscss %}"
        )
        expected = HEADER.format(css="/static/nv.d3.min.css",
                                 d3js="/static/d3.v3.min.js",
                                 nvd3js="/static/nv.d3.min.js")
        self.assertEqual(rendered, expected)

    def test_static_dir(self):
        rendered = render_template(
            "{% load nvd3_tags %}"
            "{% include_chart_jscss '/s' %}"
        )
        expected = HEADER.format(css="/s/nv.d3.min.css",
                                 d3js="/s/d3.v3.min.js",
                                 nvd3js="/s/nv.d3.min.js")
        self.assertEqual(rendered, expected)


class TestIncludeContainer(unittest.TestCase):

    def test_defaults(self):
        name = "chart"
        rendered = include_container(name=name)
        expected = CONTAINER.format(name=name, height="400px", width="600px")
        self.assertEqual(rendered, expected)

    def test_custom_size(self):
{'fraction_non_alphanumeric': 0.13806552262090482, 'fraction_numerical': 0.01735569422776911, 'mean_word_length': 2.768552534900808, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1262638', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1553, 'n_words': 318}