def test_turkish_locale(self): if platform == 'win32': locale_string = 'Turkish' else: locale_string = 'tr_TR.UTF-8' settings = read_settings( override={ 'LOCALE': locale_string, 'TEMPLATE_PAGES': { 'template/source.html': 'generated/file.html' } }) generator = TemplatePagesGenerator({'date': self.date}, settings, self.temp_content, '', self.temp_output) generator.env.filters.update({'strftime': utils.DateFormatter()}) writer = Writer(self.temp_output, settings=settings) generator.generate_output(writer) output_path = os.path.join(self.temp_output, 'generated', 'file.html') # output file has been generated self.assertTrue(os.path.exists(output_path)) # output content is correct with utils.pelican_open(output_path) as output_file: self.assertEqual(output_file, utils.strftime(self.date, 'date = %A, %d %B %Y'))
def test_french_strftime(self): # This test tries to reproduce an issue that occured with python3.3 under macos10 only locale.setlocale(locale.LC_ALL, str('fr_FR.UTF-8')) date = utils.SafeDatetime(2014,8,14) # we compare the lower() dates since macos10 returns "Jeudi" for %A whereas linux reports "jeudi" self.assertEqual( u'jeudi, 14 août 2014', utils.strftime(date, date_format="%A, %d %B %Y").lower() ) df = utils.DateFormatter() self.assertEqual( u'jeudi, 14 août 2014', df(date, date_format="%A, %d %B %Y").lower() ) # Let us now set the global locale to C: locale.setlocale(locale.LC_ALL, str('C')) # DateFormatter should still work as expected since it is the whole point of DateFormatter # (This is where pre-2014/4/15 code fails on macos10) df_date = df(date, date_format="%A, %d %B %Y").lower() self.assertEqual( u'jeudi, 14 août 2014', df_date )