def test_infer_format_invalid_date(): date = infer_format('Tuesday 5 March 2019 08:59') assert date.format == '%A %d %B %Y %H:%M' assert date.locale == 'en_US.UTF-8' assert date.date_string == 'Tuesday 5 March 2019 08:59' with pytest.raises(ValueError): date = infer_format('Tuesday 5 Marc 2019 08:59')
def test_infer_format_multiple_languages(): date = infer_format('dinsdag 5 maart 2019 08:59') assert date.format == '%A %d %B %Y %H:%M' assert date.locale == 'nl_NL.UTF-8' date = infer_format('Tuesday 5 March 2019 08:59') assert date.format == '%A %d %B %Y %H:%M' assert date.locale == 'en_US.UTF-8' date = infer_format('Dienstag 5 März 2019 08:59') assert date.format == '%A %d %B %Y %H:%M' assert date.locale == 'de_DE.UTF-8'
def test_infer_format(): assert infer_format( 'Tuesday 5 March 2019 08:59').format == '%A %d %B %Y %H:%M' assert infer_format('Friday (10 June)').format == '%A (%d %B)' assert infer_format('10 November').format == '%d %B' assert infer_format('August 3, 2009').format == '%B %d, %Y' assert infer_format('2 May 1980').format == '%d %b %Y' assert infer_format('20-08-2016').format == '%d-%m-%Y' assert infer_format('Friday').format == '%A' assert infer_format('23 feb.').format == '%d %b.' assert infer_format('01 01 2015').format == '%d %m %Y' assert infer_format('22/05/13').format == '%d/%m/%y'
def test_infer_format_unanchored_weekdays(): date = infer_format('vrijdag') assert date.format == '%A' assert date.locale == 'nl_NL.UTF-8' assert date.datetime.year == 1900 assert date.datetime.day == 15 assert date.datetime.month == 1
def test_infer_format(): assert infer_format( 'Tuesday 5 March 2019 08:59').format == '%A %d %B %Y %H:%M' assert infer_format('Friday (10 June)').format == '%A (%d %B)' assert infer_format('10 November').format == '%d %B' assert infer_format('August 3, 2009').format == '%B %d, %Y' assert infer_format('2 May 1980').format == '%d %b %Y' assert infer_format('20-08-2016').format == '%d-%m-%Y' assert infer_format('Friday').format == '%A' assert infer_format('23 feb.').format == '%d %b.' assert infer_format('01 01 2015').format == '%d %m %Y' assert infer_format('22/05/13').format == '%d/%m/%y' assert infer_format('0411').format == '%Y' # Odd edge case which results into a parsing including timezone information. # This should be handled gracefully. assert infer_format('15-34-2019').format == '%H-%M%z'