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())
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())
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())
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())