def test_four_digit_is_not_year_with_timestamp(self):
     """A 4-digit number should not be mistaken as year (w/ timestamp)."""
     self.assertEqual(
         self.ts.timestripper(
             '2000 people will attend. --12:12, 14 December 2015 (UTC)'),
         datetime.datetime(
             2015, 12, 14, 12, 12, tzinfo=tzoneFixedOffset(0, 'UTC')))
Ejemplo n.º 2
0
    def test_timestripper_match(self, key):
        """Test that correct date is matched."""
        self.ts = TimeStripper(self.get_site(key))

        tzone = tzoneFixedOffset(self.ts.site.siteinfo['timeoffset'],
                                 self.ts.site.siteinfo['timezone'])

        txtMatch = self.sites[key]['match']

        res = datetime.datetime(2010, 2, 7, 19, 48, tzinfo=tzone)

        self.assertEqual(self.ts.timestripper(txtMatch), res)

        if 'match2' not in self.sites[key]:
            return

        txtMatch = self.sites[key]['match2']

        res = datetime.datetime(2008, 9, 12, 16, 41, tzinfo=tzone)

        self.assertEqual(self.ts.timestripper(txtMatch), res)

        if 'match3' not in self.sites[key]:
            return

        txtMatch = self.sites[key]['match3']

        res = datetime.datetime(2014, 8, 14, 21, 18, tzinfo=tzone)

        self.assertEqual(self.ts.timestripper(txtMatch), res)
Ejemplo n.º 3
0
    def test_timestripper_match(self, key):
        """Test that correct date is matched."""
        self.ts = TimeStripper(self.get_site(key))

        tzone = tzoneFixedOffset(self.ts.site.siteinfo['timeoffset'],
                                 self.ts.site.siteinfo['timezone'])

        txt_match = self.sites[key]['match']

        res = datetime.datetime(2010, 2, 7, 19, 48, tzinfo=tzone)

        self.assertEqual(self.ts.timestripper(txt_match), res)

        if 'match2' not in self.sites[key]:
            return

        txt_match = self.sites[key]['match2']

        res = datetime.datetime(2008, 9, 12, 16, 41, tzinfo=tzone)

        self.assertEqual(self.ts.timestripper(txt_match), res)

        if 'match3' not in self.sites[key]:
            return

        txt_match = self.sites[key]['match3']

        res = datetime.datetime(2014, 8, 14, 21, 18, tzinfo=tzone)

        self.assertEqual(self.ts.timestripper(txt_match), res)
 def test_four_digit_is_not_year_with_timestamp(self):
     """A 4-digit number should not be mistaken as year (w/ timestamp)."""
     self.assertEqual(
         self.ts.timestripper(
             '2000 people will attend. --12:12, 14 December 2015 (UTC)'),
         datetime.datetime(
             2015, 12, 14, 12, 12, tzinfo=tzoneFixedOffset(0, 'UTC')))
Ejemplo n.º 5
0
    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)'

        res = datetime.datetime(2010, 2, 7, 19, 48,
                                tzinfo=tzoneFixedOffset(60, 'Europe/Paris'))

        self.assertEqual(self.ts.timestripper(txtMatch), res)
        self.assertEqual(self.ts.timestripper(txtNoMatch), None)
Ejemplo n.º 6
0
    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)
    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)
Ejemplo n.º 8
0
class TestTimeStripperDoNotArchiveUntil(TestCase):

    """Test cases for Do Not Archive Until templates.

    See https://commons.wikimedia.org/wiki/Template:DNAU and
    https://en.wikipedia.org/wiki/Template:Do_not_archive_until.
    """

    family = 'wikisource'
    code = 'en'

    cached = True

    username = '******'
    date = '06:57 06 June 2015 (UTC)'
    user_and_date = username + ' ' + date
    tzone = tzoneFixedOffset(0, 'UTC')

    def test_timestripper_match(self):
        """Test that dates in comments  are correctly recognised."""
        ts = TimeStripper(self.get_site())

        txt_match = '<!-- [[User:Do___ArchiveUntil]] ' + self.date + ' -->'
        res = datetime.datetime(2015, 6, 6, 6, 57, tzinfo=self.tzone)
        self.assertEqual(ts.timestripper(txt_match), res)

        txt_match = '<!-- --> <!-- ' + self.user_and_date + ' <!-- -->'
        res = datetime.datetime(2015, 6, 6, 6, 57, tzinfo=self.tzone)
        self.assertEqual(ts.timestripper(txt_match), res)

        txt_match = '<!-- ' + self.user_and_date + ' -->'
        res = datetime.datetime(2015, 6, 6, 6, 57, tzinfo=self.tzone)
        self.assertEqual(ts.timestripper(txt_match), res)

    def test_timestripper_match_only(self):
        """Test that latest date is used instead of other dates."""
        ts = TimeStripper(self.get_site())

        later_date = '10:57 06 June 2015 (UTC)'
        txt_match = '<!-- --> ' + self.user_and_date + ' <!-- -->' + later_date
        res = datetime.datetime(2015, 6, 6, 10, 57, tzinfo=self.tzone)
        self.assertEqual(ts.timestripper(txt_match), res)

        earlier_date = '02:57 06 June 2015 (UTC)'
        txt_match = '<!-- ' + self.user_and_date + ' --> ' + earlier_date
        res = datetime.datetime(2015, 6, 6, 6, 57, tzinfo=self.tzone)
        self.assertEqual(ts.timestripper(txt_match), res)
Ejemplo n.º 9
0
class TestTimeStripperTreatSpecialText(TestTimeStripperCase):
    """Test special text behaviour (comments, hyperlinks, wikilinks)."""

    family = 'wikisource'
    code = 'en'

    date = '06:57 06 June 2015 (UTC)'
    fake_date = '05:57 06 June 2015 (UTC)'
    tzone = tzoneFixedOffset(0, 'UTC')
    expected_date = datetime.datetime(2015, 6, 6, 6, 57, tzinfo=tzone)

    def test_timestripper_match_comment(self):
        """Test that comments are correctly matched."""
        ts = self.ts

        txt_match = self.date + '<!--a test comment-->'
        exp_match = 'a test comment'
        self.assertEqual(ts._comment_pat.search(txt_match).group(1), exp_match)

    def test_timestripper_match_hyperlink(self):
        """Test that hyperlinks are correctly matched."""
        ts = self.ts

        txt_match = '[http://test.org | a link]'
        exp_match = '[http://test.org | a link]'
        self.assertEqual(
            ts._hyperlink_pat.search(txt_match).group(), exp_match)

    def test_timestripper_match_wikilink(self):
        """Test that wikilinks are correctly matched."""
        ts = self.ts

        txt_match = '[[wikilink|a wikilink with no date]]'
        exp_match_link = 'wikilink'
        exp_match_anchor = '|a wikilink with no date'
        self.assertEqual(
            ts._wikilink_pat.search(txt_match).group('link'), exp_match_link)
        self.assertEqual(
            ts._wikilink_pat.search(txt_match).group('anchor'),
            exp_match_anchor)

    def test_timestripper_match_comment_with_date(self):
        """Test that dates in comments are correctly matched."""
        ts = self.ts.timestripper

        txt_match = self.date + '<!--' + self.fake_date + '-->'
        self.assertEqual(ts(txt_match), self.expected_date)

        txt_match = '<!--' + self.fake_date + '-->' + self.date
        self.assertEqual(ts(txt_match), self.expected_date)

        txt_match = '<!--' + self.date + '-->' + self.fake_date
        self.assertEqual(ts(txt_match), self.expected_date)

        txt_match = '<!--comment|' + self.date + '-->' + self.fake_date
        self.assertEqual(ts(txt_match), self.expected_date)

    def test_timestripper_skip_hyperlink(self):
        """Test that dates in hyperlinks are correctly skipped."""
        ts = self.ts.timestripper

        txt_match = self.date + '[http://' + self.fake_date + ']'
        self.assertEqual(ts(txt_match), self.expected_date)

        txt_match = '[http://' + self.fake_date + ']' + self.date
        self.assertEqual(ts(txt_match), self.expected_date)

        txt_match = ('{} [http://www.org | link with date {}]'.format(
            self.date, self.fake_date))
        self.assertEqual(ts(txt_match), self.expected_date)

        txt_match = '[http://' + self.fake_date + ']' + self.date
        self.assertEqual(ts(txt_match), self.expected_date)

    def test_timestripper_skip_hyperlink_and_do_not_connect(self):
        """Test that skipping hyperlinks will not make gaps shorter."""
        ts = self.ts.timestripper

        txt_match = (
            '{}[http://example.com Here is long enough text]{}'.format(
                self.date[:9], self.date[9:]))
        self.assertEqual(ts(txt_match), None)

    def test_timestripper_match_wikilink_with_date(self):
        """Test that dates in wikilinks are correctly matched."""
        ts = self.ts.timestripper

        txt_match = self.date + '[[' + self.fake_date + ']]'
        self.assertEqual(ts(txt_match), self.expected_date)

        txt_match = '[[' + self.fake_date + ']]' + self.date
        self.assertEqual(ts(txt_match), self.expected_date)

        txt_match = '[[' + self.date + ']]' + self.fake_date
        self.assertEqual(ts(txt_match), self.expected_date)

        txt_match = '[[wikilink|' + self.date + ']]' + self.fake_date
        self.assertEqual(ts(txt_match), self.expected_date)

    def test_timestripper_skip_wikilink_and_do_not_connect(self):
        """Test that skipping wikilinks will not make gaps shorter."""
        ts = self.ts.timestripper

        txt_match = ('{}[[Here is long enough text]]{}'.format(
            self.date[:9], self.date[9:]))
        self.assertEqual(ts(txt_match), None)

        txt_match = self.date[:9] + '[[foo]]' + self.date[9:]
        self.assertEqual(ts(txt_match), self.expected_date)