From 5af47e0eef2a51bd6a9cc5659c9d6c9cd1979243 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 3 Aug 2016 16:44:15 -0700 Subject: [PATCH] Make fn param optional with template_parser.validate(). The caller can now pass in text directly. This is mostly for testing, but it could be useful in other situations. --- tools/check-templates | 4 ++-- tools/lib/template_parser.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/check-templates b/tools/check-templates index 8d3e8d858b..d1ad1d3512 100755 --- a/tools/check-templates +++ b/tools/check-templates @@ -85,7 +85,7 @@ def check_html_templates(templates, modified_only): 'templates/zerver/right-sidebar.html', 'templates/zerver/search_operators.html', ] - validate(fn, check_indent=(fn not in bad_files)) + validate(fn=fn, check_indent=(fn not in bad_files)) def check_handlebar_templates(templates, modified_only): # type: (Iterable[str], bool) -> None @@ -94,7 +94,7 @@ def check_handlebar_templates(templates, modified_only): if not modified_only: assert len(templates) >= 10 # sanity check that we are actually doing work for fn in templates: - validate(fn, check_indent=True) + validate(fn=fn, check_indent=True) if __name__ == '__main__': check_our_files() diff --git a/tools/lib/template_parser.py b/tools/lib/template_parser.py index 7b6095a8fc..2e83717351 100644 --- a/tools/lib/template_parser.py +++ b/tools/lib/template_parser.py @@ -103,9 +103,16 @@ def tokenize(text): return tokens -def validate(fn, check_indent=True): - # type: (str, bool) -> None - text = open(fn).read() +def validate(fn=None, text=None, check_indent=True): + # type: (str, str, bool) -> None + assert fn or text + + if fn is None: + fn = '' + + if text is None: + text = open(fn).read() + tokens = tokenize(text) class State(object):