wheezy.html / src / wheezy / html / ext / tests /

""" Unit tests for ``wheezy.html.ext.mako``.

import unittest

from wheezy.html.ext.tests.test_lexer import PreprocessorMixin

class TemplatePreprocessorTestCase(PreprocessorMixin, unittest.TestCase):
    """ Test the ``MakoPreprocessor``.

    def assert_render_equal(self, template, expected, **kwargs):
        assert_template_equal(template, expected, **kwargs)

    HIDDEN = '@model.pref.hidden()!h'
    MULTIPLE_HIDDEN = '@model.prefs.multiple_hidden()'
    LABEL = "@model.username.label('<i>*</i>Username:')"
    EMPTYBOX = "@model.amount.emptybox(class_='x')!s"
    TEXTBOX = "@model.username.textbox(autocomplete='off')"
    PASSWORD = "@model.pwd.password()"
    TEXTAREA = "@model.comment.textarea()"
    CHECKBOX = "@model.remember_me.checkbox()"
    MULTIPLE_CHECKBOX = "@model.scm.multiple_checkbox(choices=scm)"
    RADIO = ""
    DROPDOWN = "@model.scm.dropdown(choices=scm)"
    LISTBOX = "@model.scm.listbox(choices=scm, class_='x')"
    ERROR = "@model.username.error()"
    GENERAL_ERROR = "@model.error()"
    INFO = ""
    WARNING = "@model.user_info.warning()"
    GENERAL_WARNING = "@message.warning()"

class WheezyWhitespaceExtensionTestCase(unittest.TestCase):
    """ Test the ``WhitespaceExtension``.

    def setUp(self):
        from wheezy.html.ext.template import WhitespaceExtension
        from wheezy.html.ext.template import whitespace_preprocessor
        whitespace_preprocessor1 = WhitespaceExtension.preprocessors[0]
        self.preprocess = lambda text: whitespace_preprocessor(

    def test_whitespace(self):
        assert '><' == self.preprocess('  >  < ')
        assert '' == self.preprocess('  ')
        assert 'x' == self.preprocess('  x')
        assert 'x' == self.preprocess('x  ')
        assert '<code>\n 1\n 2 </code>' == self.preprocess(
            '  <code> \n 1 \n 2 </code> ')
        assert '<pre>\n </pre>' == self.preprocess('  <pre> \n </pre> ')

    from wheezy.html.ext.template import WidgetExtension
    from wheezy.html.utils import html_escape
    from wheezy.template.engine import Engine
    from wheezy.template.ext.core import CoreExtension
    from wheezy.template.loader import DictLoader

    def assert_template_equal(text, expected, **kwargs):
        engine = Engine(
                'x': "@require(model, errors, message, scm)\n" + text}),
            extensions=[CoreExtension(), WidgetExtension()])
        engine.global_vars.update({'h': html_escape})
        value = engine.render('x', kwargs, {}, {})
        assert expected == value

except ImportError:  # pragma: nocover

    def assert_template_equal(text, expected, **kwargs):  # noqa
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.