~abompard/mailman/mailman-templates-utf8

« back to all changes in this revision

Viewing changes to src/mailman/utilities/tests/test_templates.py

  • Committer: Aurélien Bompard
  • Date: 2015-02-11 16:21:39 UTC
  • Revision ID: aurelien@bompard.org-20150211162139-xuo0saxblepin1qj
Resetting the locale broke other tests which assume the "C" locale

(because Mailman never calls locale.setlocale())

Show diffs side-by-side

added added

removed removed

Lines of Context:
229
229
        self.assertEqual(cm.exception.template_file, 'missing.txt')
230
230
 
231
231
    def test_encoding(self):
232
 
        with open(self.xxsite, 'w') as fp:
 
232
        with open(self.xxsite, 'w', encoding="utf-8") as fp:
233
233
            fp.write('Ol\ufffd!')
 
234
        # Settings LC_ALL to 'C' will clear locale.getpreferredencoding() from
 
235
        # references to UTF-8 that it would have caught up reading the
 
236
        # environment.
234
237
        locale.setlocale(locale.LC_ALL, 'C')
235
238
        filename, self.fp = find('site.txt', language='xx')
236
239
        try:
237
240
            content = self.fp.read()
238
241
        except UnicodeDecodeError:
239
242
            self.fail("Templates should be considered UTF-8 by default")
240
 
        finally:
241
 
            locale.resetlocale(locale.LC_ALL)
242
243
        self.assertEqual(content, 'Ol\ufffd!')
243
244
 
244
245