Kaydet (Commit) 45e3dff5 authored tarafından Julien Phalip's avatar Julien Phalip

Ensured that `makemessages` doesn't leave any temporary file over if the parsing…

Ensured that `makemessages` doesn't leave any temporary file over if the parsing of a template file fails. Refs #8536.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17240 bcc190cf-cafb-0310-a4f2-bffc1f526a37
üst 39109b0e
...@@ -229,9 +229,10 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, ...@@ -229,9 +229,10 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
if file_ext in extensions: if file_ext in extensions:
src = open(orig_file, "rU").read() src = open(orig_file, "rU").read()
thefile = '%s.py' % file thefile = '%s.py' % file
content = templatize(src, orig_file[2:])
f = open(os.path.join(dirpath, thefile), "w") f = open(os.path.join(dirpath, thefile), "w")
try: try:
f.write(templatize(src, orig_file[2:])) f.write(content)
finally: finally:
f.close() f.close()
if verbosity > 1: if verbosity > 1:
......
...@@ -108,16 +108,14 @@ class BasicExtractorTests(ExtractorTests): ...@@ -108,16 +108,14 @@ class BasicExtractorTests(ExtractorTests):
os.chdir(self.test_dir) os.chdir(self.test_dir)
shutil.copyfile('./templates/template_with_error.tpl', './templates/template_with_error.html') shutil.copyfile('./templates/template_with_error.tpl', './templates/template_with_error.html')
self.assertRaises(SyntaxError, management.call_command, 'makemessages', locale=LOCALE, verbosity=0) self.assertRaises(SyntaxError, management.call_command, 'makemessages', locale=LOCALE, verbosity=0)
try: with self.assertRaises(SyntaxError) as context_manager:
management.call_command('makemessages', locale=LOCALE, verbosity=0) management.call_command('makemessages', locale=LOCALE, verbosity=0)
except SyntaxError, e: self.assertRegexpMatches(str(context_manager.exception),
self.assertRegexpMatches(
str(e),
r'Translation blocks must not include other block tags: blocktrans \(file templates[/\\]template_with_error\.html, line 3\)' r'Translation blocks must not include other block tags: blocktrans \(file templates[/\\]template_with_error\.html, line 3\)'
) )
finally: os.remove('./templates/template_with_error.html')
os.remove('./templates/template_with_error.html') # Check that the temporary file was cleaned up
os.remove('./templates/template_with_error.html.py') # Waiting for #8536 to be fixed self.assertFalse(os.path.exists('./templates/template_with_error.html.py'))
def test_template_message_context_extractor(self): def test_template_message_context_extractor(self):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment