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.
This commit is contained in:
Steve Howell 2016-08-03 16:44:15 -07:00 committed by Tim Abbott
parent 1f8ba1d1b5
commit 5af47e0eef
2 changed files with 12 additions and 5 deletions

View File

@ -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()

View File

@ -103,9 +103,16 @@ def tokenize(text):
return tokens
def validate(fn, check_indent=True):
# type: (str, bool) -> None
def validate(fn=None, text=None, check_indent=True):
# type: (str, str, bool) -> None
assert fn or text
if fn is None:
fn = '<in memory file>'
if text is None:
text = open(fn).read()
tokens = tokenize(text)
class State(object):