<commit_before>""" Tests for rendering functions in the mako pipeline. """

from unittest import skipUnless

import ddt
from django.conf import settings
from django.test import TestCase
from paver.easy import call_task

from pipeline_mako import compressed_css, compressed_js, render_require_js_path_overrides


class RequireJSPathOverridesTest(TestCase):
    """Test RequireJS path overrides. """

    OVERRIDES = {
        'jquery': 'common/js/vendor/jquery.js',
        'backbone': 'common/js/vendor/backbone.js',
        'text': 'js/vendor/text.js'
    }

    OVERRIDES_JS = [
        "<script type=\"text/javascript\">",
        "(function (require) {",
        "require.config({",
        "paths: {",
        "'jquery': 'common/js/vendor/jquery',",
        "'text': 'js/vendor/text',",
        "'backbone': 'common/js/vendor/backbone'",
        "}",
        "});",
        "}).call(this, require || RequireJS.require);",
        "</script>"
    ]

    def test_requirejs_path_overrides(self):
        result = render_require_js_path_overrides(self.OVERRIDES)
        # To make the string comparision easy remove the whitespaces
        self.assertEqual(map(str.strip, result.splitlines()), self.OVERRIDES_JS)


@ddt.ddt
class PipelineRenderTest(TestCase):
    """Test individual pipeline rendering functions. """

    @classmethod
    def setUpClass(cls):
        """
        Create static assets once for all pipeline render tests.
        """
        super(PipelineRenderTest, cls).setUpClass()<commit_msg>Ensure npm install before static asset pipeline tests.<commit_after>""" Tests for rendering functions in the mako pipeline. """

from unittest import skipUnless

import ddt
import os
from django.conf import settings
from django.test import TestCase
from paver.easy import call_task

from pipeline_mako import compressed_css, compressed_js, render_require_js_path_overrides


class RequireJSPathOverridesTest(TestCase):
    """Test RequireJS path overrides. """

    OVERRIDES = {
        'jquery': 'common/js/vendor/jquery.js',
        'backbone': 'common/js/vendor/backbone.js',
        'text': 'js/vendor/text.js'
    }

    OVERRIDES_JS = [
        "<script type=\"text/javascript\">",
        "(function (require) {",
        "require.config({",
        "paths: {",
        "'jquery': 'common/js/vendor/jquery',",
        "'text': 'js/vendor/text',",
        "'backbone': 'common/js/vendor/backbone'",
        "}",
        "});",
        "}).call(this, require || RequireJS.require);",
        "</script>"
    ]

    def test_requirejs_path_overrides(self):
        result = render_require_js_path_overrides(self.OVERRIDES)
        # To make the string comparision easy remove the whitespaces
        self.assertEqual(map(str.strip, result.splitlines()), self.OVERRIDES_JS)


@ddt.ddt
class PipelineRenderTest(TestCase):
    """Test individual pipeline rendering functions. """

    @classmethod
    def setUpClass(cls):
        """
        Create static assets once for all pipeline render tests.
        """
        super(PipelineRenderTest, cls).setUpClass()
        # Ensure that the npm requirements are always installed before updating static assets.
        prereq_install_value_orig = os.environ.get('NO_PREREQ_INSTALL')
        os.environ['NO_PREREQ_INSTALL'] = 'False'
        try:
            call_task('pavelib.prereqs.install_node_prereqs')
        except:
            raise
        finally:
            if prereq_install_value_orig is None:
                del os.environ['NO_PREREQ_INSTALL']
            else:
                os.environ['NO_PREREQ_INSTALL'] = prereq_install_value_orig
        # Update all static assets.
{'fraction_non_alphanumeric': 0.120415982484948, 'fraction_numerical': 0.0, 'mean_word_length': 2.8841657810839534, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4621881', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1072, 'n_words': 244}