Refs #32144 -- Made makemessages remove temporary files on preprocessing error.

Co-authored-by: Anders Hovmöller <anders.hovmoller@dryft.se>
This commit is contained in:
Carlton Gibson 2021-06-30 14:15:25 +02:00 committed by Carlton Gibson
parent dfa7781033
commit 4af162d4de
3 changed files with 13 additions and 1 deletions

View File

@ -527,6 +527,11 @@ class Command(BaseCommand):
) )
) )
continue continue
except BaseException:
# Cleanup before exit.
for build_file in build_files:
build_file.cleanup()
raise
build_files.append(build_file) build_files.append(build_file)
if self.domain == 'djangojs': if self.domain == 'djangojs':

View File

@ -0,0 +1,6 @@
{% load i18n %}
{% blocktranslate %}Hello{% endblocktranslate %}
This file has a name that should be lexicographically before
'template_with_error.tpl' so that we can test the cleanup case
of the first file being successful, but the second failing.

View File

@ -226,8 +226,9 @@ class BasicExtractorTests(ExtractorTests):
) )
with self.assertRaisesMessage(SyntaxError, msg): with self.assertRaisesMessage(SyntaxError, msg):
management.call_command('makemessages', locale=[LOCALE], extensions=['tpl'], verbosity=0) management.call_command('makemessages', locale=[LOCALE], extensions=['tpl'], verbosity=0)
# The temporary file was cleaned up # The temporary files were cleaned up.
self.assertFalse(os.path.exists('./templates/template_with_error.tpl.py')) self.assertFalse(os.path.exists('./templates/template_with_error.tpl.py'))
self.assertFalse(os.path.exists('./templates/template_0_with_no_error.tpl.py'))
def test_unicode_decode_error(self): def test_unicode_decode_error(self):
shutil.copyfile('./not_utf8.sample', './not_utf8.txt') shutil.copyfile('./not_utf8.sample', './not_utf8.txt')