21 lines
714 B
Python
21 lines
714 B
Python
|
from datetime import datetime
|
||
|
from unittest import TestCase
|
||
|
|
||
|
from atextcrawler.utils.date_finder import extract_latest_date
|
||
|
|
||
|
|
||
|
class DateFinderTest(TestCase):
|
||
|
def test_extract_latest_date(self):
|
||
|
s = 'test 1987-2+1-no'
|
||
|
r = datetime(1987, 2, 1)
|
||
|
self.assertEqual(extract_latest_date(s), r)
|
||
|
s = '2020-04-06, whatever and 1987-2-1, 1/20/2021'
|
||
|
r = datetime(2020, 4, 6)
|
||
|
self.assertEqual(extract_latest_date(s, lang='de'), r)
|
||
|
s = 'test 2022-04-06, whatever and 1987-2-1, 1/20/2021'
|
||
|
r = datetime(2021, 1, 20)
|
||
|
self.assertEqual(extract_latest_date(s, lang='en'), r)
|
||
|
s = ''
|
||
|
r = None
|
||
|
self.assertEqual(extract_latest_date(s), r)
|