def test_format_date__default(self): day = date(2018, 6, 5) cases = [ ('en', 'June 5, 2018'), ('es', '5 de junio de 2018'), ('tl', 'Hunyo 5, 2018'), ('zh', '2018年6月5日'), ] for lang, expected in cases: with self.subTest(lang=lang): actual = utils.format_date(day, lang=lang) self.assertEqual(actual, expected)
def test_format_date__medium(self): """ Test passing format_='medium'. """ day = date(2018, 6, 5) cases = [ ('en', 'Jun 5, 2018'), ('es', '5 jun. 2018'), ('tl', 'Hun 5, 2018'), ('zh', '2018年6月5日'), ] for lang, expected in cases: with self.subTest(lang=lang): actual = utils.format_date(day, lang=lang, format_='medium') self.assertEqual(actual, expected)
def _format_date(context, date, format_=None): lang = context['options'].lang try: return utils.format_date(date, lang=lang, format_=format_) except Exception: raise RuntimeError(f'error formatting date: {date!r}')