Example #1
0
 def _assert_validate_error(self,
                            error: str,
                            fn: Optional[str] = None,
                            text: Optional[str] = None,
                            check_indent: bool = True) -> None:
     with self.assertRaisesRegex(TemplateParserException, error):
         validate(fn=fn, text=text, check_indent=check_indent)
Example #2
0
 def test_validate_jinja2_whitespace_markers_3(self) -> None:
     my_html = """
     {% if foo %}
     this is foo
     {% endif -%}
     """
     validate(text=my_html)
Example #3
0
 def test_validate_comment(self):
     # type: () -> None
     my_html = '''
         <!---
             <h1>foo</h1>
         -->'''
     validate(text=my_html)
Example #4
0
 def test_validate_handlebars(self) -> None:
     my_html = '''
         {{#with stream}}
             <p>{{stream}}</p>
         {{/with}}
         '''
     validate(text=my_html)
 def test_validate_comment(self):
     # type: () -> None
     my_html = '''
         <!---
             <h1>foo</h1>
         -->'''
     validate(text=my_html)
Example #6
0
 def test_validate_jinja2_whitespace_type2_markers(self) -> None:
     my_html = """
     {%- if foo -%}
     this is foo
     {% endif %}
     """
     validate(text=my_html)
Example #7
0
 def test_validate_handlebars(self) -> None:
     my_html = """
         {{#with stream}}
             <p>{{stream}}</p>
         {{/with}}
         """
     validate(text=my_html)
 def test_validate_jinja2_whitespace_markers_4(self) -> None:
     my_html = '''
     {%- if foo %}
     this is foo
     {% endif %}
     '''
     validate(text=my_html)
Example #9
0
 def _assert_validate_error(self,
                            error,
                            fn=None,
                            text=None,
                            check_indent=True):
     # type: (str, Optional[str], Optional[str], bool) -> None
     with self.assertRaisesRegex(TemplateParserException, error):
         validate(fn=fn, text=text, check_indent=check_indent)
 def _assert_validate_error(
     self,
     error: str,
     fn: Optional[str] = None,
     text: Optional[str] = None,
 ) -> None:
     with self.assertRaisesRegex(TemplateParserException, error):
         validate(fn=fn, text=text)
Example #11
0
 def test_validate_handlebars(self):
     # type: () -> None
     my_html = '''
         {{#with stream}}
             <p>{{stream}}</p>
         {{/with}}
         '''
     validate(text=my_html)
Example #12
0
 def test_validate_django(self):
     # type: () -> None
     my_html = '''
         {% include "some_other.html" %}
         {% if foo %}
             <p>bar</p>
         {% endif %}
         '''
     validate(text=my_html)
Example #13
0
 def test_validate_vanilla_html(self) -> None:
     '''
     Verify that validate() does not raise errors for
     well-formed HTML.
     '''
     my_html = '''
         <table>
             <tr>
             <td>foo</td>
             </tr>
         </table>'''
     validate(text=my_html)
Example #14
0
 def test_validate_vanilla_html(self) -> None:
     '''
     Verify that validate() does not raise errors for
     well-formed HTML.
     '''
     my_html = '''
         <table>
             <tr>
             <td>foo</td>
             </tr>
         </table>'''
     validate(text=my_html)
Example #15
0
 def test_validate_vanilla_html(self) -> None:
     """
     Verify that validate() does not raise errors for
     well-formed HTML.
     """
     my_html = """
         <table>
             <tr>
             <td>foo</td>
             </tr>
         </table>"""
     validate(text=my_html)
Example #16
0
    def test_validate_django(self) -> None:
        my_html = '''
            {% include "some_other.html" %}
            {% if foo %}
                <p>bar</p>
            {% endif %}
            '''
        validate(text=my_html)

        my_html = '''
            {% block "content" %}
                {% with className="class" %}
                {% include 'foobar' %}
                {% endwith %}
            {% endblock %}
            '''
        validate(text=my_html)
Example #17
0
    def test_validate_django(self) -> None:
        my_html = """
            {% include "some_other.html" %}
            {% if foo %}
                <p>bar</p>
            {% endif %}
            """
        validate(text=my_html)

        my_html = """
            {% block "content" %}
                {% with className="class" %}
                {% include 'foobar' %}
                {% endwith %}
            {% endblock %}
            """
        validate(text=my_html)
Example #18
0
    def test_code_blocks(self) -> None:

        # This is fine.
        my_html = '''
            <code>
                x = 5
                y = x + 1
            </code>'''
        validate(text=my_html)

        # This is also fine.
        my_html = "<code>process_widgets()</code>"
        validate(text=my_html)

        # This is illegal.
        my_html = '''
            <code>x =
            5</code>
            '''
        self._assert_validate_error('Code tag is split across two lines.', text=my_html)
Example #19
0
    def test_code_blocks(self) -> None:

        # This is fine.
        my_html = '''
            <code>
                x = 5
                y = x + 1
            </code>'''
        validate(text=my_html)

        # This is also fine.
        my_html = "<code>process_widgets()</code>"
        validate(text=my_html)

        # This is illegal.
        my_html = '''
            <code>x =
            5</code>
            '''
        self._assert_validate_error('Code tag is split across two lines.', text=my_html)
Example #20
0
    def test_anchor_blocks(self) -> None:

        # This is allowed, although strange.
        my_html = """
            <a hef="/some/url">
            Click here
            for more info.
            </a>"""
        validate(text=my_html)

        # This is fine.
        my_html = '<a href="/some/url">click here</a>'
        validate(text=my_html)

        # Even this is fine.
        my_html = """
            <a class="twitter-timeline" href="https://twitter.com/ZulipStatus"
                data-widget-id="443457763394334720"
                data-screen-name="ZulipStatus"
                >@ZulipStatus on Twitter</a>.
            """
        validate(text=my_html)
Example #21
0
    def test_anchor_blocks(self) -> None:

        # This is allowed, although strange.
        my_html = '''
            <a hef="/some/url">
            Click here
            for more info.
            </a>'''
        validate(text=my_html)

        # This is fine.
        my_html = '<a href="/some/url">click here</a>'
        validate(text=my_html)

        # Even this is fine.
        my_html = '''
            <a class="twitter-timeline" href="https://twitter.com/ZulipStatus"
                data-widget-id="443457763394334720"
                data-screen-name="ZulipStatus"
                >@ZulipStatus on Twitter</a>.
            '''
        validate(text=my_html)
Example #22
0
def pretty_print(html: str) -> str:
    fn = "<test str>"
    tokens = validate(fn=fn, text=html)
    return pretty_print_html(tokens, fn=fn)
Example #23
0
 def test_validate_comment(self) -> None:
     my_html = """
         <!---
             <h1>foo</h1>
         -->"""
     validate(text=my_html)
def pretty_print(html: str) -> str:
    tokens = validate(fn=None, text=html)
    return pretty_print_html(html, tokens)
 def _assert_validate_error(self, error, fn=None, text=None, check_indent=True):
     # type: (str, Optional[str], Optional[str], bool) -> None
     with self.assertRaisesRegex(TemplateParserException, error):
         validate(fn=fn, text=text, check_indent=check_indent)
Example #26
0
 def _assert_validate_error(self, error: str, fn: Optional[str]=None,
                            text: Optional[str]=None, check_indent: bool=True) -> None:
     with self.assertRaisesRegex(TemplateParserException, error):
         validate(fn=fn, text=text, check_indent=check_indent)
Example #27
0
 def _assert_validate_error(self, error, fn=None, text=None, check_indent=True):
     # type: (str, Optional[str], Optional[str], bool) -> None
     with self.assertRaisesRegexp(TemplateParserException, error): # type: ignore # See https://github.com/python/typeshed/issues/372
         validate(fn=fn, text=text, check_indent=check_indent)