mirror of
https://github.com/zulip/zulip.git
synced 2025-11-17 04:12:02 +00:00
python: Normalize quotes with Black.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
11741543da
commit
6e4c3e41dc
@@ -10,7 +10,7 @@ try:
|
||||
validate,
|
||||
)
|
||||
except ImportError:
|
||||
print('ERROR!!! You need to run this via tools/test-tools.')
|
||||
print("ERROR!!! You need to run this via tools/test-tools.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@@ -26,85 +26,85 @@ class ParserTest(unittest.TestCase):
|
||||
validate(fn=fn, text=text, check_indent=check_indent)
|
||||
|
||||
def test_is_django_block_tag(self) -> None:
|
||||
self.assertTrue(is_django_block_tag('block'))
|
||||
self.assertFalse(is_django_block_tag('not a django tag'))
|
||||
self.assertTrue(is_django_block_tag("block"))
|
||||
self.assertFalse(is_django_block_tag("not a django tag"))
|
||||
|
||||
def test_validate_vanilla_html(self) -> None:
|
||||
"""
|
||||
Verify that validate() does not raise errors for
|
||||
well-formed HTML.
|
||||
"""
|
||||
my_html = '''
|
||||
my_html = """
|
||||
<table>
|
||||
<tr>
|
||||
<td>foo</td>
|
||||
</tr>
|
||||
</table>'''
|
||||
</table>"""
|
||||
validate(text=my_html)
|
||||
|
||||
def test_validate_handlebars(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
{{#with stream}}
|
||||
<p>{{stream}}</p>
|
||||
{{/with}}
|
||||
'''
|
||||
"""
|
||||
validate(text=my_html)
|
||||
|
||||
def test_validate_comment(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
<!---
|
||||
<h1>foo</h1>
|
||||
-->'''
|
||||
-->"""
|
||||
validate(text=my_html)
|
||||
|
||||
def test_validate_django(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
{% include "some_other.html" %}
|
||||
{% if foo %}
|
||||
<p>bar</p>
|
||||
{% endif %}
|
||||
'''
|
||||
"""
|
||||
validate(text=my_html)
|
||||
|
||||
my_html = '''
|
||||
my_html = """
|
||||
{% block "content" %}
|
||||
{% with className="class" %}
|
||||
{% include 'foobar' %}
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
'''
|
||||
"""
|
||||
validate(text=my_html)
|
||||
|
||||
def test_validate_no_start_tag(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
foo</p>
|
||||
'''
|
||||
self._assert_validate_error('No start tag', text=my_html)
|
||||
"""
|
||||
self._assert_validate_error("No start tag", text=my_html)
|
||||
|
||||
def test_validate_mismatched_tag(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
<b>foo</i>
|
||||
'''
|
||||
self._assert_validate_error('Mismatched tag.', text=my_html)
|
||||
"""
|
||||
self._assert_validate_error("Mismatched tag.", text=my_html)
|
||||
|
||||
def test_validate_bad_indentation(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
<p>
|
||||
foo
|
||||
</p>
|
||||
'''
|
||||
self._assert_validate_error('Bad indentation.', text=my_html, check_indent=True)
|
||||
"""
|
||||
self._assert_validate_error("Bad indentation.", text=my_html, check_indent=True)
|
||||
|
||||
def test_validate_state_depth(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
<b>
|
||||
'''
|
||||
self._assert_validate_error('Missing end tag', text=my_html)
|
||||
"""
|
||||
self._assert_validate_error("Missing end tag", text=my_html)
|
||||
|
||||
def test_validate_incomplete_handlebars_tag_1(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
{{# foo
|
||||
'''
|
||||
"""
|
||||
self._assert_validate_error(
|
||||
'''Tag missing "}}" at Line 2 Col 13:"{{# foo
|
||||
"''',
|
||||
@@ -112,15 +112,15 @@ class ParserTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_validate_incomplete_handlebars_tag_2(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
{{# foo }
|
||||
'''
|
||||
"""
|
||||
self._assert_validate_error('Tag missing "}}" at Line 2 Col 13:"{{# foo }\n"', text=my_html)
|
||||
|
||||
def test_validate_incomplete_django_tag_1(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
{% foo
|
||||
'''
|
||||
"""
|
||||
self._assert_validate_error(
|
||||
'''Tag missing "%}" at Line 2 Col 13:"{% foo
|
||||
"''',
|
||||
@@ -128,15 +128,15 @@ class ParserTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_validate_incomplete_django_tag_2(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
{% foo %
|
||||
'''
|
||||
"""
|
||||
self._assert_validate_error('Tag missing "%}" at Line 2 Col 13:"{% foo %\n"', text=my_html)
|
||||
|
||||
def test_validate_incomplete_html_tag_1(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
<b
|
||||
'''
|
||||
"""
|
||||
self._assert_validate_error(
|
||||
'''Tag missing ">" at Line 2 Col 13:"<b
|
||||
"''',
|
||||
@@ -144,12 +144,12 @@ class ParserTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_validate_incomplete_html_tag_2(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
<a href="
|
||||
'''
|
||||
my_html1 = '''
|
||||
"""
|
||||
my_html1 = """
|
||||
<a href=""
|
||||
'''
|
||||
"""
|
||||
self._assert_validate_error(
|
||||
'''Tag missing ">" at Line 2 Col 13:"<a href=""
|
||||
"''',
|
||||
@@ -162,19 +162,19 @@ class ParserTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_validate_empty_html_tag(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
< >
|
||||
'''
|
||||
self._assert_validate_error('Tag name missing', text=my_html)
|
||||
"""
|
||||
self._assert_validate_error("Tag name missing", text=my_html)
|
||||
|
||||
def test_code_blocks(self) -> None:
|
||||
|
||||
# This is fine.
|
||||
my_html = '''
|
||||
my_html = """
|
||||
<code>
|
||||
x = 5
|
||||
y = x + 1
|
||||
</code>'''
|
||||
</code>"""
|
||||
validate(text=my_html)
|
||||
|
||||
# This is also fine.
|
||||
@@ -182,20 +182,20 @@ class ParserTest(unittest.TestCase):
|
||||
validate(text=my_html)
|
||||
|
||||
# This is illegal.
|
||||
my_html = '''
|
||||
my_html = """
|
||||
<code>x =
|
||||
5</code>
|
||||
'''
|
||||
self._assert_validate_error('Code tag is split across two lines.', text=my_html)
|
||||
"""
|
||||
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 = '''
|
||||
my_html = """
|
||||
<a hef="/some/url">
|
||||
Click here
|
||||
for more info.
|
||||
</a>'''
|
||||
</a>"""
|
||||
validate(text=my_html)
|
||||
|
||||
# This is fine.
|
||||
@@ -203,123 +203,123 @@ class ParserTest(unittest.TestCase):
|
||||
validate(text=my_html)
|
||||
|
||||
# Even this is fine.
|
||||
my_html = '''
|
||||
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_validate_jinja2_whitespace_markers_1(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
{% if foo -%}
|
||||
this is foo
|
||||
{% endif %}
|
||||
'''
|
||||
"""
|
||||
validate(text=my_html)
|
||||
|
||||
def test_validate_jinja2_whitespace_markers_2(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
{% if foo %}
|
||||
this is foo
|
||||
{%- endif %}
|
||||
'''
|
||||
"""
|
||||
validate(text=my_html)
|
||||
|
||||
def test_validate_jinja2_whitespace_markers_3(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
{% if foo %}
|
||||
this is foo
|
||||
{% endif -%}
|
||||
'''
|
||||
"""
|
||||
validate(text=my_html)
|
||||
|
||||
def test_validate_jinja2_whitespace_markers_4(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
{%- if foo %}
|
||||
this is foo
|
||||
{% endif %}
|
||||
'''
|
||||
"""
|
||||
validate(text=my_html)
|
||||
|
||||
def test_validate_mismatch_jinja2_whitespace_markers_1(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
{% if foo %}
|
||||
this is foo
|
||||
{%- if bar %}
|
||||
'''
|
||||
self._assert_validate_error('Missing end tag', text=my_html)
|
||||
"""
|
||||
self._assert_validate_error("Missing end tag", text=my_html)
|
||||
|
||||
def test_validate_jinja2_whitespace_type2_markers(self) -> None:
|
||||
my_html = '''
|
||||
my_html = """
|
||||
{%- if foo -%}
|
||||
this is foo
|
||||
{% endif %}
|
||||
'''
|
||||
"""
|
||||
validate(text=my_html)
|
||||
|
||||
def test_tokenize(self) -> None:
|
||||
tag = '<meta whatever>bla'
|
||||
tag = "<meta whatever>bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, 'html_special')
|
||||
self.assertEqual(token.kind, "html_special")
|
||||
|
||||
tag = '<a>bla'
|
||||
tag = "<a>bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, 'html_start')
|
||||
self.assertEqual(token.tag, 'a')
|
||||
self.assertEqual(token.kind, "html_start")
|
||||
self.assertEqual(token.tag, "a")
|
||||
|
||||
tag = '<br>bla'
|
||||
tag = "<br>bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, 'html_singleton')
|
||||
self.assertEqual(token.tag, 'br')
|
||||
self.assertEqual(token.kind, "html_singleton")
|
||||
self.assertEqual(token.tag, "br")
|
||||
|
||||
tag = '<input>bla'
|
||||
tag = "<input>bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, 'html_singleton')
|
||||
self.assertEqual(token.tag, 'input')
|
||||
self.assertEqual(token.kind, "html_singleton")
|
||||
self.assertEqual(token.tag, "input")
|
||||
|
||||
tag = '<input />bla'
|
||||
tag = "<input />bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, 'html_singleton')
|
||||
self.assertEqual(token.tag, 'input')
|
||||
self.assertEqual(token.kind, "html_singleton")
|
||||
self.assertEqual(token.tag, "input")
|
||||
|
||||
tag = '</a>bla'
|
||||
tag = "</a>bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, 'html_end')
|
||||
self.assertEqual(token.tag, 'a')
|
||||
self.assertEqual(token.kind, "html_end")
|
||||
self.assertEqual(token.tag, "a")
|
||||
|
||||
tag = '{{#with foo}}bla'
|
||||
tag = "{{#with foo}}bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, 'handlebars_start')
|
||||
self.assertEqual(token.tag, 'with')
|
||||
self.assertEqual(token.kind, "handlebars_start")
|
||||
self.assertEqual(token.tag, "with")
|
||||
|
||||
tag = '{{/with}}bla'
|
||||
tag = "{{/with}}bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, 'handlebars_end')
|
||||
self.assertEqual(token.tag, 'with')
|
||||
self.assertEqual(token.kind, "handlebars_end")
|
||||
self.assertEqual(token.tag, "with")
|
||||
|
||||
tag = '{% if foo %}bla'
|
||||
tag = "{% if foo %}bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, 'django_start')
|
||||
self.assertEqual(token.tag, 'if')
|
||||
self.assertEqual(token.kind, "django_start")
|
||||
self.assertEqual(token.tag, "if")
|
||||
|
||||
tag = '{% endif %}bla'
|
||||
tag = "{% endif %}bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, 'django_end')
|
||||
self.assertEqual(token.tag, 'if')
|
||||
self.assertEqual(token.kind, "django_end")
|
||||
self.assertEqual(token.tag, "if")
|
||||
|
||||
tag = '{% if foo -%}bla'
|
||||
tag = "{% if foo -%}bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, 'jinja2_whitespace_stripped_start')
|
||||
self.assertEqual(token.tag, 'if')
|
||||
self.assertEqual(token.kind, "jinja2_whitespace_stripped_start")
|
||||
self.assertEqual(token.tag, "if")
|
||||
|
||||
tag = '{%- endif %}bla'
|
||||
tag = "{%- endif %}bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, 'jinja2_whitespace_stripped_end')
|
||||
self.assertEqual(token.tag, 'if')
|
||||
self.assertEqual(token.kind, "jinja2_whitespace_stripped_end")
|
||||
self.assertEqual(token.tag, "if")
|
||||
|
||||
tag = '{%- if foo -%}bla'
|
||||
tag = "{%- if foo -%}bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, 'jinja2_whitespace_stripped_type2_start')
|
||||
self.assertEqual(token.tag, 'if')
|
||||
self.assertEqual(token.kind, "jinja2_whitespace_stripped_type2_start")
|
||||
self.assertEqual(token.tag, "if")
|
||||
|
||||
Reference in New Issue
Block a user