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)
def test_validate_jinja2_whitespace_markers_3(self) -> None: my_html = """ {% if foo %} this is foo {% endif -%} """ validate(text=my_html)
def test_validate_comment(self): # type: () -> None my_html = ''' <!--- <h1>foo</h1> -->''' validate(text=my_html)
def test_validate_handlebars(self) -> None: my_html = ''' {{#with stream}} <p>{{stream}}</p> {{/with}} ''' validate(text=my_html)
def test_validate_jinja2_whitespace_type2_markers(self) -> None: my_html = """ {%- if foo -%} this is foo {% endif %} """ validate(text=my_html)
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)
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)
def test_validate_handlebars(self): # type: () -> None my_html = ''' {{#with stream}} <p>{{stream}}</p> {{/with}} ''' validate(text=my_html)
def test_validate_django(self): # type: () -> None my_html = ''' {% include "some_other.html" %} {% if foo %} <p>bar</p> {% endif %} ''' validate(text=my_html)
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)
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)
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)
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)
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)
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)
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)
def pretty_print(html: str) -> str: fn = "<test str>" tokens = validate(fn=fn, text=html) return pretty_print_html(tokens, fn=fn)
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: 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)
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)