本文整理汇总了Python中dateparser.languages.detection.AutoDetectLanguage.parse方法的典型用法代码示例。如果您正苦于以下问题:Python AutoDetectLanguage.parse方法的具体用法?Python AutoDetectLanguage.parse怎么用?Python AutoDetectLanguage.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dateparser.languages.detection.AutoDetectLanguage
的用法示例。
在下文中一共展示了AutoDetectLanguage.parse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_should_accept_dates_in_different_languages
# 需要导入模块: from dateparser.languages.detection import AutoDetectLanguage [as 别名]
# 或者: from dateparser.languages.detection.AutoDetectLanguage import parse [as 别名]
def test_should_accept_dates_in_different_languages(self):
date_fixtures = [
(u'13 Ago, 2014', datetime(2014, 8, 13)),
(u'13 Septiembre, 2014', datetime(2014, 9, 13)),
(u'13 Setembro, 2014', datetime(2014, 9, 13)),
]
parser = AutoDetectLanguage(None, allow_redetection=True)
for date_string, correct_date in date_fixtures:
parsed_date = parser.parse(date_string, None)
self.assertEqual(correct_date.date(), parsed_date.date())
示例2: AutoDetectLanguageTest
# 需要导入模块: from dateparser.languages.detection import AutoDetectLanguage [as 别名]
# 或者: from dateparser.languages.detection.AutoDetectLanguage import parse [as 别名]
class AutoDetectLanguageTest(unittest.TestCase):
def setUp(self):
self.parser = AutoDetectLanguage()
def test_detect_language(self):
self.assertItemsEqual(['es', 'pt'],
map(attrgetter('shortname'), self.parser.iterate_applicable_languages('11 abril 2010')))
self.assertItemsEqual(['es'],
map(attrgetter('shortname'), self.parser.iterate_applicable_languages('11 junio 2010')))
@unittest.skip('This test should only be testing detecting languages, not parsing them. Although tests '
'for parsing this dates should be created separately to not reduce the coverage')
def test_should_reduce_possible_languages_and_reject_different(self):
dates_in_spanish = [
(u'13 Ago, 2014', datetime(2014, 8, 13)),
(u'13 Septiembre, 2014', datetime(2014, 9, 13)),
]
for date_string, correct_date in dates_in_spanish:
parsed_date = self.parser.parse(date_string, None)
self.assertEqual(correct_date.date(), parsed_date.date())
with self.assertRaisesRegexp(ValueError, 'Invalid date'):
portuguese_date = u'13 Setembro, 2014'
self.parser.parse(portuguese_date, None)
@unittest.skip('This test should only be testing detecting languages, not parsing them. Although tests '
'for parsing this dates should be created separately to not reduce the coverage')
def test_should_accept_dates_in_different_languages(self):
date_fixtures = [
(u'13 Ago, 2014', datetime(2014, 8, 13)),
(u'13 Septiembre, 2014', datetime(2014, 9, 13)),
(u'13 Setembro, 2014', datetime(2014, 9, 13)),
]
parser = AutoDetectLanguage(None, allow_redetection=True)
for date_string, correct_date in date_fixtures:
parsed_date = parser.parse(date_string, None)
self.assertEqual(correct_date.date(), parsed_date.date())