From 1dbabfe1abc067b32a6b2fd7ad740a438e59ae72 Mon Sep 17 00:00:00 2001 From: Eklavya Sharma Date: Tue, 11 Oct 2016 15:25:03 +0530 Subject: [PATCH] Annotate zerver/tests/test_bugdown.py. --- tools/run-mypy | 1 - zerver/tests/test_bugdown.py | 26 +++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/tools/run-mypy b/tools/run-mypy index 1652bda64c..70431ca0e5 100755 --- a/tools/run-mypy +++ b/tools/run-mypy @@ -33,7 +33,6 @@ bots/zephyr_mirror_backend.py tools/deprecated/generate-activity-metrics.py zproject/settings.py zproject/test_settings.py -zerver/tests/test_bugdown.py zerver/tests/test_email_mirror.py zerver/tests/test_decorators.py zerver/tests/test_upload.py diff --git a/zerver/tests/test_bugdown.py b/zerver/tests/test_bugdown.py index 338603d3d2..b9069c92c5 100644 --- a/zerver/tests/test_bugdown.py +++ b/zerver/tests/test_bugdown.py @@ -38,6 +38,10 @@ import os import ujson 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): def test_simple_quoting(self): # type: () -> None @@ -92,8 +96,8 @@ class FencedBlockPreprocessorTest(TestCase): processor = bugdown.fenced_code.FencedBlockPreprocessor(None) # Simulate code formatting. - processor.format_code = lambda lang, code: lang + ':' + code - processor.placeholder = lambda s: '**' + s.strip('\n') + '**' + processor.format_code = lambda lang, code: lang + ':' + code # type: ignore # mypy doesn't allow monkey-patching functions + processor.placeholder = lambda s: '**' + s.strip('\n') + '**' # type: ignore # https://github.com/python/mypy/issues/708 markdown = [ '``` .py', @@ -125,8 +129,8 @@ class FencedBlockPreprocessorTest(TestCase): processor = bugdown.fenced_code.FencedBlockPreprocessor(None) # Simulate code formatting. - processor.format_code = lambda lang, code: lang + ':' + code - processor.placeholder = lambda s: '**' + s.strip('\n') + '**' + processor.format_code = lambda lang, code: lang + ':' + code # type: ignore # mypy doesn't allow monkey-patching functions + processor.placeholder = lambda s: '**' + s.strip('\n') + '**' # type: ignore # https://github.com/python/mypy/issues/708 markdown = [ '~~~ quote', @@ -150,14 +154,17 @@ class FencedBlockPreprocessorTest(TestCase): self.assertEqual(lines, expected) def bugdown_convert(text): + # type: (text_type) -> text_type return bugdown.convert(text, "zulip.com") class BugdownTest(TestCase): def common_bugdown_test(self, text, expected): + # type: (text_type, text_type) -> None converted = bugdown_convert(text) self.assertEqual(converted, expected) def load_bugdown_tests(self): + # type: () -> Tuple[Dict[text_type, Any], List[List[text_type]]] test_fixtures = {} data_file = open(os.path.join(os.path.dirname(__file__), '../fixtures/bugdown-data.json'), 'r') data = ujson.loads('\n'.join(data_file.readlines())) @@ -170,7 +177,7 @@ class BugdownTest(TestCase): # type: () -> None 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): converted = bugdown_convert(test['input']) @@ -178,6 +185,7 @@ class BugdownTest(TestCase): self.assertEqual(converted, test['expected_output']) def replaced(payload, url, phrase=''): + # type: (text_type, text_type, text_type) -> text_type target = " target=\"_blank\"" if url[:4] == 'http': href = url @@ -190,7 +198,7 @@ class BugdownTest(TestCase): print("Running Bugdown Linkify tests") - self.maxDiff = None + self.maxDiff = None # type: Optional[int] for inline_url, reference, url in linkify_tests: try: match = replaced(reference, url, phrase=inline_url) @@ -262,6 +270,7 @@ class BugdownTest(TestCase): def test_inline_interesting_links(self): # type: () -> None def make_link(url): + # type: (text_type) -> text_type return '%s' % (url, url, url) normal_tweet_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 return ('
' '