mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 02:48:00 +00:00
Annotate zerver/tests/test_bugdown.py.
This commit is contained in:
committed by
Tim Abbott
parent
8e2f659f3d
commit
1dbabfe1ab
@@ -33,7 +33,6 @@ bots/zephyr_mirror_backend.py
|
|||||||
tools/deprecated/generate-activity-metrics.py
|
tools/deprecated/generate-activity-metrics.py
|
||||||
zproject/settings.py
|
zproject/settings.py
|
||||||
zproject/test_settings.py
|
zproject/test_settings.py
|
||||||
zerver/tests/test_bugdown.py
|
|
||||||
zerver/tests/test_email_mirror.py
|
zerver/tests/test_email_mirror.py
|
||||||
zerver/tests/test_decorators.py
|
zerver/tests/test_decorators.py
|
||||||
zerver/tests/test_upload.py
|
zerver/tests/test_upload.py
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ import os
|
|||||||
import ujson
|
import ujson
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from six import text_type
|
||||||
|
from zerver.lib.str_utils import NonBinaryStr
|
||||||
|
from typing import Any, AnyStr, Dict, List, Optional, Tuple
|
||||||
|
|
||||||
class FencedBlockPreprocessorTest(TestCase):
|
class FencedBlockPreprocessorTest(TestCase):
|
||||||
def test_simple_quoting(self):
|
def test_simple_quoting(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
@@ -92,8 +96,8 @@ class FencedBlockPreprocessorTest(TestCase):
|
|||||||
processor = bugdown.fenced_code.FencedBlockPreprocessor(None)
|
processor = bugdown.fenced_code.FencedBlockPreprocessor(None)
|
||||||
|
|
||||||
# Simulate code formatting.
|
# Simulate code formatting.
|
||||||
processor.format_code = lambda lang, code: lang + ':' + code
|
processor.format_code = lambda lang, code: lang + ':' + code # type: ignore # mypy doesn't allow monkey-patching functions
|
||||||
processor.placeholder = lambda s: '**' + s.strip('\n') + '**'
|
processor.placeholder = lambda s: '**' + s.strip('\n') + '**' # type: ignore # https://github.com/python/mypy/issues/708
|
||||||
|
|
||||||
markdown = [
|
markdown = [
|
||||||
'``` .py',
|
'``` .py',
|
||||||
@@ -125,8 +129,8 @@ class FencedBlockPreprocessorTest(TestCase):
|
|||||||
processor = bugdown.fenced_code.FencedBlockPreprocessor(None)
|
processor = bugdown.fenced_code.FencedBlockPreprocessor(None)
|
||||||
|
|
||||||
# Simulate code formatting.
|
# Simulate code formatting.
|
||||||
processor.format_code = lambda lang, code: lang + ':' + code
|
processor.format_code = lambda lang, code: lang + ':' + code # type: ignore # mypy doesn't allow monkey-patching functions
|
||||||
processor.placeholder = lambda s: '**' + s.strip('\n') + '**'
|
processor.placeholder = lambda s: '**' + s.strip('\n') + '**' # type: ignore # https://github.com/python/mypy/issues/708
|
||||||
|
|
||||||
markdown = [
|
markdown = [
|
||||||
'~~~ quote',
|
'~~~ quote',
|
||||||
@@ -150,14 +154,17 @@ class FencedBlockPreprocessorTest(TestCase):
|
|||||||
self.assertEqual(lines, expected)
|
self.assertEqual(lines, expected)
|
||||||
|
|
||||||
def bugdown_convert(text):
|
def bugdown_convert(text):
|
||||||
|
# type: (text_type) -> text_type
|
||||||
return bugdown.convert(text, "zulip.com")
|
return bugdown.convert(text, "zulip.com")
|
||||||
|
|
||||||
class BugdownTest(TestCase):
|
class BugdownTest(TestCase):
|
||||||
def common_bugdown_test(self, text, expected):
|
def common_bugdown_test(self, text, expected):
|
||||||
|
# type: (text_type, text_type) -> None
|
||||||
converted = bugdown_convert(text)
|
converted = bugdown_convert(text)
|
||||||
self.assertEqual(converted, expected)
|
self.assertEqual(converted, expected)
|
||||||
|
|
||||||
def load_bugdown_tests(self):
|
def load_bugdown_tests(self):
|
||||||
|
# type: () -> Tuple[Dict[text_type, Any], List[List[text_type]]]
|
||||||
test_fixtures = {}
|
test_fixtures = {}
|
||||||
data_file = open(os.path.join(os.path.dirname(__file__), '../fixtures/bugdown-data.json'), 'r')
|
data_file = open(os.path.join(os.path.dirname(__file__), '../fixtures/bugdown-data.json'), 'r')
|
||||||
data = ujson.loads('\n'.join(data_file.readlines()))
|
data = ujson.loads('\n'.join(data_file.readlines()))
|
||||||
@@ -170,7 +177,7 @@ class BugdownTest(TestCase):
|
|||||||
# type: () -> None
|
# type: () -> None
|
||||||
format_tests, linkify_tests = self.load_bugdown_tests()
|
format_tests, linkify_tests = self.load_bugdown_tests()
|
||||||
|
|
||||||
self.maxDiff = None
|
self.maxDiff = None # type: Optional[int]
|
||||||
for name, test in six.iteritems(format_tests):
|
for name, test in six.iteritems(format_tests):
|
||||||
converted = bugdown_convert(test['input'])
|
converted = bugdown_convert(test['input'])
|
||||||
|
|
||||||
@@ -178,6 +185,7 @@ class BugdownTest(TestCase):
|
|||||||
self.assertEqual(converted, test['expected_output'])
|
self.assertEqual(converted, test['expected_output'])
|
||||||
|
|
||||||
def replaced(payload, url, phrase=''):
|
def replaced(payload, url, phrase=''):
|
||||||
|
# type: (text_type, text_type, text_type) -> text_type
|
||||||
target = " target=\"_blank\""
|
target = " target=\"_blank\""
|
||||||
if url[:4] == 'http':
|
if url[:4] == 'http':
|
||||||
href = url
|
href = url
|
||||||
@@ -190,7 +198,7 @@ class BugdownTest(TestCase):
|
|||||||
|
|
||||||
|
|
||||||
print("Running Bugdown Linkify tests")
|
print("Running Bugdown Linkify tests")
|
||||||
self.maxDiff = None
|
self.maxDiff = None # type: Optional[int]
|
||||||
for inline_url, reference, url in linkify_tests:
|
for inline_url, reference, url in linkify_tests:
|
||||||
try:
|
try:
|
||||||
match = replaced(reference, url, phrase=inline_url)
|
match = replaced(reference, url, phrase=inline_url)
|
||||||
@@ -262,6 +270,7 @@ class BugdownTest(TestCase):
|
|||||||
def test_inline_interesting_links(self):
|
def test_inline_interesting_links(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
def make_link(url):
|
def make_link(url):
|
||||||
|
# type: (text_type) -> text_type
|
||||||
return '<a href="%s" target="_blank" title="%s">%s</a>' % (url, url, url)
|
return '<a href="%s" target="_blank" title="%s">%s</a>' % (url, url, url)
|
||||||
|
|
||||||
normal_tweet_html = ('<a href="https://twitter.com/twitter" target="_blank"'
|
normal_tweet_html = ('<a href="https://twitter.com/twitter" target="_blank"'
|
||||||
@@ -280,6 +289,7 @@ class BugdownTest(TestCase):
|
|||||||
'http://twitter.com/NEVNBoston/status/421654515616849920/photo/1</a>')
|
'http://twitter.com/NEVNBoston/status/421654515616849920/photo/1</a>')
|
||||||
|
|
||||||
def make_inline_twitter_preview(url, tweet_html, image_html=''):
|
def make_inline_twitter_preview(url, tweet_html, image_html=''):
|
||||||
|
# type: (text_type, text_type, text_type) -> text_type
|
||||||
## As of right now, all previews are mocked to be the exact same tweet
|
## As of right now, all previews are mocked to be the exact same tweet
|
||||||
return ('<div class="inline-preview-twitter">'
|
return ('<div class="inline-preview-twitter">'
|
||||||
'<div class="twitter-tweet">'
|
'<div class="twitter-tweet">'
|
||||||
@@ -378,6 +388,7 @@ class BugdownTest(TestCase):
|
|||||||
def test_realm_emoji(self):
|
def test_realm_emoji(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
def emoji_img(name, url):
|
def emoji_img(name, url):
|
||||||
|
# type: (text_type, text_type) -> text_type
|
||||||
return '<img alt="%s" class="emoji" src="%s" title="%s">' % (name, get_camo_url(url), name)
|
return '<img alt="%s" class="emoji" src="%s" title="%s">' % (name, get_camo_url(url), name)
|
||||||
|
|
||||||
zulip_realm = get_realm('zulip.com')
|
zulip_realm = get_realm('zulip.com')
|
||||||
@@ -458,7 +469,7 @@ class BugdownTest(TestCase):
|
|||||||
directly for testing is kind of awkward
|
directly for testing is kind of awkward
|
||||||
'''
|
'''
|
||||||
class Instance(object):
|
class Instance(object):
|
||||||
pass
|
realm = None # type: Optional[Realm]
|
||||||
instance = Instance()
|
instance = Instance()
|
||||||
instance.realm = realm
|
instance.realm = realm
|
||||||
flush_realm_filter(sender=None, instance=instance)
|
flush_realm_filter(sender=None, instance=instance)
|
||||||
@@ -526,6 +537,7 @@ class BugdownTest(TestCase):
|
|||||||
realm_alert_words = alert_words_in_realm(user_profile.realm)
|
realm_alert_words = alert_words_in_realm(user_profile.realm)
|
||||||
|
|
||||||
def render(msg, content):
|
def render(msg, content):
|
||||||
|
# type: (Message, text_type) -> text_type
|
||||||
return render_markdown(msg,
|
return render_markdown(msg,
|
||||||
content,
|
content,
|
||||||
realm_alert_words=realm_alert_words,
|
realm_alert_words=realm_alert_words,
|
||||||
|
|||||||
Reference in New Issue
Block a user