class TestTimeStripperWithDigitsAsMonths(TestCase): """Test cases for TimeStripper methods.""" family = 'wikipedia' code = 'cs' cached = True def setUp(self): super(TestTimeStripperWithDigitsAsMonths, self).setUp() self.ts = TimeStripper(self.get_site()) def test_last_match_and_replace(self): """Test that pattern matches and removes items correctly.""" txtWithOneMatch = u'this string has XX. YY. 12. in it' txtWithTwoMatch = u'this string has XX. 1. 12. in it' txtWithThreeMatch = u'this string has 1. 1. 12. in it' txtWithNoMatch = u'this string has no match' pat = self.ts.pmonthR self.assertEqual(self.ts.last_match_and_replace(txtWithOneMatch, pat), (u'this string has XX. YY. 12. in it', { 'month': u'12.' })) self.assertEqual(self.ts.last_match_and_replace(txtWithTwoMatch, pat), (u'this string has XX. 1. 12. in it', { 'month': u'12.' })) self.assertEqual( self.ts.last_match_and_replace(txtWithThreeMatch, pat), (u'this string has @@ 1. 12. in it', { 'month': u'12.' })) self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat), (txtWithNoMatch, None))
class TestTimeStripper(PywikibotTestCase): """Test cases for Link objects""" def setUp(self): site = pywikibot.Site('fr', 'wikipedia') self.ts = TimeStripper(site) super(TestTimeStripper, self).setUp() def test_findmarker(self): """Test that string which is not part of text is found""" txt = u'this is a string with a maker is @@@@already present' self.assertEqual(self.ts.findmarker(txt, base=u'@@', delta='@@'), '@@@@@@') def test_last_match_and_replace(self): """Test that pattern matches the righmost item""" txtWithMatch = u'this string has one 1998, 1999 and 3000 in it' txtWithNoMatch = u'this string has no match' pat = self.ts.yearR self.assertEqual(self.ts.last_match_and_replace(txtWithMatch, pat), (u'this string has one @@, @@ and 3000 in it', {'year': u'1999'}) ) self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat), (txtWithNoMatch, None) ) def test_timestripper(self): """Test that correct date is matched""" txtMatch = u'3 février 2010 à 19:48 (CET) 7 février 2010 à 19:48 (CET)' txtNoMatch = u'3 March 2010 19:48 (CET) 7 March 2010 19:48 (CET)' tzone = tzoneFixedOffset(self.ts.site.siteinfo['timeoffset'], self.ts.site.siteinfo['timezone']) res = datetime.datetime(2010, 2, 7, 19, 48, tzinfo=tzone) self.assertEqual(self.ts.timestripper(txtMatch), res) self.assertEqual(self.ts.timestripper(txtNoMatch), None)
class TestTimeStripperWithDigitsAsMonths(TestCase): """Test cases for TimeStripper methods.""" family = 'wikipedia' code = 'cs' cached = True def setUp(self): """Setup a timestripper for the configured site.""" super(TestTimeStripperWithDigitsAsMonths, self).setUp() self.ts = TimeStripper(self.get_site()) def test_last_match_and_replace(self): """Test that pattern matches and removes items correctly.""" txtWithOneMatch = u'this string has XX. YY. 12. in it' txtWithTwoMatch = u'this string has XX. 1. 12. in it' txtWithThreeMatch = u'this string has 1. 1. 12. in it' txtWithNoMatch = u'this string has no match' pat = self.ts.pmonthR self.assertEqual(self.ts.last_match_and_replace(txtWithOneMatch, pat), (u'this string has XX. YY. 12. in it', {'month': u'12.'}) ) self.assertEqual(self.ts.last_match_and_replace(txtWithTwoMatch, pat), (u'this string has XX. 1. 12. in it', {'month': u'12.'}) ) self.assertEqual(self.ts.last_match_and_replace(txtWithThreeMatch, pat), (u'this string has @@ 1. 12. in it', {'month': u'12.'}) ) self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat), (txtWithNoMatch, None) )
class TestTimeStripperWithNoDigitsAsMonths(TestCase): """Test cases for TimeStripper methods.""" family = 'wikipedia' code = 'fr' cached = True def setUp(self): super(TestTimeStripperWithNoDigitsAsMonths, self).setUp() self.ts = TimeStripper(self.get_site()) def test_findmarker(self): """Test that string which is not part of text is found.""" txt = u'this is a string with a maker is @@@@already present' self.assertEqual(self.ts.findmarker(txt, base=u'@@', delta='@@'), '@@@@@@') def test_last_match_and_replace(self): """Test that pattern matches and removes items correctly.""" txtWithOneMatch = u'this string has 3000, 1999 and 3000 in it' txtWithTwoMatch = u'this string has 1998, 1999 and 3000 in it' txtWithNoMatch = u'this string has no match' pat = self.ts.pyearR self.assertEqual(self.ts.last_match_and_replace(txtWithOneMatch, pat), (u'this string has 3000, @@ and 3000 in it', {'year': u'1999'}) ) self.assertEqual(self.ts.last_match_and_replace(txtWithTwoMatch, pat), (u'this string has @@, @@ and 3000 in it', {'year': u'1999'}) ) self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat), (txtWithNoMatch, None) ) txtWithOneMatch = u'this string has XXX, YYY and février in it' txtWithTwoMatch = u'this string has XXX, mars and février in it' txtWithThreeMatch = u'this string has avr, mars and février in it' txtWithNoMatch = u'this string has no match' pat = self.ts.pmonthR self.assertEqual(self.ts.last_match_and_replace(txtWithOneMatch, pat), (u'this string has XXX, YYY and @@ in it', {'month': u'février'}) ) self.assertEqual(self.ts.last_match_and_replace(txtWithTwoMatch, pat), (u'this string has XXX, @@ and @@ in it', {'month': u'février'}) ) self.assertEqual(self.ts.last_match_and_replace(txtWithThreeMatch, pat), (u'this string has @@, @@ and @@ in it', {'month': u'février'}) ) self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat), (txtWithNoMatch, None) ) def test_hour(self): """Test that correct hour is matched.""" txtHourInRange = u'7 février 2010 à 23:00 (CET)' txtHourOutOfRange = u'7 février 2010 à 24:00 (CET)' self.assertNotEqual(self.ts.timestripper(txtHourInRange), None) self.assertEqual(self.ts.timestripper(txtHourOutOfRange), None)
class TestTimeStripperWithNoDigitsAsMonths(TestCase): """Test cases for TimeStripper methods.""" family = 'wikipedia' code = 'fr' cached = True def setUp(self): """Set up test cases.""" super(TestTimeStripperWithNoDigitsAsMonths, self).setUp() self.ts = TimeStripper(self.get_site()) def test_findmarker(self): """Test that string which is not part of text is found.""" txt = u'this is a string with a maker is @@@@already present' self.assertEqual(self.ts.findmarker(txt, base=u'@@', delta='@@'), '@@@@@@') def test_last_match_and_replace(self): """Test that pattern matches and removes items correctly.""" txtWithOneMatch = u'this string has 3000, 1999 and 3000 in it' txtWithTwoMatch = u'this string has 1998, 1999 and 3000 in it' txtWithNoMatch = u'this string has no match' pat = self.ts.pyearR self.assertEqual(self.ts.last_match_and_replace(txtWithOneMatch, pat), (u'this string has 3000, @@ and 3000 in it', { 'year': u'1999' })) self.assertEqual(self.ts.last_match_and_replace(txtWithTwoMatch, pat), (u'this string has @@, @@ and 3000 in it', { 'year': u'1999' })) self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat), (txtWithNoMatch, None)) txtWithOneMatch = u'this string has XXX, YYY and février in it' txtWithTwoMatch = u'this string has XXX, mars and février in it' txtWithThreeMatch = u'this string has avr, mars and février in it' txtWithNoMatch = u'this string has no match' pat = self.ts.pmonthR self.assertEqual(self.ts.last_match_and_replace(txtWithOneMatch, pat), (u'this string has XXX, YYY and @@ in it', { 'month': u'février' })) self.assertEqual(self.ts.last_match_and_replace(txtWithTwoMatch, pat), (u'this string has XXX, @@ and @@ in it', { 'month': u'février' })) self.assertEqual( self.ts.last_match_and_replace(txtWithThreeMatch, pat), (u'this string has @@, @@ and @@ in it', { 'month': u'février' })) self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat), (txtWithNoMatch, None)) def test_hour(self): """Test that correct hour is matched.""" txtHourInRange = u'7 février 2010 à 23:00 (CET)' txtHourOutOfRange = u'7 février 2010 à 24:00 (CET)' self.assertNotEqual(self.ts.timestripper(txtHourInRange), None) self.assertEqual(self.ts.timestripper(txtHourOutOfRange), None)